public inbox for linux-ia64@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] eliminate compiler warning for xpc_channel.c
@ 2006-04-04 14:03 Dean Nelson
  2006-04-04 14:23 ` Luck, Tony
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Dean Nelson @ 2006-04-04 14:03 UTC (permalink / raw)
  To: linux-ia64

Placate a compiler warning that 'msg' may be used uninitialized in
function xpc_initiate_allocate().

Signed-off-by: Dean Nelson <dcn@sgi.com>


Index: linux-2.6/arch/ia64/sn/kernel/xpc_channel.c
=================================--- linux-2.6.orig/arch/ia64/sn/kernel/xpc_channel.c	2006-04-03 08:26:22.000000000 -0500
+++ linux-2.6/arch/ia64/sn/kernel/xpc_channel.c	2006-04-04 08:25:51.691831163 -0500
@@ -1831,7 +1831,7 @@
 {
 	struct xpc_partition *part = &xpc_partitions[partid];
 	enum xpc_retval ret = xpcUnknownReason;
-	struct xpc_msg *msg;
+	struct xpc_msg *msg = msg;
 
 
 	DBUG_ON(partid <= 0 || partid >= XP_MAX_PARTITIONS);

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

* RE: [PATCH] eliminate compiler warning for xpc_channel.c
  2006-04-04 14:03 [PATCH] eliminate compiler warning for xpc_channel.c Dean Nelson
@ 2006-04-04 14:23 ` Luck, Tony
  2006-04-04 14:27 ` Matthew Wilcox
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Luck, Tony @ 2006-04-04 14:23 UTC (permalink / raw)
  To: linux-ia64

> Placate a compiler warning that 'msg' may be used uninitialized in
> function xpc_initiate_allocate().

Which version of which compiler ... at first glance the code looks
trivially OK (&msg is passed to xpc_allocate_msg() before it is used).
On closer inspection I assume that the compiler must have inlined
xpc_allocate_msg() in order to detect this, and there are four "return"
statements in there that can return w/o doing the initialization. So
the warning is real, and we are not just "placating" the compiler.

-	struct xpc_msg *msg;
+	struct xpc_msg *msg = msg;

Did you mean to say "*msg = NULL"?

-Tony

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

* Re: [PATCH] eliminate compiler warning for xpc_channel.c
  2006-04-04 14:03 [PATCH] eliminate compiler warning for xpc_channel.c Dean Nelson
  2006-04-04 14:23 ` Luck, Tony
@ 2006-04-04 14:27 ` Matthew Wilcox
  2006-04-04 14:34 ` Luck, Tony
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Matthew Wilcox @ 2006-04-04 14:27 UTC (permalink / raw)
  To: linux-ia64

On Tue, Apr 04, 2006 at 07:23:32AM -0700, Luck, Tony wrote:
> -	struct xpc_msg *msg;
> +	struct xpc_msg *msg = msg;
> 
> Did you mean to say "*msg = NULL"?

this is actually an ANSI-permitted idiom for shutting up compiler
warnings while not actually initialising the variable.

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

* RE: [PATCH] eliminate compiler warning for xpc_channel.c
  2006-04-04 14:03 [PATCH] eliminate compiler warning for xpc_channel.c Dean Nelson
  2006-04-04 14:23 ` Luck, Tony
  2006-04-04 14:27 ` Matthew Wilcox
@ 2006-04-04 14:34 ` Luck, Tony
  2006-04-04 15:29 ` Dean Nelson
  2006-04-04 15:35 ` Luck, Tony
  4 siblings, 0 replies; 6+ messages in thread
From: Luck, Tony @ 2006-04-04 14:34 UTC (permalink / raw)
  To: linux-ia64

>> Did you mean to say "*msg = NULL"?
>
> this is actually an ANSI-permitted idiom for shutting up compiler
> warnings while not actually initialising the variable.

So I learned something new today!

But then this patch is wrong ... it shuts the compiler up
and leaves 4 ways that xpc_allocate_msg() can return without doing
the initialization, so that msg will be used uninitialized.

-Tony

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

* Re: [PATCH] eliminate compiler warning for xpc_channel.c
  2006-04-04 14:03 [PATCH] eliminate compiler warning for xpc_channel.c Dean Nelson
                   ` (2 preceding siblings ...)
  2006-04-04 14:34 ` Luck, Tony
@ 2006-04-04 15:29 ` Dean Nelson
  2006-04-04 15:35 ` Luck, Tony
  4 siblings, 0 replies; 6+ messages in thread
From: Dean Nelson @ 2006-04-04 15:29 UTC (permalink / raw)
  To: linux-ia64

On Tue, Apr 04, 2006 at 07:34:08AM -0700, Luck, Tony wrote:
> >> Did you mean to say "*msg = NULL"?
> >
> > this is actually an ANSI-permitted idiom for shutting up compiler
> > warnings while not actually initialising the variable.
> 
> So I learned something new today!
> 
> But then this patch is wrong ... it shuts the compiler up
> and leaves 4 ways that xpc_allocate_msg() can return without doing
> the initialization, so that msg will be used uninitialized.

You are correct: "*msg = NULL" is the right answer.

The compiler being used is: "gcc (GCC) 4.1.0 (SUSE Linux)".

In the past when I've seen complier warnings of this nature, it usually
(but not always) turned out that the compiler was unable to 'see' that
things were really okay. In this particular case, I hadn't seen this
warning until just yesterday (my build machine was just updated a few
days ago), and since nothing in this area of the code had changed for
some time now, I just assumed that the compiler was not seeing things
properly. It didn't occur to me that xpc_allocate_msg() was possibly
being inlined and thus the compiler was giving a correct warning that
should not be ignored.

Do you want a new patch, or are you comfortable with switching the
'msg' to a 'NULL'?

Thanks for looking more closely than I obviously did.

Dean


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

* RE: [PATCH] eliminate compiler warning for xpc_channel.c
  2006-04-04 14:03 [PATCH] eliminate compiler warning for xpc_channel.c Dean Nelson
                   ` (3 preceding siblings ...)
  2006-04-04 15:29 ` Dean Nelson
@ 2006-04-04 15:35 ` Luck, Tony
  4 siblings, 0 replies; 6+ messages in thread
From: Luck, Tony @ 2006-04-04 15:35 UTC (permalink / raw)
  To: linux-ia64

> Do you want a new patch, or are you comfortable with switching the
> 'msg' to a 'NULL'?

I'll switch it to NULL.

-Tony

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

end of thread, other threads:[~2006-04-04 15:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-04-04 14:03 [PATCH] eliminate compiler warning for xpc_channel.c Dean Nelson
2006-04-04 14:23 ` Luck, Tony
2006-04-04 14:27 ` Matthew Wilcox
2006-04-04 14:34 ` Luck, Tony
2006-04-04 15:29 ` Dean Nelson
2006-04-04 15:35 ` Luck, Tony

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