From: "Antonino A. Daplas" <adaplas@hotpop.com>
To: Jesper Juhl <juhl-lkml@dif.dk>
Cc: Antonino Daplas <adaplas@pol.net>,
linux-kernel <linux-kernel@vger.kernel.org>,
linux-fbdev-devel@lists.sourceforge.net,
Alex Kern <alex.kern@gmx.de>,
"Ben. Herrenschmidt" <benh@kernel.crashing.org>,
Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
Helge Deller <deller@gmx.de>, Philipp Rumpf <prumpf@tux.org>,
James Simmons <jsimmons@users.sf.net>,
Geert Uytterhoeven <geert@linux-m68k.org>,
"Eddie C. Dost" <ecd@skynet.be>, Nicolas Pitre <nico@cam.org>,
linux-arm-kernel@lists.arm.linux.org.uk,
Andrew Morton <akpm@osdl.org>, Richard Purdie <rpurdie@rpsys.net>
Subject: Re: [new patch] Re: [PATCH] remove redundant NULL checks before kfree() in drivers/video/w100fb.c and add if()+comment back in drivers/video/console/bitblit.c
Date: Mon, 21 Mar 2005 07:04:50 +0800 [thread overview]
Message-ID: <200503210704.50357.adaplas@hotpop.com> (raw)
In-Reply-To: <Pine.LNX.4.62.0503202332140.2508@dragon.hyggekrogen.localhost>
On Monday 21 March 2005 06:45, Jesper Juhl wrote:
> On Sun, 20 Mar 2005, Jesper Juhl wrote:
> > On Mon, 21 Mar 2005, Antonino A. Daplas wrote:
> > > On Monday 21 March 2005 06:02, Jesper Juhl wrote:
> > > > On Mon, 21 Mar 2005, Antonino A. Daplas wrote:
> > > > > On Sunday 20 March 2005 06:59, Jesper Juhl wrote:
> > > > > > Checking a pointer for NULL before calling kfree() on it is
> > > > > > redundant, kfree() deals with NULL pointers just fine.
> > > > > > This patch removes such checks from files in drivers/video/
> > > > >
> > > > > [snip]
> > > > >
> > > > > > ---
> > > > > > linux-2.6.11-mm4-orig/drivers/video/console/bitblit.c 2005-03-16
> > > > > > 15:45:26.000000000 +0100 +++
> > > > > > linux-2.6.11-mm4/drivers/video/console/bitblit.c 2005-03-19
> > > > > > 22:27:39.000000000 +0100 @@ -199,8 +199,7 @@ static void
> > > > > > bit_putcs(struct vc_data *vc
> > > > > > count -= cnt;
> > > > > > }
> > > > > >
> > > > > > - if (buf)
> > > > > > - kfree(buf);
> > > > > > + kfree(buf);
> > > > > > }
> > > > >
> > > > > This is performance critical, so I would like the check to remain.
> > > > > A comment may be added in this section.
> > > >
> > > > Ok, I believe Andrew already merged the patch into -mm, if you really
> > > > want that check back then I'll send him a patch to put it back and
> > > > add a comment once he puts out the next -mm.
> > > > But, at the risk of exposing my ignorance, I have to ask if it
> > > > wouldn't actually perform better /without/ the if(buf) bit? The
> > > > reason I say that is that the generated code shrinks quite a bit when
> > > > it's removed, and also kfree() itself does the same NULL check as the
> > > > very first thing, so it comes down to the bennefit of shorter
> > > > generated code, one less branch, against the overhead of a function
> > > > call - and how often will 'buf' be NULL? if buff is != NULL the
> > > > majority of the time, then it should be a gain to remove the if().
> > >
> > > You said it, buf is almost always NULL, except when the driver is in
> > > monochrome mode. So a kfree is rarely done.
> >
> > I see, then my change in this exact spot woul probably be a loss in the
> > general case. Thank you for explaining.
> >
> > > Anyway, if the patch is already in the tree, let's leave it at that. I
> > > would surmise that the performance loss is negligible.
> >
> > Well, I just spotted two cases I missed in drivers/video/ , so when I
> > send that patch I might as well include a hunk that puts this one check
> > back including a comment as to why it should stay.
>
> One case turned out not to be one when I took a closer look, so I actually
> only missed one. Here's a patch to fix that last one and also put the
> check in bitblit.c back.
> (Andrew: this should apply on top of what you already merged)
>
>
> Signed-off-by: Jesper Juhl <juhl-lkml@dif.dk>
>
> --- linux-2.6.11-mm4/drivers/video/console/bitblit.c~ 2005-03-20
> 23:40:58.000000000 +0100 +++
> linux-2.6.11-mm4/drivers/video/console/bitblit.c 2005-03-20
> 23:40:58.000000000 +0100 @@ -199,7 +199,11 @@ static void bit_putcs(struct
> vc_data *vc
> count -= cnt;
> }
>
> - kfree(buf);
> + /* buf is always NULL except when in monochrome mode, so in this case
> + it's a gain to check buf against NULL even though kfree() handles
> + NULL pointers just fine */
> + if (buf)
> + kfree(buf);
> }
>
As Joe Perch suggested, an if (unlikely(buf)) is better.
Tony
--- linux-2.6.11-mm4/drivers/video/console/bitblit.c~ 2005-03-20 23:40:58.000000000 +0100
+++ linux-2.6.11-mm4/drivers/video/console/bitblit.c 2005-03-20 23:40:58.000000000 +0100
@@ -199,7 +199,11 @@ static void bit_putcs(struct vc_data *vc
count -= cnt;
}
- kfree(buf);
+ /* buf is always NULL except when in monochrome mode, so in this case
+ it's a gain to check buf against NULL even though kfree() handles
+ NULL pointers just fine */
+ if (unlikely(buf))
+ kfree(buf);
}
prev parent reply other threads:[~2005-03-20 23:05 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-03-19 22:59 [PATCH] remove redundant NULL checks before kfree() in drivers/video/ Jesper Juhl
2005-03-20 20:53 ` Antonino A. Daplas
2005-03-20 21:49 ` Geert Uytterhoeven
2005-03-20 22:18 ` Antonino A. Daplas
2005-03-20 22:01 ` Jan Engelhardt
2005-03-20 22:02 ` Jesper Juhl
2005-03-20 22:17 ` Antonino A. Daplas
2005-03-20 22:29 ` Jesper Juhl
2005-03-20 22:45 ` [new patch] Re: [PATCH] remove redundant NULL checks before kfree() in drivers/video/w100fb.c and add if()+comment back in drivers/video/console/bitblit.c Jesper Juhl
2005-03-20 23:04 ` Antonino A. Daplas [this message]
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=200503210704.50357.adaplas@hotpop.com \
--to=adaplas@hotpop.com \
--cc=adaplas@pol.net \
--cc=akpm@osdl.org \
--cc=alex.kern@gmx.de \
--cc=benh@kernel.crashing.org \
--cc=deller@gmx.de \
--cc=ecd@skynet.be \
--cc=geert@linux-m68k.org \
--cc=jsimmons@users.sf.net \
--cc=juhl-lkml@dif.dk \
--cc=linux-arm-kernel@lists.arm.linux.org.uk \
--cc=linux-fbdev-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=nico@cam.org \
--cc=prumpf@tux.org \
--cc=rpurdie@rpsys.net \
--cc=tsbogend@alpha.franken.de \
/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.