Fix warning in drivers/usb/media/ov511.c
Subsystems (2)
PATCH 1/1 Fix warning in drivers/usb/media/ov511.c
Hello,
Gcc 4.0.2 had the warning:
drivers/usb/media/ov511.c: In function 'show_exposure':drivers/usb/media/ov511.c:5642: warning: 'exp' may be used uninitialized in this function
Here is the patch to fix that warning.
---
drivers/usb/media/ov511.c +1 -1
@@ -5639,7 +5639,7 @@ static CLASS_DEVICE_ATTR(hue, S_IRUGO, sstatic ssize_t show_exposure (struct class_device *cd,char *buf) {struct usb_ov511 *ov =cd_to_ov (cd); -unsigned char exp; +unsigned char exp ='\0' ;if (!ov->dev)return -ENODEV ;
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
Quoted 17 lines · Matthew Martin
Hello,
Gcc 4.0.2 had the warning:
drivers/usb/media/ov511.c: In function 'show_exposure':drivers/usb/media/ov511.c:5642: warning: 'exp' may be used uninitialized in this functionHere is the patch to fix that warning.
Signed-off-by Matthew Martin <[email protected]>---
drivers/usb/media/ov511.c static CLASS_DEVICE_ATTR(hue, S_IRUGO, s · line 5642
Quoted 5 lines
drivers/usb/media/ov511.c +1
-1@@ -5639,7 +5639,7 @@ static CLASS_DEVICE_ATTR(hue, S_IRUGO, sstatic ssize_t show_exposure (struct class_device *cd,char *buf) {struct usb_ov511 *ov =cd_to_ov (cd); -unsigned char exp; +unsigned char exp ='\0' ;
What's wrong with just "0" here?
thanks,
greg k-h
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
Hallo Greg,
Quoted 1 line · Greg KH
On Tue, Feb 14, 2006 at 08:21:12PM -0600, Matthew Martin wrote:
[...]
Quoted 5 lines
drivers/usb/media/ov511.c static CLASS_DEVICE_ATTR(hue, S_IRUGO, s · line 5642
Quoted 3 lines
drivers/usb/media/ov511.c +1
-1struct usb_ov511 *ov =cd_to_ov (cd); -unsigned char exp; +unsigned char exp ='\0' ;What's wrong with just "0" here?
Nothing, doesnt matter.
Regards Nico
Signature · 4 lines
Nico Golde - JAB: [email protected] | GPG: 0x73647CFF http://www.ngolde.de | http://www.muttng.org | http://grml.org Forget about that mouse with 3/4/5 buttons - gimme a keyboard with 103/104/105 keys!
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
Quoted 4 lines · Nico Golde
Hallo Greg,
Quoted 1 line · Greg KH
On Tue, Feb 14, 2006 at 08:21:12PM -0600, Matthew Martin wrote:
Quoted 8 lines
[...]
Quoted 5 lines
drivers/usb/media/ov511.c static CLASS_DEVICE_ATTR(hue, S_IRUGO, s · line 5642
Quoted 3 lines
drivers/usb/media/ov511.c +1
-1struct usb_ov511 *ov =cd_to_ov (cd); -unsigned char exp; +unsigned char exp ='\0' ;What's wrong with just "0" here?
Nothing, doesnt matter.
Great, care to redo the patch then with 0?
thanks,
greg k-h
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
PATCH 1/1 Fix warning in drivers/usb/media/ov511.c
In reply to Matthew MartinHello,
Gcc 4.0.2 had the warning:
drivers/usb/media/ov511.c: In function 'show_exposure':drivers/usb/media/ov511.c:5642: warning: 'exp' may be used uninitialized in this function
Here is the patch to fix that warning.
---
drivers/usb/media/ov511.c +1 -1
@@ -5639,7 +5639,7 @@ static CLASS_DEVICE_ATTR(hue, S_IRUGO, sstatic ssize_t show_exposure (struct class_device *cd,char *buf) {struct usb_ov511 *ov =cd_to_ov (cd); -unsigned char exp; +unsigned char exp =0 ;if (!ov->dev)return -ENODEV ;
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
Quoted 11 lines · Matthew Martin
Hello,
Gcc 4.0.2 had the warning:
drivers/usb/media/ov511.c: In function 'show_exposure':drivers/usb/media/ov511.c:5642: warning: 'exp' may be used uninitialized in this functionHere is the patch to fix that warning.
Signed-off-by Matthew Martin <lihnucks at gmail.com>
Real e-mail address please.
Thanks,
Nish
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
Quoted 5 lines · Greg KH
drivers/usb/media/ov511.c static CLASS_DEVICE_ATTR(hue, S_IRUGO, s · line 5642
Quoted 2 lines · Matthew Martin
drivers/usb/media/ov511.c +1
-1-unsigned char exp; +unsigned char exp ='\0' ;What's wrong with just "0" here?
In my opinion '\0' is the correct representation here.
'\0' ASCII nul character
0 arithmetic value zero
NULL null pointer
All of those _could_ be represented with just "0", however using 0 as such a multipurpose character/value/pointer constant is not a good idea because it makes the code less clear to read.
Linus has been very clear on that NULL and only NULL should be used for pointers, and there was a large set of patches converting from 0 to NULL in 2004.
How is '\0' vs 0 different?
BR Håkon Løvdal
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
Quoted 5 lines · H?kon L?vdal
Quoted 4 lines · Greg KH
Quoted 2 lines · Matthew Martin
drivers/usb/media/ov511.c +1
-1-unsigned char exp; +unsigned char exp ='\0' ;
Quoted 7 lines
Quoted 1 line
What's wrong with just "0" here?
In my opinion '\0' is the correct representation here.
'\0' ASCII nul character
0 arithmetic value zero
NULL null pointer
If you look at how this variable is used, it's not used as an ASCII value, but rather as a arithmetic value.
That is why I said it should be 0, not '\0'.
thanks,
greg k-h
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
Quoted 17 lines · Håkon Løvdal
Quoted 5 lines · Greg KH
drivers/usb/media/ov511.c static CLASS_DEVICE_ATTR(hue, S_IRUGO, s · line 5642
Quoted 2 lines · Matthew Martin
drivers/usb/media/ov511.c +1
-1-unsigned char exp; +unsigned char exp ='\0' ;What's wrong with just "0" here?
In my opinion '\0' is the correct representation here.
'\0' ASCII nul character
0 arithmetic value zero
NULL null pointerAll of those _could_ be represented with just "0", however using 0 as such a multipurpose character/value/pointer constant is not a good idea because it makes the code less clear to read.
Quoted 5 lines
Linus has been very clear on that NULL and only NULL should be used for pointers, and there was a large set of patches converting from 0 to NULL in 2004.
How is '\0' vs 0 different?
I didn't see any problem with using '\0' either, as long as it's meant to be a character instead of an 8-bit integer.
Looking at ov511.c, it appears to be an 8-bit integer... so 0 makes more sense to me in this case.
I find its usage more interesting. Did the patch also address this part? What does this do?
sensor_get_exposure(ov, &exp); return sprintf(buf, "%d\n", exp >> 8);
Does that always print 0? (for exp >> 8)
Signature · 6 lines
~Randy _______________________________________________ Kernel-janitors mailing list [email protected] https://lists.osdl.org/mailman/listinfo/kernel-janitors
Quoted 4 lines · Greg KH
If you look at how this variable is used, it's not used as an ASCII value, but rather as a arithmetic value.
That is why I said it should be 0, not '\0'.
Ah, I see. I must confess that I only looked at the patch itself and when '\0' was used I assumed that this was because the variable was used as a character later on. When this is not the case I have not done a good enough review. Good that someone else is :)
BR Håkon Løvdal
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
Quoted 31 lines · Randy.Dunlap
Quoted 17 lines · H?kon L?vdal
Quoted 5 lines · Greg KH
drivers/usb/media/ov511.c static CLASS_DEVICE_ATTR(hue, S_IRUGO, s · line 5642
Quoted 2 lines · Matthew Martin
drivers/usb/media/ov511.c +1
-1-unsigned char exp; +unsigned char exp ='\0' ;What's wrong with just "0" here?
In my opinion '\0' is the correct representation here.
'\0' ASCII nul character
0 arithmetic value zero
NULL null pointerAll of those _could_ be represented with just "0", however using 0 as such a multipurpose character/value/pointer constant is not a good idea because it makes the code less clear to read.
Quoted 5 lines
Linus has been very clear on that NULL and only NULL should be used for pointers, and there was a large set of patches converting from 0 to NULL in 2004.
How is '\0' vs 0 different?
I didn't see any problem with using '\0' either, as long as it's meant to be a character instead of an 8-bit integer.
Looking at
ov511.c, it appears to be an 8-bit integer... so 0 makes more sense to me in this case.
Quoted 7 lines
I find its usage more interesting. Did the patch also address this part? What does this do?
sensor_get_exposure(ov, &exp); return sprintf(buf, "%d\n", exp >> 8);Does that always print 0? (for exp >> 8)
Heh, it should :)
Anyone have this device to test this with?
thanks,
greg k-h
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
Quoted 9 lines
I find its usage more interesting. Did the patch also address this part? What does this do?
sensor_get_exposure(ov, &exp); return sprintf(buf, "%d\n", exp >> 8);Does that always print 0? (for exp >> 8)
No, the patch did not address that.
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
Quoted 4 lines · Nishanth Aravamudan
Real e-mail address please.
Thanks,
Nish
That is my real e-mail address.
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
Quoted 8 lines · Matthew Martin
Quoted 4 lines · Nishanth Aravamudan
Real e-mail address please.
Thanks,
NishThat is my real e-mail address.
You snipped the part that matters, but:
Quoted 1 line
Quoted 1 line
Signed-off-by Matthew Martin <lihnucks at gmail.com>
s/\ at\ /\@/
You did it fine with th resent patch, I think. Just wanted to make sure this one was unintentional.
Thanks,
Nish
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
Quoted 8 lines · Matthew Martin
Quoted 4 lines · Nishanth Aravamudan
Real e-mail address please.
Thanks,
NishThat is my real e-mail address.
email addresses are of the form [email protected]
while yours was listed as: addy at domain.tld
Just a small difference, that's all. No obfuscation.
Signature · 1 line
~Randy
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
[jumps from train]
Gentlemen, instead of broke-arounding non-issues, I suggest to actually read sensor_get_exposure(). You'll notice quite a few strange things for 1.5-screenful function, I promise:
drivers/usb/media/ov511.c:
1856 static int
1857 sensor_get_exposure(struct usb_ov511 *ov, unsigned char *val)
1858 {
1859 int rc;
1860
1861 switch (ov->sensor) {
1862 case SEN_OV7610:
1863 case SEN_OV6620:
1864 case SEN_OV6630:
1865 case SEN_OV7620:
1866 case SEN_OV76BE:
1867 case SEN_OV8600:
1868 rc = i2c_r(ov, 0x10);
1869 if (rc < 0)
1870 return rc;
Oops, it can return error value. So, instead checking return value of sensor_get_exposure(), you tell gcc to STFU. Notice that *val is not touched on this path.
1871 else 1872 *val = rc;
It's touched here, but the function will return 0.
1873 break; 1874 case SEN_KS0127: 1875 case SEN_KS0127B: 1876 case SEN_SAA7111A: 1877 val = NULL;
Now, who can explain this line? Change of "val" will be forgotten right after "return".
1878 PDEBUG(3, "Unsupported with this sensor"); 1879 return -EPERM;
This looks slightly bizarre. -EPERM occurs usually when Joe User tries to do something not under root.
1880 default:
1881 err("Sensor not supported for get_exposure");
1882 return -EINVAL;"Invalid argument". So there should be valid argument, right? Wrong. "Sensor not supported".
1883 } 1884 1885 PDEBUG(3, "%d", *val); 1886 ov->exposure = *val; 1887 1888 return 0; 1889 }
As was noted, "unsigned char >> 8" somewhere near line 5396 is pretty funny too.
Resume:
Patch is rejected because it's very wrong, fixes problem in the wrong place and only makes whole situation worse.
Future "may be used uninitialized" patches must contain description of code path that can lead to said uninitialized using.
Fed my pet project to 3.4.4:
-Wall -- no warnings
-Wall -O -- out little friends and I can prove they are bogus.
-Wall -O[123s] -- ditto
Alexey "warnings by commitee" Dobriyan
Quoted 9 lines · Matthew Martin
Gcc 4.0.2 had the warning:
drivers/usb/media/ov511.c: In function 'show_exposure':drivers/usb/media/ov511.c:5642: warning: 'exp' may be used uninitialized in this function
drivers/usb/media/ov511.c static CLASS_DEVICE_ATTR(hue, S_IRUGO, s · line 5645
Quoted 8 lines
drivers/usb/media/ov511.c +1
-1@@ -5639,7 +5639,7 @@ static CLASS_DEVICE_ATTR(hue, S_IRUGO, sstatic ssize_t show_exposure (struct class_device *cd,char *buf) {struct usb_ov511 *ov =cd_to_ov (cd); -unsigned char exp; +unsigned char exp =0 ;if (!ov->dev)return -ENODEV ;
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
hi alexey,
several usb drivers return -EPERM. perhaps
gkh will accept a cleanup patch for this issue.
re,
walter
Quoted 101 lines · Alexey Dobriyan
[jumps from train]
Gentlemen, instead of broke-arounding non-issues, I suggest to actually read
sensor_get_exposure(). You'll notice quite a few strange things for 1.5-screenful function, I promise:
drivers/usb/media/ov511.c:
1856 static int
1857sensor_get_exposure(struct usb_ov511 *ov, unsigned char *val)
1858 {
1859 int rc;
1860
1861 switch (ov->sensor) {
1862 caseSEN_OV7610:
1863 caseSEN_OV6620:
1864 caseSEN_OV6630:
1865 caseSEN_OV7620:
1866 caseSEN_OV76BE:
1867 caseSEN_OV8600:
1868 rc =i2c_r(ov, 0x10);
1869 if (rc < 0)
1870 return rc;Oops, it can return error value. So, instead checking return value of
sensor_get_exposure(), you tell gcc to STFU. Notice that *val is not touched on this path.1871 else 1872 *val = rc;It's touched here, but the function will return 0.
1873 break; 1874 case SEN_KS0127: 1875 case SEN_KS0127B: 1876 case SEN_SAA7111A: 1877 val = NULL;Now, who can explain this line? Change of "val" will be forgotten right after "return".
1878 PDEBUG(3, "Unsupported with this sensor"); 1879 return -EPERM;This looks slightly bizarre.
-EPERMoccurs usually when Joe User tries to do something not under root.1880 default: 1881 err("Sensor not supported for get_exposure"); 1882 return -EINVAL;"Invalid argument". So there should be valid argument, right? Wrong. "Sensor not supported".
1883 } 1884 1885 PDEBUG(3, "%d", *val); 1886 ov->exposure = *val; 1887 1888 return 0; 1889 }As was noted, "unsigned char >> 8" somewhere near line 5396 is pretty funny too.
Resume:
Patch is rejected because it's very wrong, fixes problem in the wrong place and only makes whole situation worse.Future "may be used uninitialized" patches must contain description of code path that can lead to said uninitialized using.
Fed my pet project to 3.4.4:
-Wall -- no warnings
-Wall -O -- out little friends and I can prove they are bogus.
-Wall -O[123s] -- dittoAlexey "warnings by commitee" Dobriyan
Quoted 9 lines · Matthew Martin
Gcc 4.0.2 had the warning:
drivers/usb/media/ov511.c: In function 'show_exposure':drivers/usb/media/ov511.c:5642: warning: 'exp' may be used uninitialized in this functiondrivers/usb/media/ov511.c static CLASS_DEVICE_ATTR(hue, S_IRUGO, s · line 5645
Quoted 8 lines
drivers/usb/media/ov511.c +1
-1@@ -5639,7 +5639,7 @@ static CLASS_DEVICE_ATTR(hue, S_IRUGO, sstatic ssize_t show_exposure (struct class_device *cd,char *buf) {struct usb_ov511 *ov =cd_to_ov (cd); -unsigned char exp; +unsigned char exp =0 ;if (!ov->dev)return -ENODEV ;------------------------------------------------------------------------
Quoted 4 lines
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
Quoted 3 lines · walter harms
hi alexey,
several usb drivers return-EPERM. perhaps
gkh will accept a cleanup patch for this issue.
I will gladly do so.
thanks,
greg k-h
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors