[PATCH RFC] try_module_get usage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux