public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [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

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