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

From: Dan Carpenter
Date: Wed May 19 2021 - 04:40:47 EST


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