Project

General

Profile

Actions

Feature #3239

open

008: Driver becomes not available for unloading permanently

Added by Vadim Mutilin over 12 years ago. Updated almost 11 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Start date:
07/20/2012
Due date:
% Done:

0%

Estimated time:
Published in build:

Description

(copied almost as is from kernel-rules/rules/DRVRULES_en.trl)

SUMMARY

Once you blocked a driver using `try_module_get()` you should unblock it by `module_put()`.

DESCRIPTION

There is a possibility to block unloading of a driver (kernel module). You might want to use it if the driver is currently in use by OS objects or user processes. However, its uncautious usage can undermine stability of the system as a whole.

Note that such calls can be nested (they increase/decrease semaphore counter internally). Therefore, you should call exactly one proceure that unblocks the driver for each preceeding blocking one. Otherwise, the driver will not be available for unloading--without any serious reason to put such a restriction.

LINKS

[Sample bugfix](http://lkml.org/lkml/2010/1/12/246) of `drivers/mtd/mtd_blkdevs.c`

EXAMPLE

Sample error:

static int dev_open(struct inode*, struct file*)
{
try_module_get(THIS_MODULE);
...
//the absence of the module_put(THIS_MODULE) call
return 0;
}

Sample error in `drivers/mtd/mtd_blkdevs.c`:

static int blktrans_open(struct block_device *bdev, fmode_t mode)
{
struct mtd_blktrans_dev *dev = bdev->bd_disk->private_data;
struct mtd_blktrans_ops *tr = dev->tr;
int ret = -ENODEV;

if (!get_mtd_device(NULL, dev->mtd->index))
goto out;

if (!try_module_get(tr->owner))
goto out_tr;

/* FIXME: Locking. A hot pluggable device can go away
(del_mtd_device can be called for it) without its module
being unloaded. */
dev->mtd->usecount++;

ret = 0;
if (tr->open && (ret = tr->open(dev))) {
dev->mtd->usecount--;
put_mtd_device(dev->mtd);
out_tr:
module_put(tr->owner);
}
out:
return ret;
}


1. If `try_module_get(tr->owner) == 0` then we goto label `out_tr`;
2. At label `out_tr` we call `module_put` on the unloaded driver;

To fix the error we should replace:

goto out_tr;

with

goto out;
Actions #1

Updated by Ilya Shchepetkov over 12 years ago

  • Subject changed from 008: Driver becomes not available for unloading permanently to 08_1: Driver becomes not available for unloading permanently
  • Status changed from New to Resolved

Fixed in commit d83e232 of fix_08_1a branch. Will be merged to master together with it.

Actions #2

Updated by Alexey Khoroshilov almost 12 years ago

  • Subject changed from 08_1: Driver becomes not available for unloading permanently to 008_1: Driver becomes not available for unloading permanently
Actions #3

Updated by Vadim Mutilin about 11 years ago

  • Subject changed from 008_1: Driver becomes not available for unloading permanently to 008: Driver becomes not available for unloading permanently
Actions #4

Updated by Evgeny Novikov about 11 years ago

  • Status changed from Resolved to Open

Commit 762fb1d to the main kernel Makefile in particular has added "-Werror=strict-prototypes" to CFLAGS. This causes an error for function prototype:

extern void ldv_module_put_and_exit();

Actions #5

Updated by Evgeny Novikov almost 11 years ago

  • Status changed from Open to Resolved
  • Assignee deleted (Ilya Shchepetkov)

The issue was fixed in 661eeff9 by Vladimir.

Actions

Also available in: Atom PDF