Re: [PATCH] Next branch: authgss: authgss.c: Fix warnings for uninitizlized variable expire

2014-09-02 Thread Boaz Harrosh
On 09/02/2014 05:17 PM, Bruce Fields wrote:
> On Tue, Sep 02, 2014 at 04:59:45PM +0300, Boaz Harrosh wrote:
>> uninitialized_var was made to be a friend not an enemy, in the face of real
>> ugliness it is the best we can do. And that is what it should communicate to
>> everyone. Why has it become everyone's favorite blasphemy I do not know.
> 
> Not personally claiming it should never be used, just that this
> particular case is kind of extreme, since unless I'm missing a real
> compilication it's basically just:
> 
>   if (ctx)
>   assign to expire
>   ...
>   if (ctx)
>   use expire
> 
> A compiler wouldn't have to be that smart to actually prove to itself
> that expire is initialized at the last step, and that it's not only
> failing to do that but actually flagging it as possibly unitialized is
> weird.

Actually that is a complicated case for a compiler. Because of the two
different scopes. I think it only optimizes that on higher optimization
values. Cross scope analysis is not done at parsing time but more on
code generation time, the "warning" is more of the former phase.

Perhaps change the code, if possible, so the assign and use of "expire"
is under the last if (or the first)? That would be also easier on the
reader.

BTW: You are most probably right though, because here I do not have this
 problem. I guess it is the case of an old compiler with a certain
 compilation environment.

Thanks
Boaz

> 
> --b.
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] Next branch: authgss: authgss.c: Fix warnings for uninitizlized variable expire

2014-09-02 Thread Bruce Fields
On Tue, Sep 02, 2014 at 04:59:45PM +0300, Boaz Harrosh wrote:
> uninitialized_var was made to be a friend not an enemy, in the face of real
> ugliness it is the best we can do. And that is what it should communicate to
> everyone. Why has it become everyone's favorite blasphemy I do not know.

Not personally claiming it should never be used, just that this
particular case is kind of extreme, since unless I'm missing a real
compilication it's basically just:

if (ctx)
assign to expire
...
if (ctx)
use expire

A compiler wouldn't have to be that smart to actually prove to itself
that expire is initialized at the last step, and that it's not only
failing to do that but actually flagging it as possibly unitialized is
weird.

--b.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] Next branch: authgss: authgss.c: Fix warnings for uninitizlized variable expire

2014-09-02 Thread Boaz Harrosh
On 09/02/2014 04:21 PM, Bruce Fields wrote:
> 
> You'd rather avoid sprinkling that all over, though.  If nothing else it
> increases the chances you'll suppress a legimate warning some day.
> 

But this is exactly why it was created.

If you do the "= 0" then it is gone forever. If you have missed a legitimate
needed assignment, it will be missed as well.

But if you do the uninitialized_var() dance then there is a make option that 
turns
it off and every once in a while people do a make with it to see if it still
holds.

The diff between foo = 0; and uninitialized_var(foo) is that the programmer is
communicating to his friends that:
"I have encountered a bogus compiler, this is falsely initialized"

As opposed to =0 the compiler bug is covered up and forgotten

> And unless I'm missing something this one really does look like an
> unambiguous compiler bug.
> 

Right! so that is how you specify this in code at Linux: uninitialized_var(foo);

Putting =0 is way way worse, because it will never be revised and specially
not automatically with a make switch.

And leaving the warning on is even worse because two three of these and people
start to ignore warnings.

> --b.
> 

uninitialized_var was made to be a friend not an enemy, in the face of real
ugliness it is the best we can do. And that is what it should communicate to
everyone. Why has it become everyone's favorite blasphemy I do not know.

Cheers
Boaz

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] Next branch: authgss: authgss.c: Fix warnings for uninitizlized variable expire

2014-09-02 Thread Bruce Fields
On Tue, Sep 02, 2014 at 01:52:15PM +0300, Boaz Harrosh wrote:
> On 09/01/2014 04:50 PM, Trond Myklebust wrote:
> > On Mon, Sep 1, 2014 at 7:32 AM, Shakil A Khan  wrote:
> >> Signed-off-by : Shakil A Khan 
> >> ---
> >>  net/sunrpc/auth_gss/auth_gss.c |2 +-
> >>  1 files changed, 1 insertions(+), 1 deletions(-)
> >>
> >> diff --git a/net/sunrpc/auth_gss/auth_gss.c 
> >> b/net/sunrpc/auth_gss/auth_gss.c
> >> index afb292c..bea0951 100644
> >> --- a/net/sunrpc/auth_gss/auth_gss.c
> >> +++ b/net/sunrpc/auth_gss/auth_gss.c
> >> @@ -1387,7 +1387,7 @@ gss_key_timeout(struct rpc_cred *rc)
> >> struct gss_cred *gss_cred = container_of(rc, struct gss_cred, 
> >> gc_base);
> >> struct gss_cl_ctx *ctx;
> >> unsigned long now = jiffies;
> >> -   unsigned long expire;
> >> +   unsigned long expire = 0;
> >>
> >> rcu_read_lock();
> >> ctx = rcu_dereference(gss_cred->gc_ctx);
> >> --
> >> 1.7.1
> > 
> > That would be a compiler bug, not a kernel bug. The kernel code is
> > perfectly correct as it stands, and will never access the
> > uninitialised variable.
> > 
> 
> Than you will need the infamous uninitialised_var()

