Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1397981
| From | Johannes Thumshirn <jthumshirn@suse.de> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 2/2] mcb: Acquire reference to carrier module in core |
| Date | 2016-05-10 12:50 +0200 |
| Message-ID | <rxdoK-P9-11@gated-at.bofh.it> (permalink) |
| References | <rxdoJ-P9-9@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Acquire a reference to the carrier's kernel module in bus code, so
it can't be removed from the kernel while it still has a bus and thus
possibly devices attached to it.
Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Reported-by: Andreas Werner <andreas.werner@men.de>
Tested-by: Andreas Werner <andreas.werner@men.de>
---
drivers/mcb/mcb-core.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/drivers/mcb/mcb-core.c b/drivers/mcb/mcb-core.c
index f5923c2..6f2c852 100644
--- a/drivers/mcb/mcb-core.c
+++ b/drivers/mcb/mcb-core.c
@@ -61,22 +61,36 @@ static int mcb_probe(struct device *dev)
struct mcb_driver *mdrv = to_mcb_driver(dev->driver);
struct mcb_device *mdev = to_mcb_device(dev);
const struct mcb_device_id *found_id;
+ struct module *carrier_mod;
+ int ret;
found_id = mcb_match_id(mdrv->id_table, mdev);
if (!found_id)
return -ENODEV;
+ carrier_mod = mdev->dev.parent->driver->owner;
+ if (!try_module_get(carrier_mod))
+ return -EINVAL;
+
get_device(dev);
- return mdrv->probe(mdev, found_id);
+ ret = mdrv->probe(mdev, found_id);
+ if (ret)
+ module_put(carrier_mod);
+
+ return ret;
}
static int mcb_remove(struct device *dev)
{
struct mcb_driver *mdrv = to_mcb_driver(dev->driver);
struct mcb_device *mdev = to_mcb_device(dev);
+ struct module *carrier_mod;
mdrv->remove(mdev);
+ carrier_mod = mdev->dev.parent->driver->owner;
+ module_put(carrier_mod);
+
put_device(&mdev->dev);
return 0;
--
2.8.1
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 0/2] MCB: two additional fixes for v4.7 Johannes Thumshirn <jthumshirn@suse.de> - 2016-05-10 12:50 +0200 [PATCH 2/2] mcb: Acquire reference to carrier module in core Johannes Thumshirn <jthumshirn@suse.de> - 2016-05-10 12:50 +0200 [PATCH 1/2] mcb: Acquire reference to device in probe Johannes Thumshirn <jthumshirn@suse.de> - 2016-05-10 12:50 +0200
csiph-web