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2VudHJ5ICpw
YSwgKnBlOwotCXBhcy0+dXNlcnMgPSAwOwotCXBhcy0+Z3JvdXBzID0gMDsKKworCW1lbXNldChw
YXMsIDAsIHNpemVvZigqcGFzKSk7CiAJcGFzLT5tYXNrID0gMDc7CiAKIAlwZSA9IGFjbC0+YV9l
bnRyaWVzICsgYWNsLT5hX2NvdW50OwoKLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t
LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLQpUaGlzIFNGLm5ldCBlbWFp
bCBpcyBzcG9uc29yZWQgYnkgREIyIEV4cHJlc3MKRG93bmxvYWQgREIyIEV4cHJlc3MgQyAtIHRo
ZSBGUkVFIHZlcnNpb24gb2YgREIyIGV4cHJlc3MgYW5kIHRha2UKY29udHJvbCBvZiB5b3VyIFhN
TC4gTm8gbGltaXRzLiBKdXN0IGRhdGEuIENsaWNrIHRvIGdldCBpdCBub3cuCmh0dHA6Ly9zb3Vy
Y2Vmb3JnZS5uZXQvcG93ZXJiYXIvZGIyLwpfX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f
X19fX19fX19fX19fX19fXwpORlMgbWFpbGxpc3QgIC0gIE5GU0BsaXN0cy5zb3VyY2Vmb3JnZS5u
ZXQKaHR0cHM6Ly9saXN0cy5zb3VyY2Vmb3JnZS5uZXQvbGlzdHMvbGlzdGluZm8vbmZzCg==


2007-05-29 03:00:56

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [PATCH] NFSD: fix uninitialized variable

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.

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

2007-05-29 03:19:27

by Jeff Garzik

[permalink] [raw]
Subject: Re: [PATCH] NFSD: fix uninitialized variable

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



-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

2007-05-29 04:31:12

by Dave Young

[permalink] [raw]
Subject: Re: [NFS] [PATCH] NFSD: fix uninitialized variable

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

2007-05-29 07:29:23

by Matt Keenan

[permalink] [raw]
Subject: Re: [PATCH] NFSD: fix uninitialized variable

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


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

2007-05-29 08:32:41

by Dave Young

[permalink] [raw]
Subject: Re: [PATCH] NFSD: fix uninitialized variable

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);

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

2007-05-29 19:52:34

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [PATCH] NFSD: fix uninitialized variable

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;

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs