mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-06 05:02:31 +00:00
virtio: store owner from modules with register_virtio_driver()
Modules registering driver with register_virtio_driver() might forget to set .owner field. i2c-virtio.c for example has it missing. The field is used by some 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 virtio code, just like we did for platform_driver in commit9447057eaf
("platform_device: use a macro instead of platform_driver_register"). Fixes:3cfc883804
("i2c: virtio: add a virtio i2c frontend driver") Cc: "Jie Deng" <jie.deng@intel.com> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Message-Id: <20240331-module-owner-virtio-v2-1-98f04bfaf46a@linaro.org> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
df9ace7647
commit
ffe6176b7f
@ -97,7 +97,6 @@ like this::
|
||||
|
||||
static struct virtio_driver virtio_dummy_driver = {
|
||||
.driver.name = KBUILD_MODNAME,
|
||||
.driver.owner = THIS_MODULE,
|
||||
.id_table = id_table,
|
||||
.probe = virtio_dummy_probe,
|
||||
.remove = virtio_dummy_remove,
|
||||
|
@ -362,14 +362,16 @@ static const struct bus_type virtio_bus = {
|
||||
.remove = virtio_dev_remove,
|
||||
};
|
||||
|
||||
int register_virtio_driver(struct virtio_driver *driver)
|
||||
int __register_virtio_driver(struct virtio_driver *driver, struct module *owner)
|
||||
{
|
||||
/* Catch this early. */
|
||||
BUG_ON(driver->feature_table_size && !driver->feature_table);
|
||||
driver->driver.bus = &virtio_bus;
|
||||
driver->driver.owner = owner;
|
||||
|
||||
return driver_register(&driver->driver);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(register_virtio_driver);
|
||||
EXPORT_SYMBOL_GPL(__register_virtio_driver);
|
||||
|
||||
void unregister_virtio_driver(struct virtio_driver *driver)
|
||||
{
|
||||
|
@ -170,7 +170,7 @@ size_t virtio_max_dma_size(const struct virtio_device *vdev);
|
||||
|
||||
/**
|
||||
* struct virtio_driver - operations for a virtio I/O driver
|
||||
* @driver: underlying device driver (populate name and owner).
|
||||
* @driver: underlying device driver (populate name).
|
||||
* @id_table: the ids serviced by this driver.
|
||||
* @feature_table: an array of feature numbers supported by this driver.
|
||||
* @feature_table_size: number of entries in the feature table array.
|
||||
@ -208,7 +208,10 @@ static inline struct virtio_driver *drv_to_virtio(struct device_driver *drv)
|
||||
return container_of(drv, struct virtio_driver, driver);
|
||||
}
|
||||
|
||||
int register_virtio_driver(struct virtio_driver *drv);
|
||||
/* use a macro to avoid include chaining to get THIS_MODULE */
|
||||
#define register_virtio_driver(drv) \
|
||||
__register_virtio_driver(drv, THIS_MODULE)
|
||||
int __register_virtio_driver(struct virtio_driver *drv, struct module *owner);
|
||||
void unregister_virtio_driver(struct virtio_driver *drv);
|
||||
|
||||
/* module_virtio_driver() - Helper macro for drivers that don't do
|
||||
|
Loading…
Reference in New Issue
Block a user