[PATCH] pci: apple: i needs to be initialised and used

Tom Rini trini at konsulko.com
Fri Aug 15 22:17:17 CEST 2025


On Wed, Aug 06, 2025 at 12:30:00PM +0100, Andrew Goodbody wrote:
> In apple_pcie_probe the variable 'i' is declared and then its value
> printed on an error but 'i' is not initialised nor is it made use of.
> Add an initial value for 'i' and have it incremented in the for loop.
> 
> This issue was found by Smatch.
> 
> Signed-off-by: Andrew Goodbody <andrew.goodbody at linaro.org>
> ---
>  drivers/pci/pcie_apple.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/pcie_apple.c b/drivers/pci/pcie_apple.c
> index 6a8e715d4b6..216b6512af1 100644
> --- a/drivers/pci/pcie_apple.c
> +++ b/drivers/pci/pcie_apple.c
> @@ -335,7 +335,7 @@ static int apple_pcie_probe(struct udevice *dev)
>  	struct apple_pcie_priv *pcie = dev_get_priv(dev);
>  	fdt_addr_t addr;
>  	ofnode of_port;
> -	int i, ret;
> +	int i = 0, ret;
>  
>  	pcie->hw = (struct reg_info *)dev_get_driver_data(dev);
>  
> @@ -353,7 +353,7 @@ static int apple_pcie_probe(struct udevice *dev)
>  	INIT_LIST_HEAD(&pcie->ports);
>  
>  	for (of_port = ofnode_first_subnode(dev_ofnode(dev));
> -	     ofnode_valid(of_port);
> +	     ofnode_valid(of_port), i++;
>  	     of_port = ofnode_next_subnode(of_port)) {
>  		if (!ofnode_is_enabled(of_port))
>  			continue;

I don't think this is right because with this applied:
            apple_m1       : all -1425 rodata -101 text -1324
               u-boot: add: 0/-3, grow: 0/-1 bytes: 0/-1324 (-1324)
                 function                                   old     new   delta
                 gpio_request_by_name_nodev                  12       -     -12
                 devfdt_get_addr_name                        80       -     -80
                 _gpio_request_by_name_nodev                156       -    -156
                 apple_pcie_probe                          1204     128   -1076

So the probe becomes an almost nothing func (that I assume returns
early) and we can discard some other functions.

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20250815/7fc0c235/attachment.sig>


More information about the U-Boot mailing list