All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Whitcroft <apw@shadowen.org>
To: Dave Jones <davej@redhat.com>
Cc: jschopp <jschopp@austin.ibm.com>,
	rdunlap@xenotime.net, Linux Kernel <linux-kernel@vger.kernel.org>
Subject: Re: Make checkpatch warn about pointless casting of kalloc returns.
Date: Mon, 13 Aug 2007 11:24:38 +0100	[thread overview]
Message-ID: <46C03166.1000301@shadowen.org> (raw)
In-Reply-To: <46B9F7C9.9060406@austin.ibm.com>

jschopp wrote:
>> +# check for pointless casting of kmalloc return
>> +        if ($rawline =~ /\*\)[ ]k[czm]alloc/) {
> 
> It looks to me like this will catch
> 
> foo = (char *) kmalloc(512);
> 
> but not
> 
> for = (char* )kmalloc(512);
> 
> I haven't tried it but how about something like:
> 
> if($rawline =~/\(.*\)\s*k[czm]alloc/){
> 
> which if I got it right should match the typecast with any combination
> of spacing.
> 
>> +            WARN("No need to cast return value.\n");
> 
> Could the warning be more descriptive?  This describes what, but it
> should also describe why; after all if somebody made this error they may
> not know they why.

Yes there are a few problems with the match, plus it needs to be on the
processed line to avoid false matches in strings (however unlikely).  I
ended up with the following:

                if ($line =~ /\*\s*\)\s*k[czm]alloc\b/) {
                        WARN("unnecessary cast may hide bugs, see
http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
                }

Which just fits on the line :).

Thanks for the patch.  Will be in 0.10 coming to an -mm near you soon.

-apw

      parent reply	other threads:[~2007-08-13 13:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-08  2:43 Make checkpatch warn about pointless casting of kalloc returns Dave Jones
2007-08-08 17:05 ` jschopp
2007-08-08 18:00   ` Dave Jones
2007-08-08 18:10     ` Cal Peake
2007-08-08 18:27     ` jschopp
2007-08-08 18:40       ` Nish Aravamudan
2007-08-13 10:24   ` Andy Whitcroft [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=46C03166.1000301@shadowen.org \
    --to=apw@shadowen.org \
    --cc=davej@redhat.com \
    --cc=jschopp@austin.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdunlap@xenotime.net \
    /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.