Skip to content

Commit de501b2

Browse files
floatiousroxanan1996
authored andcommitted
ata: ahci: Clean up sysfs file on error
BugLink: https://bugs.launchpad.net/bugs/2073765 commit eeb25a09c5e0805d92e4ebd12c4b0ad0df1b0295 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: [email protected] Reviewed-by: Damien Le Moal <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Niklas Cassel <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Portia Stephens <[email protected]> Signed-off-by: Roxana Nicolescu <[email protected]>
1 parent 8940351 commit de501b2

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

drivers/ata/ahci.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,8 +1898,10 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
18981898
n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map));
18991899

19001900
host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports);
1901-
if (!host)
1902-
return -ENOMEM;
1901+
if (!host) {
1902+
rc = -ENOMEM;
1903+
goto err_rm_sysfs_file;
1904+
}
19031905
host->private_data = hpriv;
19041906

19051907
if (ahci_init_msi(pdev, n_ports, hpriv) < 0) {
@@ -1952,11 +1954,11 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
19521954
/* initialize adapter */
19531955
rc = ahci_configure_dma_masks(pdev, hpriv);
19541956
if (rc)
1955-
return rc;
1957+
goto err_rm_sysfs_file;
19561958

19571959
rc = ahci_pci_reset_controller(host);
19581960
if (rc)
1959-
return rc;
1961+
goto err_rm_sysfs_file;
19601962

19611963
ahci_pci_init_controller(host);
19621964
ahci_pci_print_info(host);
@@ -1965,10 +1967,15 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
19651967

19661968
rc = ahci_host_activate(host, &ahci_sht);
19671969
if (rc)
1968-
return rc;
1970+
goto err_rm_sysfs_file;
19691971

19701972
pm_runtime_put_noidle(&pdev->dev);
19711973
return 0;
1974+
1975+
err_rm_sysfs_file:
1976+
sysfs_remove_file_from_group(&pdev->dev.kobj,
1977+
&dev_attr_remapped_nvme.attr, NULL);
1978+
return rc;
19721979
}
19731980

19741981
static void ahci_shutdown_one(struct pci_dev *pdev)

0 commit comments

Comments
 (0)