Re: [PATCH v4 2/4] PCI/sysfs: Fix null pointer dereference during hotplug

Krzysztof Wilczyński
2026-05-02T16:24:22Z

Hello,

> Given this, would setting the pointer to NULL after kfree still be
> considered a worthwhile defensive measure?
>
[...]
> > > diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
> > > index 18e5d4603b472..fbcbf39232732 100644
> > > --- a/drivers/pci/pci-sysfs.c
> > > +++ b/drivers/pci/pci-sysfs.c
> > > @@ -1227,12 +1227,14 @@ static void pci_remove_resource_files(struct pci_dev *pdev)
> > > if (res_attr) {
> > > sysfs_remove_bin_file(&pdev->dev.kobj, res_attr);
> > > kfree(res_attr);
> > > + pdev->res_attr[i] = NULL;
> > > }
> > > res_attr = pdev->res_attr_wc[i];
> > > if (res_attr) {
> > > sysfs_remove_bin_file(&pdev->dev.kobj, res_attr);
> > > kfree(res_attr);
> > > + pdev->res_attr_wc[i] = NULL;
> > > }
> > > }
> > > }

If the changes like the following series:

https://lore.kernel.org/linux-pci/20260422161407.118748-1-kwilczynski@kernel.org/

Will eventually be accepted, then this won't be needed.

Thank you!

Krzysztof