Re: [PATCH] PCI/sysfs: NULL res_attr slot after kfree as defence against double-remove
From: Krzysztof Wilczyński
Date: Thu May 21 2026 - 07:59:22 EST
Hello,
> diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
> --- a/drivers/pci/pci-sysfs.c
> +++ b/drivers/pci/pci-sysfs.c
> @@ -1228,11 +1228,13 @@ 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;
> }
> }
> }
Similar such patches (for reference):
- https://lore.kernel.org/linux-pci/20251010093023.2569-1-guojinhui.liam@xxxxxxxxxxxxx/
- https://lore.kernel.org/linux-pci/20250629030547.1073425-1-zhangjian496@xxxxxxxxxx/
- https://lore.kernel.org/linux-pci/20210507102706.7658-1-danijel.slivka@xxxxxxx/
- https://lore.kernel.org/linux-pci/20191024172157.878735-2-s.miroshnichenko@xxxxxxxxx/
Thank you!
Krzysztof