You'd rather avoid sprinkling that all over, though.  If nothing else it
increases the chances you'll suppress a legimate warning some day.

And unless I'm missing something this one really does look like an
unambiguous compiler bug.

--b.

> 
> diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
> index afb292c..bea0951 100644
> --- a/net/sunrpc/auth_gss/auth_gss.c
> +++ b/net/sunrpc/auth_gss/auth_gss.c
> @@ -1387,7 +1387,7 @@ gss_key_timeout(struct rpc_cred *rc)
>   struct gss_cred *gss_cred = container_of(rc, struct gss_cred, gc_base);
>   struct gss_cl_ctx *ctx;
>   unsigned long now = jiffies;
> - unsigned long expire;
> + unsigned long uninitialised_var(expire);
>  
>   rcu_read_lock();
>   ctx = rcu_dereference(gss_cred->gc_ctx);
> 
> Cheers
> Boaz
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] Next branch: authgss: authgss.c: Fix warnings for uninitizlized variable expire

2014-09-02 Thread Boaz Harrosh
On 09/01/2014 04:50 PM, Trond Myklebust wrote:
> On Mon, Sep 1, 2014 at 7:32 AM, Shakil A Khan  wrote:
>> Signed-off-by : Shakil A Khan 
>> ---
>>  net/sunrpc/auth_gss/auth_gss.c |2 +-
>>  1 files changed, 1 insertions(+), 1 deletions(-)
>>
>> diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
>> index afb292c..bea0951 100644
>> --- a/net/sunrpc/auth_gss/auth_gss.c
>> +++ b/net/sunrpc/auth_gss/auth_gss.c
>> @@ -1387,7 +1387,7 @@ gss_key_timeout(struct rpc_cred *rc)
>> struct gss_cred *gss_cred = container_of(rc, struct gss_cred, 
>> gc_base);
>> struct gss_cl_ctx *ctx;
>> unsigned long now = jiffies;
>> -   unsigned long expire;
>> +   unsigned long expire = 0;
>>
>> rcu_read_lock();
>> ctx = rcu_dereference(gss_cred->gc_ctx);
>> --
>> 1.7.1
> 
> That would be a compiler bug, not a kernel bug. The kernel code is
> perfectly correct as it stands, and will never access the
> uninitialised variable.
> 

Than you will need the infamous uninitialised_var()

diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
index afb292c..bea0951 100644
--- a/net/sunrpc/auth_gss/auth_gss.c
+++ b/net/sunrpc/auth_gss/auth_gss.c
@@ -1387,7 +1387,7 @@ gss_key_timeout(struct rpc_cred *rc)
struct gss_cred *gss_cred = container_of(rc, struct gss_cred, gc_base);
struct gss_cl_ctx *ctx;
unsigned long now = jiffies;
-   unsigned long expire;
+   unsigned long uninitialised_var(expire);
 
rcu_read_lock();
ctx = rcu_dereference(gss_cred->gc_ctx);

Cheers
Boaz
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] Next branch: authgss: authgss.c: Fix warnings for uninitizlized variable expire

2014-09-02 Thread Boaz Harrosh
On 09/01/2014 04:50 PM, Trond Myklebust wrote:
 On Mon, Sep 1, 2014 at 7:32 AM, Shakil A Khan shakilk1...@gmail.com wrote:
 Signed-off-by : Shakil A Khan shakilk1...@gmail.com
 ---
  net/sunrpc/auth_gss/auth_gss.c |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

 diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
 index afb292c..bea0951 100644
 --- a/net/sunrpc/auth_gss/auth_gss.c
 +++ b/net/sunrpc/auth_gss/auth_gss.c
 @@ -1387,7 +1387,7 @@ gss_key_timeout(struct rpc_cred *rc)
 struct gss_cred *gss_cred = container_of(rc, struct gss_cred, 
 gc_base);
 struct gss_cl_ctx *ctx;
 unsigned long now = jiffies;
 -   unsigned long expire;
 +   unsigned long expire = 0;

 rcu_read_lock();
 ctx = rcu_dereference(gss_cred-gc_ctx);
 --
 1.7.1
 
 That would be a compiler bug, not a kernel bug. The kernel code is
 perfectly correct as it stands, and will never access the
 uninitialised variable.
 

Than you will need the infamous uninitialised_var()

diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
index afb292c..bea0951 100644
--- a/net/sunrpc/auth_gss/auth_gss.c
+++ b/net/sunrpc/auth_gss/auth_gss.c
@@ -1387,7 +1387,7 @@ gss_key_timeout(struct rpc_cred *rc)
struct gss_cred *gss_cred = container_of(rc, struct gss_cred, gc_base);
struct gss_cl_ctx *ctx;
unsigned long now = jiffies;
-   unsigned long expire;
+   unsigned long uninitialised_var(expire);
 
rcu_read_lock();
ctx = rcu_dereference(gss_cred-gc_ctx);

Cheers
Boaz
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] Next branch: authgss: authgss.c: Fix warnings for uninitizlized variable expire

2014-09-02 Thread Bruce Fields
On Tue, Sep 02, 2014 at 01:52:15PM +0300, Boaz Harrosh wrote:
 On 09/01/2014 04:50 PM, Trond Myklebust wrote:
  On Mon, Sep 1, 2014 at 7:32 AM, Shakil A Khan shakilk1...@gmail.com wrote:
  Signed-off-by : Shakil A Khan shakilk1...@gmail.com
  ---
   net/sunrpc/auth_gss/auth_gss.c |2 +-
   1 files changed, 1 insertions(+), 1 deletions(-)
 
  diff --git a/net/sunrpc/auth_gss/auth_gss.c 
  b/net/sunrpc/auth_gss/auth_gss.c
  index afb292c..bea0951 100644
  --- a/net/sunrpc/auth_gss/auth_gss.c
  +++ b/net/sunrpc/auth_gss/auth_gss.c
  @@ -1387,7 +1387,7 @@ gss_key_timeout(struct rpc_cred *rc)
  struct gss_cred *gss_cred = container_of(rc, struct gss_cred, 
  gc_base);
  struct gss_cl_ctx *ctx;
  unsigned long now = jiffies;
  -   unsigned long expire;
  +   unsigned long expire = 0;
 
  rcu_read_lock();
  ctx = rcu_dereference(gss_cred-gc_ctx);
  --
  1.7.1
  
  That would be a compiler bug, not a kernel bug. The kernel code is
  perfectly correct as it stands, and will never access the
  uninitialised variable.
  
 
 Than you will need the infamous uninitialised_var()

You'd rather avoid sprinkling that all over, though.  If nothing else it
increases the chances you'll suppress a legimate warning some day.

And unless I'm missing something this one really does look like an
unambiguous compiler bug.

--b.

 
 diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
 index afb292c..bea0951 100644
 --- a/net/sunrpc/auth_gss/auth_gss.c
 +++ b/net/sunrpc/auth_gss/auth_gss.c
 @@ -1387,7 +1387,7 @@ gss_key_timeout(struct rpc_cred *rc)
   struct gss_cred *gss_cred = container_of(rc, struct gss_cred, gc_base);
   struct gss_cl_ctx *ctx;
   unsigned long now = jiffies;
 - unsigned long expire;
 + unsigned long uninitialised_var(expire);
  
   rcu_read_lock();
   ctx = rcu_dereference(gss_cred-gc_ctx);
 
 Cheers
 Boaz
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] Next branch: authgss: authgss.c: Fix warnings for uninitizlized variable expire

2014-09-02 Thread Boaz Harrosh
On 09/02/2014 04:21 PM, Bruce Fields wrote:
 
 You'd rather avoid sprinkling that all over, though.  If nothing else it
 increases the chances you'll suppress a legimate warning some day.
 

But this is exactly why it was created.

If you do the = 0 then it is gone forever. If you have missed a legitimate
needed assignment, it will be missed as well.

But if you do the uninitialized_var() dance then there is a make option that 
turns
it off and every once in a while people do a make with it to see if it still
holds.

The diff between foo = 0; and uninitialized_var(foo) is that the programmer is
communicating to his friends that:
I have encountered a bogus compiler, this is falsely initialized

As opposed to =0 the compiler bug is covered up and forgotten

 And unless I'm missing something this one really does look like an
 unambiguous compiler bug.
 

Right! so that is how you specify this in code at Linux: uninitialized_var(foo);

Putting =0 is way way worse, because it will never be revised and specially
not automatically with a make switch.

And leaving the warning on is even worse because two three of these and people
start to ignore warnings.

 --b.
 

uninitialized_var was made to be a friend not an enemy, in the face of real
ugliness it is the best we can do. And that is what it should communicate to
everyone. Why has it become everyone's favorite blasphemy I do not know.

Cheers
Boaz

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] Next branch: authgss: authgss.c: Fix warnings for uninitizlized variable expire

