Skip to content

Commit d8d5412

Browse files
floatiousgregkh
authored andcommitted
ata: ahci: Clean up sysfs file on error
commit eeb25a0 upstream. .probe() (ahci_init_one()) calls sysfs_add_file_to_group(), however, if probe() fails after this call, we currently never call sysfs_remove_file_from_group(). (The sysfs_remove_file_from_group() call in .remove() (ahci_remove_one()) does not help, as .remove() is not called on .probe() error.) Thus, if probe() fails after the sysfs_add_file_to_group() call, the next time we insmod the module we will get: sysfs: cannot create duplicate filename '/devices/pci0000:00/0000:00:04.0/remapped_nvme' CPU: 11 PID: 954 Comm: modprobe Not tainted 6.10.0-rc5 #43 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-2.fc40 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0x5d/0x80 sysfs_warn_dup.cold+0x17/0x23 sysfs_add_file_mode_ns+0x11a/0x130 sysfs_add_file_to_group+0x7e/0xc0 ahci_init_one+0x31f/0xd40 [ahci] Fixes: 894fba7 ("ata: ahci: Add sysfs attribute to show remapped NVMe device count") Cc: stable@vger.kernel.org Reviewed-by: Damien Le Moal <dlemoal@kernel.org> Reviewed-by: Hannes Reinecke <hare@suse.de> Link: https://lore.kernel.org/r/20240629124210.181537-10-cassel@kernel.org Signed-off-by: Niklas Cassel <cassel@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3e72558 commit d8d5412

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

Diff for: drivers/ata/ahci.c

+12-5
Original file line numberDiff line numberDiff line change
@@ -1890,8 +1890,10 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
18901890
n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map));
18911891

18921892
host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports);
1893-
if (!host)
1894-
return -ENOMEM;
1893+
if (!host) {
1894+
rc = -ENOMEM;
1895+
goto err_rm_sysfs_file;
1896+
}
18951897
host->private_data = hpriv;
18961898

18971899
if (ahci_init_msi(pdev, n_ports, hpriv) < 0) {
@@ -1944,11 +1946,11 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
19441946
/* initialize adapter */
19451947
rc = ahci_configure_dma_masks(pdev, hpriv);
19461948
if (rc)
1947-
return rc;
1949+
goto err_rm_sysfs_file;
19481950

19491951
rc = ahci_pci_reset_controller(host);
19501952
if (rc)
1951-
return rc;
1953+
goto err_rm_sysfs_file;
19521954

19531955
ahci_pci_init_controller(host);
19541956
ahci_pci_print_info(host);
@@ -1957,10 +1959,15 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
19571959

19581960
rc = ahci_host_activate(host, &ahci_sht);
19591961
if (rc)
1960-
return rc;
1962+
goto err_rm_sysfs_file;
19611963

19621964
pm_runtime_put_noidle(&pdev->dev);
19631965
return 0;
1966+
1967+
err_rm_sysfs_file:
1968+
sysfs_remove_file_from_group(&pdev->dev.kobj,
1969+
&dev_attr_remapped_nvme.attr, NULL);
1970+
return rc;
19641971
}
19651972

19661973
static void ahci_shutdown_one(struct pci_dev *pdev)

0 commit comments

Comments
 (0)