From: Richard Fitzgerald <rf@opensource.cirrus.com>
To: <gregkh@linuxfoundation.org>, <rafael@kernel.org>
Cc: <dri-devel@lists.freedesktop.org>, <linux-kernel@vger.kernel.org>,
<patches@opensource.cirrus.com>,
Richard Fitzgerald <rf@opensource.cirrus.com>
Subject: [PATCH] component: try_module_get() to prevent unloading while in use
Date: Mon, 25 Jul 2022 17:08:59 +0100 [thread overview]
Message-ID: <20220725160859.1274472-1-rf@opensource.cirrus.com> (raw)
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
next reply other threads:[~2022-07-25 16:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-25 16:08 Richard Fitzgerald [this message]
2022-07-25 18:09 ` [PATCH] component: try_module_get() to prevent unloading while in use 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220725160859.1274472-1-rf@opensource.cirrus.com \
--to=rf@opensource.cirrus.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=patches@opensource.cirrus.com \
--cc=rafael@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox