Messages in this thread | | | Subject | Re: [PATCH] don't do pointless NULL checks and casts before kfree() in security/ | Date | Sun, 20 Mar 2005 13:31:43 +0000 | From | Ralph Corderoy <> |
| |
Hi Jesper,
> > Not necessarily. It helps tell the reader that the pointer may be > > NULL at that point. This has come up before. > > > > http://groups-beta.google.com/group/linux.kernel/browse_thread/thread/bd3d6e5a29e43c73/7b43819f874295e8?q=ralph@inputplus.co.uk+persuade+lkml#7b43819f874295e8 > > > > I agree that > > if (foo->bar) { > kfree(foo->bar); > foo->bar = NULL; > } > > makes it easy to see that foo->bar might be NULL, but I think the > advantages of simply > > kfree(foo->bar); > foo->bar = NULL; > > outweigh that. > > Having to remember that kfree(NULL) is valid shouldn't be hard, people > should be used to that from userspace code calling free(),
Agreed.
> and if there are places where it's important to remember that the > pointer might be NULL, then a simple comment would do, wouldn't it? > > kfree(foo->bar); /* kfree(NULL) is valid */
I'd rather be without the same comment littering the code.
> the short version also have the real bennefits of generating shorter > and faster code as well as being shorter "on-screen".
Faster code? I'd have thought avoiding the function call outweighed the overhead of checking before calling.
Cheers,
Ralph.
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |