summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Gunthorpe <jgg@nvidia.com>2021-04-06 22:40:27 +0300
committerAlex Williamson <alex.williamson@redhat.com>2021-04-08 00:39:16 +0300
commit91b9969d9c6bb7c02253bbfc536bfd892f636fdc (patch)
treedb6bbb6639ffa0c14f8dae99463064417ea90d56
parent2a3d15f270efa50d78d8a32d895e9d5396668f3a (diff)
downloadlinux-91b9969d9c6bb7c02253bbfc536bfd892f636fdc.tar.xz
vfio/mdev: Simplify driver registration
This is only done once, we don't need to generate code to initialize a structure stored in the ELF .data segment. Fill in the three required .driver members directly instead of copying data into them during mdev_register_driver(). Further the to_mdev_driver() function doesn't belong in a public header, just inline it into the two places that need it. Finally, we can now clearly see that 'drv' derived from dev->driver cannot be NULL, firstly because the driver core forbids it, and secondly because NULL won't pass through the container_of(). Remove the dead code. Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Reviewed-by: Cornelia Huck <cohuck@redhat.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Message-Id: <4-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
-rw-r--r--Documentation/driver-api/vfio-mediated-device.rst5
-rw-r--r--drivers/vfio/mdev/mdev_driver.c15
-rw-r--r--drivers/vfio/mdev/vfio_mdev.c8
-rw-r--r--include/linux/mdev.h6
4 files changed, 15 insertions, 19 deletions
diff --git a/Documentation/driver-api/vfio-mediated-device.rst b/Documentation/driver-api/vfio-mediated-device.rst
index c43c1dc33333..1779b85f014e 100644
--- a/Documentation/driver-api/vfio-mediated-device.rst
+++ b/Documentation/driver-api/vfio-mediated-device.rst
@@ -98,13 +98,11 @@ structure to represent a mediated device's driver::
/*
* struct mdev_driver [2] - Mediated device's driver
- * @name: driver name
* @probe: called when new device created
* @remove: called when device removed
* @driver: device driver structure
*/
struct mdev_driver {
- const char *name;
int (*probe) (struct mdev_device *dev);
void (*remove) (struct mdev_device *dev);
struct device_driver driver;
@@ -115,8 +113,7 @@ to register and unregister itself with the core driver:
* Register::
- extern int mdev_register_driver(struct mdev_driver *drv,
- struct module *owner);
+ extern int mdev_register_driver(struct mdev_driver *drv);
* Unregister::
diff --git a/drivers/vfio/mdev/mdev_driver.c b/drivers/vfio/mdev/mdev_driver.c
index 44c3ba7e56d9..041699571b7e 100644
--- a/drivers/vfio/mdev/mdev_driver.c
+++ b/drivers/vfio/mdev/mdev_driver.c
@@ -39,7 +39,8 @@ static void mdev_detach_iommu(struct mdev_device *mdev)
static int mdev_probe(struct device *dev)
{
- struct mdev_driver *drv = to_mdev_driver(dev->driver);
+ struct mdev_driver *drv =
+ container_of(dev->driver, struct mdev_driver, driver);
struct mdev_device *mdev = to_mdev_device(dev);
int ret;
@@ -47,7 +48,7 @@ static int mdev_probe(struct device *dev)
if (ret)
return ret;
- if (drv && drv->probe) {
+ if (drv->probe) {
ret = drv->probe(mdev);
if (ret)
mdev_detach_iommu(mdev);
@@ -58,10 +59,11 @@ static int mdev_probe(struct device *dev)
static int mdev_remove(struct device *dev)
{
- struct mdev_driver *drv = to_mdev_driver(dev->driver);
+ struct mdev_driver *drv =
+ container_of(dev->driver, struct mdev_driver, driver);
struct mdev_device *mdev = to_mdev_device(dev);
- if (drv && drv->remove)
+ if (drv->remove)
drv->remove(mdev);
mdev_detach_iommu(mdev);
@@ -79,16 +81,13 @@ EXPORT_SYMBOL_GPL(mdev_bus_type);
/**
* mdev_register_driver - register a new MDEV driver
* @drv: the driver to register
- * @owner: module owner of driver to be registered
*
* Returns a negative value on error, otherwise 0.
**/
-int mdev_register_driver(struct mdev_driver *drv, struct module *owner)
+int mdev_register_driver(struct mdev_driver *drv)
{
/* initialize common driver fields */
- drv->driver.name = drv->name;
drv->driver.bus = &mdev_bus_type;
- drv->driver.owner = owner;
/* register with core */
return driver_register(&drv->driver);
diff --git a/drivers/vfio/mdev/vfio_mdev.c b/drivers/vfio/mdev/vfio_mdev.c
index 91b7b8b9eb9c..cc9507ed85a1 100644
--- a/drivers/vfio/mdev/vfio_mdev.c
+++ b/drivers/vfio/mdev/vfio_mdev.c
@@ -152,14 +152,18 @@ static void vfio_mdev_remove(struct mdev_device *mdev)
}
static struct mdev_driver vfio_mdev_driver = {
- .name = "vfio_mdev",
+ .driver = {
+ .name = "vfio_mdev",
+ .owner = THIS_MODULE,
+ .mod_name = KBUILD_MODNAME,
+ },
.probe = vfio_mdev_probe,
.remove = vfio_mdev_remove,
};
static int __init vfio_mdev_init(void)
{
- return mdev_register_driver(&vfio_mdev_driver, THIS_MODULE);
+ return mdev_register_driver(&vfio_mdev_driver);
}
static void __exit vfio_mdev_exit(void)
diff --git a/include/linux/mdev.h b/include/linux/mdev.h
index 52f7ea19dd0f..cb771c712da0 100644
--- a/include/linux/mdev.h
+++ b/include/linux/mdev.h
@@ -137,21 +137,17 @@ struct mdev_type_attribute mdev_type_attr_##_name = \
/**
* struct mdev_driver - Mediated device driver
- * @name: driver name
* @probe: called when new device created
* @remove: called when device removed
* @driver: device driver structure
*
**/
struct mdev_driver {
- const char *name;
int (*probe)(struct mdev_device *dev);
void (*remove)(struct mdev_device *dev);
struct device_driver driver;
};
-#define to_mdev_driver(drv) container_of(drv, struct mdev_driver, driver)
-
static inline void *mdev_get_drvdata(struct mdev_device *mdev)
{
return mdev->driver_data;
@@ -170,7 +166,7 @@ extern struct bus_type mdev_bus_type;
int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops);
void mdev_unregister_device(struct device *dev);
-int mdev_register_driver(struct mdev_driver *drv, struct module *owner);
+int mdev_register_driver(struct mdev_driver *drv);
void mdev_unregister_driver(struct mdev_driver *drv);
struct device *mdev_parent_dev(struct mdev_device *mdev);