Re: [PATCH v3] misc: alcor_pci: fix null-ptr-deref when there is no PCI bridge

From: Tong Zhang
Date: Wed May 19 2021 - 16:20:39 EST


On Wed, May 19, 2021 at 1:40 AM Dan Carpenter <dan.carpenter@xxxxxxxxxx> wrote:
>
> Hello Tong Zhang,
>
> This is a semi-automatic email about new static checker warnings.
>
> The patch 3ce3e45cc333: "misc: alcor_pci: fix null-ptr-deref when
> there is no PCI bridge" from May 13, 2021, leads to the following
> Smatch complaint:
>
> drivers/misc/cardreader/alcor_pci.c:149 alcor_pci_init_check_aspm()
> error: we previously assumed 'priv->parent_pdev' could be null (see line 147)
>
> drivers/misc/cardreader/alcor_pci.c
> 142 /*
> 143 * A device might be attached to root complex directly and
> 144 * priv->parent_pdev will be NULL. In this case we don't check its
> 145 * capability and disable ASPM completely.
> 146 */
> 147 if (!priv->parent_pdev)
> ^^^^^^^^^^^^^^^^^^
>
> 148 priv->parent_cap_off = alcor_pci_find_cap_offset(priv,
> 149 priv->parent_pdev);
> ^^^^^^^^^^^^^^^^^^
> It will just crash inside the function call. Is the if statement
> reversed?
>
> 150
> 151 if ((priv->pdev_cap_off == 0) || (priv->parent_cap_off == 0)) {
>
> regards,
> dan carpenter


Thanks Dan.
I already corrected this in v4
https://lkml.org/lkml/2021/5/18/1040
Please check if the issue persists.
- Tong