On 10/3/05, Russell King <[email protected]> wrote:
> It makes sense for kfree() to ignore NULL pointers, but does it really
> make sense for *_unregister() to do so too? Surely you want to only
> unregister things which you know have previously been registered?
Usually yes but it makes releasing partial initialization much simpler
because you can reuse the normal release counterpart. For example,
static int driver_init(void)
{
dev->resource1 = request_region(...);
if (!dev->resource1)
goto failed;
dev->resource2 = request_region(...);
if (!dev->resource2)
goto failed;
return 0;
failed:
driver_release(dev);
return -1;
}
static void driver_release(struct device * dev)
{
release_resource(dev->resource1);
release_resource(dev->resource2);
kfree(dev);
}
Many drivers have the release function copy-pasted to init with lots
of goto labels exactly because release_region, iounmap, and friends
aren't NULL safe.
Pekka
-
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]