* [PATCH RFC] try_module_get usage
@ 2007-07-11 7:55 Fernando Luis Vázquez Cao
2007-07-11 8:11 ` [PATCH] UBI: cleanup usage of try_module_get Fernando Luis Vázquez Cao
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Fernando Luis Vázquez Cao @ 2007-07-11 7:55 UTC (permalink / raw)
To: Rusty Russell; +Cc: dedekind, linux-kernel
I keep seeing uses of try_module_get(THIS_MODULE) which seem to mimic
the behavior of the former MOD_INC_USE_COUNT. The UBI driver is one
example:
int ubi_get_device_info(int ubi_num, struct ubi_device_info *di)
{
const struct ubi_device *ubi;
if (!try_module_get(THIS_MODULE))
return -ENODEV;
if (ubi_num < 0 || ubi_num >= UBI_MAX_DEVICES ||
!ubi_devices[ubi_num]) {
module_put(THIS_MODULE);
return -ENODEV;
}
ubi = ubi_devices[ubi_num];
di->ubi_num = ubi->ubi_num;
di->leb_size = ubi->leb_size;
di->min_io_size = ubi->min_io_size;
di->ro_mode = ubi->ro_mode;
di->cdev = MKDEV(ubi->major, 0);
module_put(THIS_MODULE);
return 0;
}
My understanding is that this is not completely safe (we could be
preempted before try_modules_get gets executed) and that it is the
caller who should manipulate the refcounts. Am I missing something here?
Thank you in advance.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] UBI: cleanup usage of try_module_get
2007-07-11 7:55 [PATCH RFC] try_module_get usage Fernando Luis Vázquez Cao
@ 2007-07-11 8:11 ` Fernando Luis Vázquez Cao
2007-07-11 9:17 ` Artem Bityutskiy
2007-07-11 9:41 ` [PATCH RFC] try_module_get usage Christoph Hellwig
2007-07-11 10:18 ` Rusty Russell
2 siblings, 1 reply; 6+ messages in thread
From: Fernando Luis Vázquez Cao @ 2007-07-11 8:11 UTC (permalink / raw)
To: Rusty Russell; +Cc: dedekind, linux-kernel
The use of try_module_get(THIS_MODULE) in ubi_get_device_info does not
offer real protection against unexpected driver unloads, since we could
be preempted before try_modules_get gets executed. It is the caller who
should manipulate the refcounts. Besides, ubi_get_device_info is an
exported symbol which guarantees protection when accessed through
symbol_get.
Signed-off-by: Fernando Luis Vazquez Cao <fernando@oss.ntt.co.jp>
---
diff -urNp linux-2.6.22-orig/drivers/mtd/ubi/kapi.c linux-2.6.22/drivers/mtd/ubi/kapi.c
--- linux-2.6.22-orig/drivers/mtd/ubi/kapi.c 2007-07-09 08:32:17.000000000 +0900
+++ linux-2.6.22/drivers/mtd/ubi/kapi.c 2007-07-11 16:34:10.000000000 +0900
@@ -37,12 +37,8 @@ int ubi_get_device_info(int ubi_num, str
{
const struct ubi_device *ubi;
- if (!try_module_get(THIS_MODULE))
- return -ENODEV;
-
if (ubi_num < 0 || ubi_num >= UBI_MAX_DEVICES ||
!ubi_devices[ubi_num]) {
- module_put(THIS_MODULE);
return -ENODEV;
}
@@ -52,7 +48,6 @@ int ubi_get_device_info(int ubi_num, str
di->min_io_size = ubi->min_io_size;
di->ro_mode = ubi->ro_mode;
di->cdev = MKDEV(ubi->major, 0);
- module_put(THIS_MODULE);
return 0;
}
EXPORT_SYMBOL_GPL(ubi_get_device_info);
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] UBI: cleanup usage of try_module_get
2007-07-11 8:11 ` [PATCH] UBI: cleanup usage of try_module_get Fernando Luis Vázquez Cao
@ 2007-07-11 9:17 ` Artem Bityutskiy
0 siblings, 0 replies; 6+ messages in thread
From: Artem Bityutskiy @ 2007-07-11 9:17 UTC (permalink / raw)
To: Fernando Luis Vázquez Cao; +Cc: Rusty Russell, linux-kernel
On Wed, 2007-07-11 at 17:11 +0900, Fernando Luis Vázquez Cao wrote:
> The use of try_module_get(THIS_MODULE) in ubi_get_device_info does not
> offer real protection against unexpected driver unloads, since we could
> be preempted before try_modules_get gets executed. It is the caller who
> should manipulate the refcounts. Besides, ubi_get_device_info is an
> exported symbol which guarantees protection when accessed through
> symbol_get.
Yeah, looks fair, committed to UBI git, thanks.
--
Best regards,
Artem Bityutskiy (Битюцкий Артём)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH RFC] try_module_get usage
2007-07-11 7:55 [PATCH RFC] try_module_get usage Fernando Luis Vázquez Cao
2007-07-11 8:11 ` [PATCH] UBI: cleanup usage of try_module_get Fernando Luis Vázquez Cao
@ 2007-07-11 9:41 ` Christoph Hellwig
2007-07-11 10:01 ` Artem Bityutskiy
2007-07-11 10:18 ` Rusty Russell
2 siblings, 1 reply; 6+ messages in thread
From: Christoph Hellwig @ 2007-07-11 9:41 UTC (permalink / raw)
To: Fernando Luis V?zquez Cao; +Cc: Rusty Russell, dedekind, linux-kernel
On Wed, Jul 11, 2007 at 04:55:31PM +0900, Fernando Luis V?zquez Cao wrote:
> I keep seeing uses of try_module_get(THIS_MODULE) which seem to mimic
> the behavior of the former MOD_INC_USE_COUNT. The UBI driver is one
> example:
It's of course buggy as hell. But UBI folks prefer not to listen to
advice and keep their bugs.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH RFC] try_module_get usage
2007-07-11 9:41 ` [PATCH RFC] try_module_get usage Christoph Hellwig
@ 2007-07-11 10:01 ` Artem Bityutskiy
0 siblings, 0 replies; 6+ messages in thread
From: Artem Bityutskiy @ 2007-07-11 10:01 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: Fernando Luis V?zquez Cao, Rusty Russell, linux-kernel
On Wed, 2007-07-11 at 10:41 +0100, Christoph Hellwig wrote:
> On Wed, Jul 11, 2007 at 04:55:31PM +0900, Fernando Luis V?zquez Cao
> wrote:
> > I keep seeing uses of try_module_get(THIS_MODULE) which seem to
> mimic
> > the behavior of the former MOD_INC_USE_COUNT. The UBI driver is one
> > example:
>
> It's of course buggy as hell. But UBI folks prefer not to listen to
> advice and keep their bugs.
Christoph, stop this please, point the bugs we do not listen about. Your
patches sit in the UBI git and wait for the merge window:
http://git.infradead.org/?p=ubi-2.6.git;a=summary
I plan to let dwmw2 pull them and send to Linus together with other
MTD/JFFS2 patches. If you have specific requests - go ahead.
--
Best regards,
Artem Bityutskiy (Битюцкий Артём)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH RFC] try_module_get usage
2007-07-11 7:55 [PATCH RFC] try_module_get usage Fernando Luis Vázquez Cao
2007-07-11 8:11 ` [PATCH] UBI: cleanup usage of try_module_get Fernando Luis Vázquez Cao
2007-07-11 9:41 ` [PATCH RFC] try_module_get usage Christoph Hellwig
@ 2007-07-11 10:18 ` Rusty Russell
2 siblings, 0 replies; 6+ messages in thread
From: Rusty Russell @ 2007-07-11 10:18 UTC (permalink / raw)
To: Fernando Luis Vázquez Cao; +Cc: dedekind, linux-kernel
On Wed, 2007-07-11 at 16:55 +0900, Fernando Luis Vázquez Cao wrote:
> I keep seeing uses of try_module_get(THIS_MODULE) which seem to mimic
> the behavior of the former MOD_INC_USE_COUNT. The UBI driver is one
> example:
>
> int ubi_get_device_info(int ubi_num, struct ubi_device_info *di)
> {
> const struct ubi_device *ubi;
>
> if (!try_module_get(THIS_MODULE))
> return -ENODEV;
Yes, this code is wrong.
Thanks,
Rusty.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-07-11 10:18 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-11 7:55 [PATCH RFC] try_module_get usage Fernando Luis Vázquez Cao
2007-07-11 8:11 ` [PATCH] UBI: cleanup usage of try_module_get Fernando Luis Vázquez Cao
2007-07-11 9:17 ` Artem Bityutskiy
2007-07-11 9:41 ` [PATCH RFC] try_module_get usage Christoph Hellwig
2007-07-11 10:01 ` Artem Bityutskiy
2007-07-11 10:18 ` Rusty Russell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox