Please review all modules for unload races
willy en thepuffingroup.com
willy en thepuffingroup.com
Dom Ene 30 09:51:38 CST 2000
On Sun, Jan 30, 2000 at 07:09:00PM +1100, Keith Owens wrote:
> static int open_foo(struct inode *inode, struct file *file)
> {
> MOD_INC_USE_COUNT; /* must be first */
> if (request_irq(FOO_IRQ, foo_interrupt, 0, "FOO", NULL)) {
> MOD_DEC_USE_COUNT; /* failure path */
> return -EBUSY;
> }
> return 0;
> }
>From a performance and readability PoV, the following idiom is generally
preferred:
static int open_foo(struct inode *inode, struct file *file)
{
int retval;
MOD_INC_USE_COUNT;
retval = -EBUSY;
if (request_irq(FOO_IRQ, foo_interrupt, 0, "FOO", NULL))
goto fail;
return 0;
fail:
MOD_DEC_USE_COUNT;
return retval;
}
This keeps the failure (uncommon) case out of the normal path and ensures
that _all_ failing calls call MOD_DEC_USE_COUNT. I'm quite a big fan of
`only two return statements per function' because it allows for easier
printk-based debugging. Oh, and it drives the anti-goto fanatics wild,
so it's also worthwhile.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo en vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/
Más información sobre la lista de distribución Ayuda