scsi: core: Store owner from modules with scsi_register_driver()

Modules registering driver with scsi_driver_register() might forget to set
.owner field.  The field is used by some of other kernel parts for
reference counting (try_module_get()), so it is expected that drivers will
set it.

Solve the problem by moving this task away from the drivers to the core
scsi code, just like we did for platform_driver in commit 9447057eaf
("platform_device: use a macro instead of platform_driver_register").

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20240328-b4-module-owner-scsi-v1-1-c86cb4f6e91c@linaro.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
This commit is contained in:
Krzysztof Kozlowski 2024-03-28 21:45:45 +01:00 committed by Martin K. Petersen
parent 4e64bbba53
commit 65a09ba269
2 changed files with 6 additions and 3 deletions

View File

@ -1609,13 +1609,14 @@ void scsi_remove_target(struct device *dev)
}
EXPORT_SYMBOL(scsi_remove_target);
int scsi_register_driver(struct device_driver *drv)
int __scsi_register_driver(struct device_driver *drv, struct module *owner)
{
drv->bus = &scsi_bus_type;
drv->owner = owner;
return driver_register(drv);
}
EXPORT_SYMBOL(scsi_register_driver);
EXPORT_SYMBOL(__scsi_register_driver);
int scsi_register_interface(struct class_interface *intf)
{

View File

@ -22,7 +22,9 @@ struct scsi_driver {
#define to_scsi_driver(drv) \
container_of((drv), struct scsi_driver, gendrv)
extern int scsi_register_driver(struct device_driver *);
#define scsi_register_driver(drv) \
__scsi_register_driver(drv, THIS_MODULE)
int __scsi_register_driver(struct device_driver *, struct module *);
#define scsi_unregister_driver(drv) \
driver_unregister(drv);