2014-09-02 Thread Bruce Fields
On Tue, Sep 02, 2014 at 04:59:45PM +0300, Boaz Harrosh wrote:
 uninitialized_var was made to be a friend not an enemy, in the face of real
 ugliness it is the best we can do. And that is what it should communicate to
 everyone. Why has it become everyone's favorite blasphemy I do not know.

Not personally claiming it should never be used, just that this
particular case is kind of extreme, since unless I'm missing a real
compilication it's basically just:

if (ctx)
assign to expire
...
if (ctx)
use expire

A compiler wouldn't have to be that smart to actually prove to itself
that expire is initialized at the last step, and that it's not only
failing to do that but actually flagging it as possibly unitialized is
weird.

--b.
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] Next branch: authgss: authgss.c: Fix warnings for uninitizlized variable expire

2014-09-02 Thread Boaz Harrosh
On 09/02/2014 05:17 PM, Bruce Fields wrote:
 On Tue, Sep 02, 2014 at 04:59:45PM +0300, Boaz Harrosh wrote:
 uninitialized_var was made to be a friend not an enemy, in the face of real
 ugliness it is the best we can do. And that is what it should communicate to
 everyone. Why has it become everyone's favorite blasphemy I do not know.
 
 Not personally claiming it should never be used, just that this
 particular case is kind of extreme, since unless I'm missing a real
 compilication it's basically just:
 
   if (ctx)
   assign to expire
   ...
   if (ctx)
   use expire
 
 A compiler wouldn't have to be that smart to actually prove to itself
 that expire is initialized at the last step, and that it's not only
 failing to do that but actually flagging it as possibly unitialized is
 weird.

Actually that is a complicated case for a compiler. Because of the two
different scopes. I think it only optimizes that on higher optimization
values. Cross scope analysis is not done at parsing time but more on
code generation time, the warning is more of the former phase.

Perhaps change the code, if possible, so the assign and use of expire
is under the last if (or the first)? That would be also easier on the
reader.

BTW: You are most probably right though, because here I do not have this
 problem. I guess it is the case of an old compiler with a certain
 compilation environment.

Thanks
Boaz

 
 --b.
 

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] Next branch: authgss: authgss.c: Fix warnings for uninitizlized variable expire

2014-09-01 Thread Trond Myklebust
On Mon, Sep 1, 2014 at 7:32 AM, Shakil A Khan  wrote:
> Signed-off-by : Shakil A Khan 
> ---
>  net/sunrpc/auth_gss/auth_gss.c |2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
> index afb292c..bea0951 100644
> --- a/net/sunrpc/auth_gss/auth_gss.c
> +++ b/net/sunrpc/auth_gss/auth_gss.c
> @@ -1387,7 +1387,7 @@ gss_key_timeout(struct rpc_cred *rc)
> struct gss_cred *gss_cred = container_of(rc, struct gss_cred, 
> gc_base);
> struct gss_cl_ctx *ctx;
> unsigned long now = jiffies;
> -   unsigned long expire;
> +   unsigned long expire = 0;
>
> rcu_read_lock();
> ctx = rcu_dereference(gss_cred->gc_ctx);
> --
> 1.7.1

That would be a compiler bug, not a kernel bug. The kernel code is
perfectly correct as it stands, and will never access the
uninitialised variable.

-- 
Trond Myklebust

Linux NFS client maintainer, PrimaryData

trond.mykleb...@primarydata.com
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] Next branch: authgss: authgss.c: Fix warnings for uninitizlized variable expire

2014-09-01 Thread Trond Myklebust
On Mon, Sep 1, 2014 at 7:32 AM, Shakil A Khan shakilk1...@gmail.com wrote:
 Signed-off-by : Shakil A Khan shakilk1...@gmail.com
 ---
  net/sunrpc/auth_gss/auth_gss.c |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

 diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
 index afb292c..bea0951 100644
 --- a/net/sunrpc/auth_gss/auth_gss.c
 +++ b/net/sunrpc/auth_gss/auth_gss.c
 @@ -1387,7 +1387,7 @@ gss_key_timeout(struct rpc_cred *rc)
 struct gss_cred *gss_cred = container_of(rc, struct gss_cred, 
 gc_base);
 struct gss_cl_ctx *ctx;
 unsigned long now = jiffies;
 -   unsigned long expire;
 +   unsigned long expire = 0;

 rcu_read_lock();
 ctx = rcu_dereference(gss_cred-gc_ctx);
 --
 1.7.1

That would be a compiler bug, not a kernel bug. The kernel code is
perfectly correct as it stands, and will never access the
uninitialised variable.

-- 
Trond Myklebust

Linux NFS client maintainer, PrimaryData

trond.mykleb...@primarydata.com
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/