lkml.org 
[lkml]   [2009]   [Oct]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH] scripts/checkpatch.pl: Add WARN on sizeof(&
From
On Sun, Oct 4, 2009 at 9:12 AM, Joe Perches <joe@perches.com> wrote:
> On Sat, 2009-10-03 at 17:38 +0200, Jan Ceuleers wrote:
>> David Miller wrote:
>> > Any time you see "&" in a sizeof() expression, it's almost
>> > certainly a bug.  Something for the folks with automated
>> > tools to look for if they haven't already :-)
>>
>> Your remark prompted me to find four more instances of such bugs
>> (none of which in the networking bits). I have submitted patches.
>
> Perhaps a checkpatch test.

A quick grep shows we have more:

grep -e '\bsizeof[:space:]*([:space:]*\&.*)' -nr ./
./drivers/media/video/em28xx/em28xx-cards.c:2237:
memset(&dev->info, 0, sizeof(&dev->info));
./drivers/media/video/saa7164/saa7164-cmd.c:350:
memset(&response_t, 0, sizeof(&response_t));
./drivers/media/dvb/dvb-usb/ce6230.c:108: memset(&req, 0, sizeof(&req));
./drivers/video/backlight/lcd.c:59: memset(&ld->fb_notif, 0,
sizeof(&ld->fb_notif));

>
> ---
>
> sizeof(&foo) is frequently an error.  Warn on its use.
>
> Signed-off-by: Joe Perches <joe@perches.com>


This patch looks fine for me,

Acked-by: WANG Cong <xiyou.wangcong@gmail.com>


>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 87bbb8b..596dd72 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -2534,6 +2534,11 @@ sub process {
>                        WARN("plain inline is preferred over $1\n" . $herecurr);
>                }
>
> +# check for sizeof(&)
> +               if ($line =~ /\bsizeof\s*\(\s*\&/) {
> +                       WARN("sizeof(& should be avoided\n" . $herecurr);
> +               }
> +
>  # check for new externs in .c files.
>                if ($realfile =~ /\.c$/ && defined $stat &&
>                    $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)
>
>
--
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/

\
 
 \ /
  Last update: 2009-10-05 10:07    [W:0.050 / U:0.368 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site