lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <520f0cf10808130450w72757a4dp9b9b0942d6c6a1b1@mail.gmail.com>
Date:	Wed, 13 Aug 2008 13:50:32 +0200
From:	"John Kacur" <jkacur@...il.com>
To:	LKML <linux-kernel@...r.kernel.org>
Cc:	"Andy Whitcroft" <apw@...dowen.org>, rdunlap@...otime.net,
	jschopp@...tin.ibm.com
Subject: Re: drop overzealous ERROR: do not initialise statics to 0 or NULL from checkpatch.pl

On Wed, Aug 13, 2008 at 12:39 PM, John Kacur <jkacur@...il.com> wrote:
> Could we drop this somewhat overzealous "ERROR: do not initialise
> statics to 0 or NULL" from checkpatch.pl?
>
> Reasoning:
> 1. This is not part of Documentation/CodingStyle
> 2. K&R 2nd.ed do it (pg 83, static int bufp = 0;) The purpose is to
> remove access to the bufp from external routines, and to avoid name
> conflict)
> 3. It can be a good form of documentation.
> 4. It creates a lot of needless code churn to change this kind of
> thing for no good reason.
> 5. It doesn't even change the object size (thus kernel size) to do so.
> Demo with user space code.
>
> jkacur@...ux-ipxk:~/try> cat foo.c
> #include <stdio.h>
> #include <stdlib.h>
>
> static int a[1000];
>
> /* Function Prototype */
> void foo(void);
> int main(void)
> {
>        exit(0);
> }
>
> void foo(void)
> {
>        static int b[1000];
>        static int c;
> }
> jkacur@...ux-ipxk:~/try> gcc foo.c
> jkacur@...ux-ipxk:~/try> size a.out
>   text    data     bss     dec     hex filename
>   1203     520    8064    9787    263b a.out
> jkacur@...ux-ipxk:~/try> ls -l a.out
> -rwxr-xr-x 1 jkacur users 11237 2008-08-13 12:26 a.out
>
> Now initialize all the statics to 0 and there will be no difference in
> the object size
> jkacur@...ux-ipxk:~/try> cat foo.c
> #include <stdio.h>
> #include <stdlib.h>
>
> static int a[1000] = {0};
>
> /* Function Prototype */
> void foo(void);
> int main(void)
> {
>        exit(0);
> }
>
> void foo(void)
> {
>        static int b[1000] = {0};
>        static int c = 0;
> }
> jkacur@...ux-ipxk:~/try> gcc foo.c
> jkacur@...ux-ipxk:~/try> size a.out
>   text    data     bss     dec     hex filename
>   1203     520    8064    9787    263b a.out
> <----------------------- No difference with the initialization to 0!!!
> jkacur@...ux-ipxk:~/try> ls -l a.out
> -rwxr-xr-x 1 jkacur users 11237 2008-08-13 12:26 a.out
> <----------------------- No difference with the initialization to 0!!!
>
>
> Now if we initialize it to a value other than 0 or NULL, then the bss
> is decreased at the expense of the data section, which does indeed
> increase the object size, however checkpatch.pl doesn't complain about
> this. (it is valid to do this)
> jkacur@...ux-ipxk:~/try> cat foo.c
> #include <stdio.h>
> #include <stdlib.h>
>
> static int a[1000] = {1};
>
> /* Function Prototype */
> void foo(void);
> int main(void)
> {
>        exit(0);
> }
>
> void foo(void)
> {
>        static int b[1000] = {1};
>        static int c = 1;
> }
> jkacur@...ux-ipxk:~/try> gcc foo.c
> jkacur@...ux-ipxk:~/try> size a.out
>   text    data     bss     dec     hex filename
>   1203    8568      16    9787    263b a.out
> jkacur@...ux-ipxk:~/try> ls -l a.out
> -rwxr-xr-x 1 jkacur users 19301 2008-08-13 12:27 a.out
>

My apologies for not ccing the maintainers of checkpatch the first
time. Attached is a patch to remove the check in case anybody agrees
with me. :)
The patch is against a recently updated git tree.

View attachment "remove_static_initialise_error.patch" of type "text/x-patch" (688 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