From: Ralph Corderoy <ralph@inputplus.co.uk>
To: Jesper Juhl <juhl-lkml@dif.dk>
Cc: linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] don't do pointless NULL checks and casts before kfree() in security/
Date: Sun, 20 Mar 2005 13:31:43 +0000 [thread overview]
Message-ID: <200503201331.j2KDVhm12383@blake.inputplus.co.uk> (raw)
In-Reply-To: <Pine.LNX.4.62.0503201407220.2501@dragon.hyggekrogen.localhost>
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.
next prev parent reply other threads:[~2005-03-20 13:32 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-03-20 12:29 [PATCH] don't do pointless NULL checks and casts before kfree() in security/ Jesper Juhl
2005-03-20 12:50 ` Ralph Corderoy
2005-03-20 13:18 ` Jesper Juhl
2005-03-20 13:31 ` Ralph Corderoy [this message]
2005-03-20 14:04 ` YOSHIFUJI Hideaki / 吉藤英明
2005-03-20 14:39 ` Jesper Juhl
2005-03-21 10:17 ` Ralph Corderoy
2005-03-22 15:00 ` Stephen Smalley
2005-03-22 15:00 ` Stephen Smalley
2005-03-22 20:57 ` [PATCH] don't do pointless NULL checks and casts before kfree() in security/selinux/ Jesper Juhl
2005-03-22 15:34 ` [PATCH] don't do pointless NULL checks and casts before kfree() in security/ David Howells
2005-03-22 20:46 ` Jesper Juhl
[not found] <fa.p25ihnj.4026at@ifi.uio.no>
[not found] ` <fa.iqmuavi.o6kfai@ifi.uio.no>
2005-03-20 13:18 ` Bodo Eggert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200503201331.j2KDVhm12383@blake.inputplus.co.uk \
--to=ralph@inputplus.co.uk \
--cc=juhl-lkml@dif.dk \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.