lkml.org 
[lkml]   [2007]   [Jul]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Subject[PATCH RFC] try_module_get usage
From
Date
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.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2007-07-11 10:26    [W:0.045 / U:0.720 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site