Skip to contentSkip to conversation

misc: suppress build warning

PATCH In review Lad, Prabhakar 4 participants 5 messages Dec 4, 2014 – Dec 5, 2014 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 misc: suppress build warning

this patch fixes following build warning:

drivers/misc/ioc4.c: In function ‘ioc4_probe’:
drivers/misc/ioc4.c:194:16: warning: ‘start’ may be used uninitialized in this function [-Wmaybe-uninitialized]
period = (end - start) /

                ^

drivers/misc/ioc4.c:148:11: note: ‘start’ was declared here
uint64_t start, end, period;

---
Note:- I have compile tested only, and this was noticed on linux-next

 drivers/misc/ioc4.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/ioc4.c +1 -1
index 3336ddc..c1f1e6c 100644
@@ -145,7 +145,7 @@ ioc4_clock_calibrate(struct ioc4_driver_data *idd)
 	union ioc4_int_out int_out;
 	union ioc4_gpcr gpcr;
 	unsigned int state, last_state = 1;
-	uint64_t start, end, period;
+	uint64_t start = 0, end, period;
 	unsigned int count = 0;
 
 	/* Enable output */
Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 10 lines · Prabhakar

this patch fixes following build warning:

drivers/misc/ioc4.c: In function ‘ioc4_probe’:
drivers/misc/ioc4.c:194:16: warning: ‘start’ may be used uninitialized in this function [-Wmaybe-uninitialized]
period = (end - start) /

                ^

drivers/misc/ioc4.c:148:11: note: ‘start’ was declared here
uint64_t start, end, period;

Please explain why the compiler thinks there is a bug, why you are sure that there isn't, and why you picked '0' as the initialization value.

Arnd

#2 lore raw
Quoted 10 lines · Arnd Bergmann
Quoted 9 lines · Prabhakar

this patch fixes following build warning:

drivers/misc/ioc4.c: In function ‘ioc4_probe’:
drivers/misc/ioc4.c:194:16: warning: ‘start’ may be used uninitialized in this function [-Wmaybe-uninitialized]
period = (end - start) /

                ^

drivers/misc/ioc4.c:148:11: note: ‘start’ was declared here
uint64_t start, end, period;

Quoted 6 lines
Quoted 1 line

Please explain why the compiler thinks there is a bug, why you are sure that there isn't, and why you picked '0' as the initialization value.

Its a false positive, to suppress the warning '0' was picked.

Thanks,
--Prabhakar Lad

#3 lore raw
Quoted 11 lines · Prabhakar Lad
Quoted 10 lines · Arnd Bergmann
Quoted 9 lines · Prabhakar

this patch fixes following build warning:

drivers/misc/ioc4.c: In function ‘ioc4_probe’:
drivers/misc/ioc4.c:194:16: warning: ‘start’ may be used uninitialized in this function [-Wmaybe-uninitialized]
period = (end - start) /

                ^

drivers/misc/ioc4.c:148:11: note: ‘start’ was declared here
uint64_t start, end, period;

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

Please explain why the compiler thinks there is a bug, why you are sure that there isn't, and why you picked '0' as the initialization value.

Its a false positive, to suppress the warning '0' was picked.

Are you _sure_ it's a false positive? That odd do/while loop looks like it might just not ever initialize the start variable, are you sure the logic there is correct?

thanks,

greg k-h

#4 lore raw
Quoted 18 lines · On Thu, 4 Dec 2014 08:30:32 -0800 Greg Kroah-Hartman…
Quoted 17 lines · Prabhakar Lad
Quoted 16 lines · Arnd Bergmann
Quoted 10 lines · Prabhakar

this patch fixes following build warning:

drivers/misc/ioc4.c: In function ___ioc4_probe___:
drivers/misc/ioc4.c:194:16: warning: ___start___ may be used uninitialized in this function [-Wmaybe-uninitialized]
period = (end - start) /

                ^

drivers/misc/ioc4.c:148:11: note: ___start___ was declared here
uint64_t start, end, period;

Please explain why the compiler thinks there is a bug, why you are sure that there isn't, and why you picked '0' as the initialization value.

Quoted 6 lines
Quoted 1 line

Its a false positive, to suppress the warning '0' was picked.

Are you _sure_ it's a false positive? That odd do/while loop looks like it might just not ever initialize the start variable, are you sure the logic there is correct?

As long as IOC4_CALIBRATE_END is greater than IOC4_CALIBRATE_DISCARD (it is), `start' is written to.

It would be nice to simplify the code, but I'm not sure how.

And I really dislike this initialize-it-to-zero-to-stop-the-warning thing which we do all over the place. The reader doesn't know *why* it's initialized to zero and the initialization can conceal bugs if we get a code path which should have written to it but forgot to. And it adds unneeded code to vlinux.

I much prefer unintialized_var() which fixes the documentation issue and doesn't add code. But Linus and Ingo had a dummy-spit over it.