public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] component: try_module_get() to prevent unloading while in use
@ 2022-07-25 16:08 Richard Fitzgerald
  2022-07-25 18:09 ` Greg KH
  0 siblings, 1 reply; 6+ messages in thread
From: Richard Fitzgerald @ 2022-07-25 16:08 UTC (permalink / raw)
  To: gregkh, rafael; +Cc: dri-devel, linux-kernel, patches, Richard Fitzgerald

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@opensource.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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-07-28 11:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-25 16:08 [PATCH] component: try_module_get() to prevent unloading while in use Richard Fitzgerald
2022-07-25 18:09 ` Greg KH
2022-07-26 10:32   ` Richard Fitzgerald
2022-07-26 17:28     ` Greg KH
2022-07-28 10:49       ` Richard Fitzgerald
2022-07-28 11:48         ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox