The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] NFSD: fix uninitialized variable
@ 2007-05-27 10:34 Jeff Garzik
  2007-05-29  3:00 ` [NFS] " J. Bruce Fields
  0 siblings, 1 reply; 7+ messages in thread
From: Jeff Garzik @ 2007-05-27 10:34 UTC (permalink / raw)
  To: Andrew Morton, neilb; +Cc: LKML, nfs


Unlike many of the bogus warnings spewed by gcc, this one actually
complains about a real bug:

fs/nfsd/nfs4acl.c: In function ‘_posix_to_nfsv4_one’:
fs/nfsd/nfs4acl.c:227: warning: ‘pas.owner’ may be used uninitialized in this function
fs/nfsd/nfs4acl.c:227: warning: ‘pas.group’ may be used uninitialized in this function
fs/nfsd/nfs4acl.c:227: warning: ‘pas.other’ may be used uninitialized in this function

Signed-off-by: Jeff Garzik <jeff@garzik.org>

diff --git a/fs/nfsd/nfs4acl.c b/fs/nfsd/nfs4acl.c
index cc3b7ba..7fd4d44 100644
--- a/fs/nfsd/nfs4acl.c
+++ b/fs/nfsd/nfs4acl.c
@@ -183,8 +183,8 @@ static void
 summarize_posix_acl(struct posix_acl *acl, struct posix_acl_summary *pas)
 {
 	struct posix_acl_entry *pa, *pe;
-	pas->users = 0;
-	pas->groups = 0;
+
+	memset(pas, 0, sizeof(*pas));
 	pas->mask = 07;
 
 	pe = acl->a_entries + acl->a_count;

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [NFS] [PATCH] NFSD: fix uninitialized variable
  2007-05-27 10:34 [PATCH] NFSD: fix uninitialized variable Jeff Garzik
@ 2007-05-29  3:00 ` J. Bruce Fields
  2007-05-29  3:19   ` Jeff Garzik
  0 siblings, 1 reply; 7+ messages in thread
From: J. Bruce Fields @ 2007-05-29  3:00 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: Andrew Morton, neilb, nfs, LKML

On Sun, May 27, 2007 at 06:34:42AM -0400, Jeff Garzik wrote:
> 
> Unlike many of the bogus warnings spewed by gcc, this one actually
> complains about a real bug:

No, the calls to posix_acl_valid() in nfs4_acl_posix_to_nfsv4() ensure
that the passed-in acl has ACL_USER_OBJ, ACL_GROUP_OBJ, and ACL_OTHER
entries, and hence that these fields will always be initialized.

But I don't want anyone else wasting their time on this.  Should we cave
in and add the initialization here just to shut up gcc?  Or would a
comment here help?

--b.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [NFS] [PATCH] NFSD: fix uninitialized variable
  2007-05-29  3:00 ` [NFS] " J. Bruce Fields
@ 2007-05-29  3:19   ` Jeff Garzik
  2007-05-29  4:31     ` young dave
  2007-05-29 19:52     ` J. Bruce Fields
  0 siblings, 2 replies; 7+ messages in thread
From: Jeff Garzik @ 2007-05-29  3:19 UTC (permalink / raw)
  To: J. Bruce Fields; +Cc: Andrew Morton, neilb, nfs, LKML

J. Bruce Fields wrote:
> On Sun, May 27, 2007 at 06:34:42AM -0400, Jeff Garzik wrote:
>> Unlike many of the bogus warnings spewed by gcc, this one actually
>> complains about a real bug:
> 
> No, the calls to posix_acl_valid() in nfs4_acl_posix_to_nfsv4() ensure
> that the passed-in acl has ACL_USER_OBJ, ACL_GROUP_OBJ, and ACL_OTHER
> entries, and hence that these fields will always be initialized.

OK


> But I don't want anyone else wasting their time on this.  Should we cave
> in and add the initialization here just to shut up gcc?  Or would a
> comment here help?

Given what you said above, I don't see gcc, on its best day, will ever 
know enough to validate that that variable is indeed always initialized. 
  So I would vote for silencing it on those grounds.

	Jeff



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [NFS] [PATCH] NFSD: fix uninitialized variable
  2007-05-29  3:19   ` Jeff Garzik
@ 2007-05-29  4:31     ` young dave
  2007-05-29  7:29       ` Matt Keenan
  2007-05-29 19:52     ` J. Bruce Fields
  1 sibling, 1 reply; 7+ messages in thread
From: young dave @ 2007-05-29  4:31 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: J. Bruce Fields, Andrew Morton, neilb, nfs, LKML

Hi,

> Given what you said above, I don't see gcc, on its best day, will ever
> know enough to validate that that variable is indeed always initialized.
>   So I would vote for silencing it on those grounds.

I agree too. How about this one:

diff -dur linux/fs/nfsd/nfs4acl.c linux.new/fs/nfsd/nfs4acl.c
--- linux/fs/nfsd/nfs4acl.c     2007-05-29 12:28:29.000000000 +0000
+++ linux.new/fs/nfsd/nfs4acl.c 2007-05-29 12:30:45.000000000 +0000
@@ -183,8 +183,6 @@
 summarize_posix_acl(struct posix_acl *acl, struct posix_acl_summary *pas)
 {
        struct posix_acl_entry *pa, *pe;
-       pas->users = 0;
-       pas->groups = 0;
        pas->mask = 07;

        pe = acl->a_entries + acl->a_count;
@@ -229,6 +227,7 @@
        int eflag = ((flags & NFS4_ACL_TYPE_DEFAULT) ?
                NFS4_INHERITANCE_FLAGS | NFS4_ACE_INHERIT_ONLY_ACE : 0);

+       memset(pas, 0, sizeof(struct posix_acl_summary);
        BUG_ON(pacl->a_count < 3);
        summarize_posix_acl(pacl, &pas);

Regards
dave

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [NFS] [PATCH] NFSD: fix uninitialized variable
  2007-05-29  4:31     ` young dave
@ 2007-05-29  7:29       ` Matt Keenan
  2007-05-29  8:32         ` young dave
  0 siblings, 1 reply; 7+ messages in thread
From: Matt Keenan @ 2007-05-29  7:29 UTC (permalink / raw)
  To: young dave; +Cc: Jeff Garzik, J. Bruce Fields, Andrew Morton, neilb, nfs, LKML

young dave wrote:
> Hi,
>
>> Given what you said above, I don't see gcc, on its best day, will ever
>> know enough to validate that that variable is indeed always initialized.
>>   So I would vote for silencing it on those grounds.
>
> I agree too. How about this one:
>
> diff -dur linux/fs/nfsd/nfs4acl.c linux.new/fs/nfsd/nfs4acl.c
> --- linux/fs/nfsd/nfs4acl.c     2007-05-29 12:28:29.000000000 +0000
> +++ linux.new/fs/nfsd/nfs4acl.c 2007-05-29 12:30:45.000000000 +0000
> @@ -183,8 +183,6 @@
> summarize_posix_acl(struct posix_acl *acl, struct posix_acl_summary *pas)
> {
>        struct posix_acl_entry *pa, *pe;
> -       pas->users = 0;
> -       pas->groups = 0;
>        pas->mask = 07;
>
>        pe = acl->a_entries + acl->a_count;
> @@ -229,6 +227,7 @@
>        int eflag = ((flags & NFS4_ACL_TYPE_DEFAULT) ?
>                NFS4_INHERITANCE_FLAGS | NFS4_ACE_INHERIT_ONLY_ACE : 0);
>
> +       memset(pas, 0, sizeof(struct posix_acl_summary);
>        BUG_ON(pacl->a_count < 3);
>        summarize_posix_acl(pacl, &pas);
>
                                                                          
^^^^^

apart from the fact that this patch won't compile let alone run...


Matt


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [NFS] [PATCH] NFSD: fix uninitialized variable
  2007-05-29  7:29       ` Matt Keenan
@ 2007-05-29  8:32         ` young dave
  0 siblings, 0 replies; 7+ messages in thread
From: young dave @ 2007-05-29  8:32 UTC (permalink / raw)
  To: Matt Keenan; +Cc: Jeff Garzik, J. Bruce Fields, Andrew Morton, neilb, nfs, LKML

Hi, matt
embarrassed :)
below resend it.

diff -dur linux/fs/nfsd/nfs4acl.c linux.new/fs/nfsd/nfs4acl.c
--- linux/fs/nfsd/nfs4acl.c     2007-05-29 12:28:29.000000000 +0000
+++ linux.new/fs/nfsd/nfs4acl.c 2007-05-29 16:32:26.000000000 +0000
@@ -183,8 +183,6 @@
 summarize_posix_acl(struct posix_acl *acl, struct posix_acl_summary *pas)
 {
        struct posix_acl_entry *pa, *pe;
-       pas->users = 0;
-       pas->groups = 0;
        pas->mask = 07;

        pe = acl->a_entries + acl->a_count;
@@ -229,6 +227,7 @@
        int eflag = ((flags & NFS4_ACL_TYPE_DEFAULT) ?
                NFS4_INHERITANCE_FLAGS | NFS4_ACE_INHERIT_ONLY_ACE : 0);

+       memset(pas, 0, sizeof(struct posix_acl_summary));
        BUG_ON(pacl->a_count < 3);
        summarize_posix_acl(pacl, &pas);

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [NFS] [PATCH] NFSD: fix uninitialized variable
  2007-05-29  3:19   ` Jeff Garzik
  2007-05-29  4:31     ` young dave
@ 2007-05-29 19:52     ` J. Bruce Fields
  1 sibling, 0 replies; 7+ messages in thread
From: J. Bruce Fields @ 2007-05-29 19:52 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: Andrew Morton, neilb, nfs, LKML

On Mon, May 28, 2007 at 11:19:21PM -0400, Jeff Garzik wrote:
> J. Bruce Fields wrote:
> >But I don't want anyone else wasting their time on this.  Should we cave
> >in and add the initialization here just to shut up gcc?  Or would a
> >comment here help?
> 
> Given what you said above, I don't see gcc, on its best day, will ever 
> know enough to validate that that variable is indeed always initialized. 

I recall there being arguments before about when to add initializations.
Unfortunately I can't remember the content of those arguments.  But I
thought that on the gcc-haters side the complaint was exactly that gcc
was emitting warnings in cases where it could never hope to determine
whether an initialization is required.  Am I misremembering?

>  So I would vote for silencing it on those grounds.

That said, I'm OK with the extra initialization.  Might be worth a
comment, though, just to avoid giving the wrong impression about the
assumptions here; something like:

--b.

diff --git a/fs/nfsd/nfs4acl.c b/fs/nfsd/nfs4acl.c
index cc3b7ba..4adb5ee 100644
--- a/fs/nfsd/nfs4acl.c
+++ b/fs/nfsd/nfs4acl.c
@@ -183,8 +183,13 @@ static void
 summarize_posix_acl(struct posix_acl *acl, struct posix_acl_summary *pas)
 {
 	struct posix_acl_entry *pa, *pe;
-	pas->users = 0;
-	pas->groups = 0;
+
+	/*
+	 * Only pas.users and pas.groups need initialization; previous
+	 * posix_acl_valid() calls ensure that the other fields will be
+	 * initialized in the following loop.  But, just to placate gcc:
+	 */
+	memset(pas, 0, sizeof(*pas));
 	pas->mask = 07;
 
 	pe = acl->a_entries + acl->a_count;

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-05-29 19:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-27 10:34 [PATCH] NFSD: fix uninitialized variable Jeff Garzik
2007-05-29  3:00 ` [NFS] " J. Bruce Fields
2007-05-29  3:19   ` Jeff Garzik
2007-05-29  4:31     ` young dave
2007-05-29  7:29       ` Matt Keenan
2007-05-29  8:32         ` young dave
2007-05-29 19:52     ` J. Bruce Fields

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox