Skip to content

Commit 163f649

Browse files
jhovoldfloatious
authored andcommitted
ata: pata_parport: switch to dynamic root device
Driver core expects devices to be dynamically allocated and will, for example, complain loudly when no release function has been provided. Use root_device_register() to allocate and register the root device instead of open coding using a static device. Note that this also fixes a reference leak in the unlikely event that device_register() ever fails. Signed-off-by: Johan Hovold <johan@kernel.org> Reviewed-by: Damien Le Moal <dlemoal@kernel.org> Signed-off-by: Niklas Cassel <cassel@kernel.org>
1 parent 254f496 commit 163f649

1 file changed

Lines changed: 7 additions & 14 deletions

File tree

drivers/ata/pata_parport/pata_parport.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -459,19 +459,11 @@ static void pata_parport_dev_release(struct device *dev)
459459
kfree(pi);
460460
}
461461

462-
static void pata_parport_bus_release(struct device *dev)
463-
{
464-
/* nothing to do here but required to avoid warning on device removal */
465-
}
466-
467462
static const struct bus_type pata_parport_bus_type = {
468463
.name = DRV_NAME,
469464
};
470465

471-
static struct device pata_parport_bus = {
472-
.init_name = DRV_NAME,
473-
.release = pata_parport_bus_release,
474-
};
466+
static struct device *pata_parport_bus;
475467

476468
static const struct scsi_host_template pata_parport_sht = {
477469
PATA_PARPORT_SHT("pata_parport")
@@ -518,7 +510,7 @@ static struct pi_adapter *pi_init_one(struct parport *parport,
518510
}
519511

520512
/* set up pi->dev before pi_probe_unit() so it can use dev_printk() */
521-
pi->dev.parent = &pata_parport_bus;
513+
pi->dev.parent = pata_parport_bus;
522514
pi->dev.bus = &pata_parport_bus_type;
523515
pi->dev.driver = &pr->driver;
524516
pi->dev.release = pata_parport_dev_release;
@@ -780,8 +772,9 @@ static __init int pata_parport_init(void)
780772
return error;
781773
}
782774

783-
error = device_register(&pata_parport_bus);
784-
if (error) {
775+
pata_parport_bus = root_device_register(DRV_NAME);
776+
if (IS_ERR(pata_parport_bus)) {
777+
error = PTR_ERR(pata_parport_bus);
785778
pr_err("failed to register pata_parport bus, error: %d\n", error);
786779
goto out_unregister_bus;
787780
}
@@ -811,7 +804,7 @@ static __init int pata_parport_init(void)
811804
out_remove_new:
812805
bus_remove_file(&pata_parport_bus_type, &bus_attr_new_device);
813806
out_unregister_dev:
814-
device_unregister(&pata_parport_bus);
807+
root_device_unregister(pata_parport_bus);
815808
out_unregister_bus:
816809
bus_unregister(&pata_parport_bus_type);
817810
return error;
@@ -822,7 +815,7 @@ static __exit void pata_parport_exit(void)
822815
parport_unregister_driver(&pata_parport_driver);
823816
bus_remove_file(&pata_parport_bus_type, &bus_attr_new_device);
824817
bus_remove_file(&pata_parport_bus_type, &bus_attr_delete_device);
825-
device_unregister(&pata_parport_bus);
818+
root_device_unregister(pata_parport_bus);
826819
bus_unregister(&pata_parport_bus_type);
827820
}
828821

0 commit comments

Comments
 (0)