Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge patch series "scsi: Make use of bus callbacks"

Uwe Kleine-König <u.kleine-koenig@baylibre.com> says:

Hello,

this is v2 of the series to make the scsi subsystem stop using the
callbacks .probe(), .remove() and .shutdown() of struct device_driver.
Instead use their designated alternatives in struct bus_type.

The eventual goal is to drop the callbacks from struct device_driver.

The 2nd patch introduces some legacy handling for drivers still using
the device_driver callbacks. This results in a runtime warning (in
driver_register()). The following patches convert all in-tree drivers
(and thus fix the warnings one after another).
Conceptually this legacy handling could be dropped at the end of the
series, but I think this is a bad idea because this silently breaks
out-of-tree drivers (which also covers drivers that are currently
prepared for mainline submission) and in-tree drivers I might have
missed (though I'm convinced I catched them all). That convinces me that
keeping the legacy handling for at least one development cycle is the
right choice. I'll care for that at the latest when I remove the
callbacks from struct device_driver.

Link: https://patch.msgid.link/cover.1766133330.git.u.kleine-koenig@baylibre.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

+139 -72
+9 -9
drivers/scsi/ch.c
··· 894 894 895 895 /* ------------------------------------------------------------------------ */ 896 896 897 - static int ch_probe(struct device *dev) 897 + static int ch_probe(struct scsi_device *sd) 898 898 { 899 - struct scsi_device *sd = to_scsi_device(dev); 899 + struct device *dev = &sd->sdev_gendev; 900 900 struct device *class_dev; 901 901 int ret; 902 902 scsi_changer *ch; ··· 967 967 return ret; 968 968 } 969 969 970 - static int ch_remove(struct device *dev) 970 + static void ch_remove(struct scsi_device *sd) 971 971 { 972 + struct device *dev = &sd->sdev_gendev; 972 973 scsi_changer *ch = dev_get_drvdata(dev); 973 974 974 975 spin_lock(&ch_index_lock); ··· 980 979 device_destroy(&ch_sysfs_class, MKDEV(SCSI_CHANGER_MAJOR, ch->minor)); 981 980 scsi_device_put(ch->device); 982 981 kref_put(&ch->ref, ch_destroy); 983 - return 0; 984 982 } 985 983 986 984 static struct scsi_driver ch_template = { 987 - .gendrv = { 985 + .probe = ch_probe, 986 + .remove = ch_remove, 987 + .gendrv = { 988 988 .name = "ch", 989 989 .owner = THIS_MODULE, 990 - .probe = ch_probe, 991 - .remove = ch_remove, 992 990 }, 993 991 }; 994 992 ··· 1014 1014 SCSI_CHANGER_MAJOR); 1015 1015 goto fail1; 1016 1016 } 1017 - rc = scsi_register_driver(&ch_template.gendrv); 1017 + rc = scsi_register_driver(&ch_template); 1018 1018 if (rc < 0) 1019 1019 goto fail2; 1020 1020 return 0; ··· 1028 1028 1029 1029 static void __exit exit_ch_module(void) 1030 1030 { 1031 - scsi_unregister_driver(&ch_template.gendrv); 1031 + scsi_unregister_driver(&ch_template); 1032 1032 unregister_chrdev(SCSI_CHANGER_MAJOR, "ch"); 1033 1033 class_unregister(&ch_sysfs_class); 1034 1034 idr_destroy(&ch_index_idr);
+74 -3
drivers/scsi/scsi_sysfs.c
··· 554 554 return 0; 555 555 } 556 556 557 + static int scsi_bus_probe(struct device *dev) 558 + { 559 + struct scsi_device *sdp = to_scsi_device(dev); 560 + struct scsi_driver *drv = to_scsi_driver(dev->driver); 561 + 562 + if (drv->probe) 563 + return drv->probe(sdp); 564 + else 565 + return 0; 566 + } 567 + 568 + static void scsi_bus_remove(struct device *dev) 569 + { 570 + struct scsi_device *sdp = to_scsi_device(dev); 571 + struct scsi_driver *drv = to_scsi_driver(dev->driver); 572 + 573 + if (drv->remove) 574 + drv->remove(sdp); 575 + } 576 + 577 + static void scsi_bus_shutdown(struct device *dev) 578 + { 579 + struct scsi_device *sdp = to_scsi_device(dev); 580 + struct scsi_driver *drv; 581 + 582 + if (!dev->driver) 583 + return; 584 + 585 + drv = to_scsi_driver(dev->driver); 586 + 587 + if (drv->shutdown) 588 + drv->shutdown(sdp); 589 + } 590 + 591 + 557 592 const struct bus_type scsi_bus_type = { 558 - .name = "scsi", 559 - .match = scsi_bus_match, 593 + .name = "scsi", 594 + .match = scsi_bus_match, 560 595 .uevent = scsi_bus_uevent, 596 + .probe = scsi_bus_probe, 597 + .remove = scsi_bus_remove, 598 + .shutdown = scsi_bus_shutdown, 561 599 #ifdef CONFIG_PM 562 600 .pm = &scsi_bus_pm_ops, 563 601 #endif ··· 1592 1554 } 1593 1555 EXPORT_SYMBOL(scsi_remove_target); 1594 1556 1595 - int __scsi_register_driver(struct device_driver *drv, struct module *owner) 1557 + static int scsi_legacy_probe(struct scsi_device *sdp) 1596 1558 { 1559 + struct device *dev = &sdp->sdev_gendev; 1560 + struct device_driver *driver = dev->driver; 1561 + 1562 + return driver->probe(dev); 1563 + } 1564 + 1565 + static void scsi_legacy_remove(struct scsi_device *sdp) 1566 + { 1567 + struct device *dev = &sdp->sdev_gendev; 1568 + struct device_driver *driver = dev->driver; 1569 + 1570 + driver->remove(dev); 1571 + } 1572 + 1573 + static void scsi_legacy_shutdown(struct scsi_device *sdp) 1574 + { 1575 + struct device *dev = &sdp->sdev_gendev; 1576 + struct device_driver *driver = dev->driver; 1577 + 1578 + driver->shutdown(dev); 1579 + } 1580 + 1581 + int __scsi_register_driver(struct scsi_driver *sdrv, struct module *owner) 1582 + { 1583 + struct device_driver *drv = &sdrv->gendrv; 1584 + 1597 1585 drv->bus = &scsi_bus_type; 1598 1586 drv->owner = owner; 1587 + 1588 + if (!sdrv->probe && drv->probe) 1589 + sdrv->probe = scsi_legacy_probe; 1590 + if (!sdrv->remove && drv->remove) 1591 + sdrv->remove = scsi_legacy_remove; 1592 + if (!sdrv->shutdown && drv->shutdown) 1593 + sdrv->shutdown = scsi_legacy_shutdown; 1599 1594 1600 1595 return driver_register(drv); 1601 1596 }
+15 -14
drivers/scsi/sd.c
··· 108 108 struct queue_limits *lim); 109 109 static void sd_revalidate_disk(struct gendisk *); 110 110 static void sd_unlock_native_capacity(struct gendisk *disk); 111 - static void sd_shutdown(struct device *); 111 + static void sd_shutdown(struct scsi_device *); 112 112 static void scsi_disk_release(struct device *cdev); 113 113 114 114 static DEFINE_IDA(sd_index_ida); ··· 3935 3935 * sd_probe - called during driver initialization and whenever a 3936 3936 * new scsi device is attached to the system. It is called once 3937 3937 * for each scsi device (not just disks) present. 3938 - * @dev: pointer to device object 3938 + * @sdp: pointer to device object 3939 3939 * 3940 3940 * Returns 0 if successful (or not interested in this scsi device 3941 3941 * (e.g. scanner)); 1 when there is an error. ··· 3949 3949 * Assume sd_probe is not re-entrant (for time being) 3950 3950 * Also think about sd_probe() and sd_remove() running coincidentally. 3951 3951 **/ 3952 - static int sd_probe(struct device *dev) 3952 + static int sd_probe(struct scsi_device *sdp) 3953 3953 { 3954 - struct scsi_device *sdp = to_scsi_device(dev); 3954 + struct device *dev = &sdp->sdev_gendev; 3955 3955 struct scsi_disk *sdkp; 3956 3956 struct gendisk *gd; 3957 3957 int index; ··· 4091 4091 * sd_remove - called whenever a scsi disk (previously recognized by 4092 4092 * sd_probe) is detached from the system. It is called (potentially 4093 4093 * multiple times) during sd module unload. 4094 - * @dev: pointer to device object 4094 + * @sdp: pointer to device object 4095 4095 * 4096 4096 * Note: this function is invoked from the scsi mid-level. 4097 4097 * This function potentially frees up a device name (e.g. /dev/sdc) 4098 4098 * that could be re-used by a subsequent sd_probe(). 4099 4099 * This function is not called when the built-in sd driver is "exit-ed". 4100 4100 **/ 4101 - static int sd_remove(struct device *dev) 4101 + static void sd_remove(struct scsi_device *sdp) 4102 4102 { 4103 + struct device *dev = &sdp->sdev_gendev; 4103 4104 struct scsi_disk *sdkp = dev_get_drvdata(dev); 4104 4105 4105 4106 scsi_autopm_get_device(sdkp->device); ··· 4108 4107 device_del(&sdkp->disk_dev); 4109 4108 del_gendisk(sdkp->disk); 4110 4109 if (!sdkp->suspended) 4111 - sd_shutdown(dev); 4110 + sd_shutdown(sdp); 4112 4111 4113 4112 put_disk(sdkp->disk); 4114 - return 0; 4115 4113 } 4116 4114 4117 4115 static void scsi_disk_release(struct device *dev) ··· 4197 4197 * the normal SCSI command structure. Wait for the command to 4198 4198 * complete. 4199 4199 */ 4200 - static void sd_shutdown(struct device *dev) 4200 + static void sd_shutdown(struct scsi_device *sdp) 4201 4201 { 4202 + struct device *dev = &sdp->sdev_gendev; 4202 4203 struct scsi_disk *sdkp = dev_get_drvdata(dev); 4203 4204 4204 4205 if (!sdkp) ··· 4369 4368 }; 4370 4369 4371 4370 static struct scsi_driver sd_template = { 4371 + .probe = sd_probe, 4372 + .remove = sd_remove, 4373 + .shutdown = sd_shutdown, 4372 4374 .gendrv = { 4373 4375 .name = "sd", 4374 - .probe = sd_probe, 4375 4376 .probe_type = PROBE_PREFER_ASYNCHRONOUS, 4376 - .remove = sd_remove, 4377 - .shutdown = sd_shutdown, 4378 4377 .pm = &sd_pm_ops, 4379 4378 }, 4380 4379 .rescan = sd_rescan, ··· 4418 4417 goto err_out_class; 4419 4418 } 4420 4419 4421 - err = scsi_register_driver(&sd_template.gendrv); 4420 + err = scsi_register_driver(&sd_template); 4422 4421 if (err) 4423 4422 goto err_out_driver; 4424 4423 ··· 4445 4444 4446 4445 SCSI_LOG_HLQUEUE(3, printk("exit_sd: exiting sd driver\n")); 4447 4446 4448 - scsi_unregister_driver(&sd_template.gendrv); 4447 + scsi_unregister_driver(&sd_template); 4449 4448 mempool_destroy(sd_page_pool); 4450 4449 4451 4450 class_unregister(&sd_disk_class);
+4 -11
drivers/scsi/ses.c
··· 42 42 return (ses_dev->page2 != NULL); 43 43 } 44 44 45 - static int ses_probe(struct device *dev) 45 + static int ses_probe(struct scsi_device *sdev) 46 46 { 47 - struct scsi_device *sdev = to_scsi_device(dev); 48 47 int err = -ENODEV; 49 48 50 49 if (sdev->type != TYPE_ENCLOSURE) ··· 846 847 return err; 847 848 } 848 849 849 - static int ses_remove(struct device *dev) 850 - { 851 - return 0; 852 - } 853 - 854 850 static void ses_intf_remove_component(struct scsi_device *sdev) 855 851 { 856 852 struct enclosure_device *edev, *prev = NULL; ··· 900 906 }; 901 907 902 908 static struct scsi_driver ses_template = { 909 + .probe = ses_probe, 903 910 .gendrv = { 904 911 .name = "ses", 905 - .probe = ses_probe, 906 - .remove = ses_remove, 907 912 }, 908 913 }; 909 914 ··· 914 921 if (err) 915 922 return err; 916 923 917 - err = scsi_register_driver(&ses_template.gendrv); 924 + err = scsi_register_driver(&ses_template); 918 925 if (err) 919 926 goto out_unreg; 920 927 ··· 927 934 928 935 static void __exit ses_exit(void) 929 936 { 930 - scsi_unregister_driver(&ses_template.gendrv); 937 + scsi_unregister_driver(&ses_template); 931 938 scsi_unregister_interface(&ses_interface); 932 939 } 933 940
+10 -11
drivers/scsi/sr.c
··· 82 82 CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R|CDC_DVD_RAM|CDC_GENERIC_PACKET| \ 83 83 CDC_MRW|CDC_MRW_W|CDC_RAM) 84 84 85 - static int sr_probe(struct device *); 86 - static int sr_remove(struct device *); 85 + static int sr_probe(struct scsi_device *); 86 + static void sr_remove(struct scsi_device *); 87 87 static blk_status_t sr_init_command(struct scsi_cmnd *SCpnt); 88 88 static int sr_done(struct scsi_cmnd *); 89 89 static int sr_runtime_suspend(struct device *dev); ··· 93 93 }; 94 94 95 95 static struct scsi_driver sr_template = { 96 + .probe = sr_probe, 97 + .remove = sr_remove, 96 98 .gendrv = { 97 99 .name = "sr", 98 - .probe = sr_probe, 99 - .remove = sr_remove, 100 100 .pm = &sr_pm_ops, 101 101 }, 102 102 .init_command = sr_init_command, ··· 616 616 { 617 617 } 618 618 619 - static int sr_probe(struct device *dev) 619 + static int sr_probe(struct scsi_device *sdev) 620 620 { 621 - struct scsi_device *sdev = to_scsi_device(dev); 621 + struct device *dev = &sdev->sdev_gendev; 622 622 struct gendisk *disk; 623 623 struct scsi_cd *cd; 624 624 int minor, error; ··· 982 982 return ret; 983 983 } 984 984 985 - static int sr_remove(struct device *dev) 985 + static void sr_remove(struct scsi_device *sdev) 986 986 { 987 + struct device *dev = &sdev->sdev_gendev; 987 988 struct scsi_cd *cd = dev_get_drvdata(dev); 988 989 989 990 scsi_autopm_get_device(cd->device); 990 991 991 992 del_gendisk(cd->disk); 992 993 put_disk(cd->disk); 993 - 994 - return 0; 995 994 } 996 995 997 996 static int __init init_sr(void) ··· 1000 1001 rc = register_blkdev(SCSI_CDROM_MAJOR, "sr"); 1001 1002 if (rc) 1002 1003 return rc; 1003 - rc = scsi_register_driver(&sr_template.gendrv); 1004 + rc = scsi_register_driver(&sr_template); 1004 1005 if (rc) 1005 1006 unregister_blkdev(SCSI_CDROM_MAJOR, "sr"); 1006 1007 ··· 1009 1010 1010 1011 static void __exit exit_sr(void) 1011 1012 { 1012 - scsi_unregister_driver(&sr_template.gendrv); 1013 + scsi_unregister_driver(&sr_template); 1013 1014 unregister_blkdev(SCSI_CDROM_MAJOR, "sr"); 1014 1015 } 1015 1016
+11 -11
drivers/scsi/st.c
··· 202 202 unsigned long, size_t, int); 203 203 static int sgl_unmap_user_pages(struct st_buffer *, const unsigned int, int); 204 204 205 - static int st_probe(struct device *); 206 - static int st_remove(struct device *); 205 + static int st_probe(struct scsi_device *); 206 + static void st_remove(struct scsi_device *); 207 207 208 208 static struct scsi_driver st_template = { 209 + .probe = st_probe, 210 + .remove = st_remove, 209 211 .gendrv = { 210 212 .name = "st", 211 - .probe = st_probe, 212 - .remove = st_remove, 213 213 .groups = st_drv_groups, 214 214 }, 215 215 }; ··· 4342 4342 } 4343 4343 } 4344 4344 4345 - static int st_probe(struct device *dev) 4345 + static int st_probe(struct scsi_device *SDp) 4346 4346 { 4347 - struct scsi_device *SDp = to_scsi_device(dev); 4347 + struct device *dev = &SDp->sdev_gendev; 4348 4348 struct scsi_tape *tpnt = NULL; 4349 4349 struct st_modedef *STm; 4350 4350 struct st_partstat *STps; ··· 4499 4499 }; 4500 4500 4501 4501 4502 - static int st_remove(struct device *dev) 4502 + static void st_remove(struct scsi_device *SDp) 4503 4503 { 4504 + struct device *dev = &SDp->sdev_gendev; 4504 4505 struct scsi_tape *tpnt = dev_get_drvdata(dev); 4505 4506 int index = tpnt->index; 4506 4507 4507 - scsi_autopm_get_device(to_scsi_device(dev)); 4508 + scsi_autopm_get_device(SDp); 4508 4509 remove_cdevs(tpnt); 4509 4510 4510 4511 mutex_lock(&st_ref_mutex); ··· 4514 4513 spin_lock(&st_index_lock); 4515 4514 idr_remove(&st_index_idr, index); 4516 4515 spin_unlock(&st_index_lock); 4517 - return 0; 4518 4516 } 4519 4517 4520 4518 /** ··· 4576 4576 goto err_class; 4577 4577 } 4578 4578 4579 - err = scsi_register_driver(&st_template.gendrv); 4579 + err = scsi_register_driver(&st_template); 4580 4580 if (err) 4581 4581 goto err_chrdev; 4582 4582 ··· 4592 4592 4593 4593 static void __exit exit_st(void) 4594 4594 { 4595 - scsi_unregister_driver(&st_template.gendrv); 4595 + scsi_unregister_driver(&st_template); 4596 4596 unregister_chrdev_region(MKDEV(SCSI_TAPE_MAJOR, 0), 4597 4597 ST_MAX_TAPE_ENTRIES); 4598 4598 class_unregister(&st_sysfs_class);
+11 -11
drivers/ufs/core/ufshcd.c
··· 10525 10525 EXPORT_SYMBOL(ufshcd_runtime_resume); 10526 10526 #endif /* CONFIG_PM */ 10527 10527 10528 - static void ufshcd_wl_shutdown(struct device *dev) 10528 + static void ufshcd_wl_shutdown(struct scsi_device *sdev) 10529 10529 { 10530 - struct scsi_device *sdev = to_scsi_device(dev); 10531 10530 struct ufs_hba *hba = shost_priv(sdev->host); 10532 10531 10533 10532 down(&hba->host_sem); ··· 11132 11133 } 11133 11134 #endif 11134 11135 11135 - static int ufshcd_wl_probe(struct device *dev) 11136 + static int ufshcd_wl_probe(struct scsi_device *sdev) 11136 11137 { 11137 - struct scsi_device *sdev = to_scsi_device(dev); 11138 + struct device *dev = &sdev->sdev_gendev; 11138 11139 11139 11140 if (!is_device_wlun(sdev)) 11140 11141 return -ENODEV; ··· 11146 11147 return 0; 11147 11148 } 11148 11149 11149 - static int ufshcd_wl_remove(struct device *dev) 11150 + static void ufshcd_wl_remove(struct scsi_device *sdev) 11150 11151 { 11152 + struct device *dev = &sdev->sdev_gendev; 11153 + 11151 11154 pm_runtime_forbid(dev); 11152 - return 0; 11153 11155 } 11154 11156 11155 11157 static const struct dev_pm_ops ufshcd_wl_pm_ops = { ··· 11223 11223 * Hence register a scsi driver for ufs wluns only. 11224 11224 */ 11225 11225 static struct scsi_driver ufs_dev_wlun_template = { 11226 + .probe = ufshcd_wl_probe, 11227 + .remove = ufshcd_wl_remove, 11228 + .shutdown = ufshcd_wl_shutdown, 11226 11229 .gendrv = { 11227 11230 .name = "ufs_device_wlun", 11228 - .probe = ufshcd_wl_probe, 11229 - .remove = ufshcd_wl_remove, 11230 11231 .pm = &ufshcd_wl_pm_ops, 11231 - .shutdown = ufshcd_wl_shutdown, 11232 11232 }, 11233 11233 }; 11234 11234 ··· 11240 11240 11241 11241 ufs_debugfs_init(); 11242 11242 11243 - ret = scsi_register_driver(&ufs_dev_wlun_template.gendrv); 11243 + ret = scsi_register_driver(&ufs_dev_wlun_template); 11244 11244 if (ret) 11245 11245 ufs_debugfs_exit(); 11246 11246 return ret; ··· 11249 11249 static void __exit ufshcd_core_exit(void) 11250 11250 { 11251 11251 ufs_debugfs_exit(); 11252 - scsi_unregister_driver(&ufs_dev_wlun_template.gendrv); 11252 + scsi_unregister_driver(&ufs_dev_wlun_template); 11253 11253 } 11254 11254 11255 11255 module_init(ufshcd_core_init);
+5 -2
include/scsi/scsi_driver.h
··· 12 12 struct scsi_driver { 13 13 struct device_driver gendrv; 14 14 15 + int (*probe)(struct scsi_device *); 16 + void (*remove)(struct scsi_device *); 17 + void (*shutdown)(struct scsi_device *); 15 18 int (*resume)(struct device *); 16 19 void (*rescan)(struct device *); 17 20 blk_status_t (*init_command)(struct scsi_cmnd *); ··· 28 25 29 26 #define scsi_register_driver(drv) \ 30 27 __scsi_register_driver(drv, THIS_MODULE) 31 - int __scsi_register_driver(struct device_driver *, struct module *); 28 + int __scsi_register_driver(struct scsi_driver *, struct module *); 32 29 #define scsi_unregister_driver(drv) \ 33 - driver_unregister(drv); 30 + driver_unregister(&(drv)->gendrv); 34 31 35 32 extern int scsi_register_interface(struct class_interface *); 36 33 #define scsi_unregister_interface(intf) \