[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220725160859.1274472-1-rf@opensource.cirrus.com>
Date: Mon, 25 Jul 2022 17:08:59 +0100
From: Richard Fitzgerald <rf@...nsource.cirrus.com>
To: <gregkh@...uxfoundation.org>, <rafael@...nel.org>
CC: <dri-devel@...ts.freedesktop.org>, <linux-kernel@...r.kernel.org>,
<patches@...nsource.cirrus.com>,
Richard Fitzgerald <rf@...nsource.cirrus.com>
Subject: [PATCH] component: try_module_get() to prevent unloading while in use
Call try_module_get() on a component before attempting to call its
bind() function, to ensure that a loadable module cannot be
unloaded while we are executing its bind().
If the bind is successful the module_put() is called only after it
has been unbound. This ensures that the module cannot be unloaded
while it is in use as an aggregate device.
Signed-off-by: Richard Fitzgerald <rf@...nsource.cirrus.com>
---
drivers/base/component.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/base/component.c b/drivers/base/component.c
index 5eadeac6c532..01dbef4a6187 100644
--- a/drivers/base/component.c
+++ b/drivers/base/component.c
@@ -580,6 +580,8 @@ static void component_unbind(struct component *component,
/* Release all resources claimed in the binding of this component */
devres_release_group(component->dev, component);
+
+ module_put(component->dev->driver->owner);
}
/**
@@ -617,13 +619,18 @@ static int component_bind(struct component *component, struct aggregate_device *
{
int ret;
+ if (!try_module_get(component->dev->driver->owner))
+ return -ENODEV;
+
/*
* Each component initialises inside its own devres group.
* This allows us to roll-back a failed component without
* affecting anything else.
*/
- if (!devres_open_group(adev->parent, NULL, GFP_KERNEL))
+ if (!devres_open_group(adev->parent, NULL, GFP_KERNEL)) {
+ module_put(component->dev->driver->owner);
return -ENOMEM;
+ }
/*
* Also open a group for the device itself: this allows us
@@ -632,6 +639,7 @@ static int component_bind(struct component *component, struct aggregate_device *
*/
if (!devres_open_group(component->dev, component, GFP_KERNEL)) {
devres_release_group(adev->parent, NULL);
+ module_put(component->dev->driver->owner);
return -ENOMEM;
}
--
2.30.2
Powered by blists - more mailing lists