Re: Please review all modules for unload races

From: willy@thepuffingroup.com
Date: Sun Jan 30 2000 - 11:41:52 EST


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@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Mon Jan 31 2000 - 21:00:25 EST