Staging: comedidev.h comedi_lrange should be const struct
A message that is not in the archive (sent off-list or not yet received): 20170409194120.GA23199@Leliel
Quoted 25 lines · Greg KH
Quoted 13 lines · Arthur Brainville (Ybalrid)
According to checkpatch.pl,
comedi_lrangeshould be declared asconst structinstead ofstructindriver/staging/comedidev.hSigned-off-by Arthur Brainville (Ybalrid) <[email protected]>--- drivers/staging/comedi/comedidev.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/staging/comedi/comedidev.h +0
-0drivers/staging/comedi/comedidev.h extern const struct comedi_lrange range_unknown; · line 629
Quoted 8 lines
drivers/staging/comedi/comedidev.h +1
-1@@ -623,7 +623,7 @@ extern const struct comedi_lrange range_unknown;* There may also be a flag that indicates the minimum and maximum are merely * scale factors for an unknown, external reference. */ -struct comedi_lrange { +const struct comedi_lrange {int length;struct comedi_krange range[]; };Huh? Please explain how this change is correct.
Quoted 1 line
greg k-h
First of all, thanks for taking the time to reply! Well, sorry if I did something wrong, I'm a newbie here, so let me explain:
When checking a bunch of files with /script/checkpatch.pl -f on the staging directory, it gave me this output:
Quoted 9 lines
WARNING: struct
comedi_lrangeshould normally be const #626: FILE:drivers/staging/comedi/comedidev.h:626:
+structcomedi_lrange{total: 0 errors, 1 warnings, 6 checks, 1043 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
For this specific header.
Declaring it as const struct fixes that coding style warning, and
doesn't break the build but, AFAIK isn't actually meaningfull since it's declaring a struct, but not any variable of type "comedi_lrange" at this point. And it built fine.
I was watching an old talk (from you) about how you can send a patch to
correct this kind of little things, so I tried.
Looking further into it, it seems that this change makes GCC trigger the following warning in any file that #include it :
Quoted 5 lines
In file included from drivers/staging/comedi//comedi_usb.h:24:0,
from drivers/staging/comedi//comedi_usb.c:21: drivers/staging/comedi//comedidev.h:629:1: warning: useless type qualifier in empty declaration };
So, probably not good?
Like I said here the const qualifier doen't change anything, you could create a struct comedi_lrange variable with some initialization, and change it later, it will not be const, unless declared so at that
point.
It was just to make this file pass the checkpatch perl script without warning, but it makes the staging comedi driver compile with warnings.
It doesn't change anything "functionally", if you see what I mean.
Quoted 56 lines · Arthur Brainville
Quoted 25 lines · Greg KH
Quoted 13 lines · Arthur Brainville (Ybalrid)
According to checkpatch.pl,
comedi_lrangeshould be declared asconst structinstead ofstructindriver/staging/comedidev.hSigned-off-by Arthur Brainville (Ybalrid) <[email protected]>--- drivers/staging/comedi/comedidev.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/staging/comedi/comedidev.h +0
-0drivers/staging/comedi/comedidev.h extern const struct comedi_lrange range_unknown; · line 629
Quoted 8 lines
drivers/staging/comedi/comedidev.h +1
-1@@ -623,7 +623,7 @@ extern const struct comedi_lrange range_unknown;* There may also be a flag that indicates the minimum and maximum are merely * scale factors for an unknown, external reference. */ -struct comedi_lrange { +const struct comedi_lrange {int length;struct comedi_krange range[]; };Huh? Please explain how this change is correct.
Quoted 1 line
greg k-h
First of all, thanks for taking the time to reply! Well, sorry if I did something wrong, I'm a newbie here, so let me explain:
When checking a bunch of files with /script/checkpatch.pl -f on the staging directory, it gave me this output:
Quoted 9 lines
WARNING: struct
comedi_lrangeshould normally be const #626: FILE:drivers/staging/comedi/comedidev.h:626:
+structcomedi_lrange{total: 0 errors, 1 warnings, 6 checks, 1043 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.For this specific header.
Declaring it as const struct fixes that coding style warning, and doesn't break the build but, AFAIK isn't actually meaningfull since it's declaring a struct, but not any variable of type "
comedi_lrange" at this point. And it built fine.
I was watching an old talk (from you) about how you can send a patch to correct this kind of little things, so I tried.Looking further into it, it seems that this change makes GCC trigger the following warning in any file that #include it :
Quoted 7 lines
Quoted 5 lines
In file included from drivers/staging/comedi//comedi_usb.h:24:0,
from drivers/staging/comedi//comedi_usb.c:21: drivers/staging/comedi//comedidev.h:629:1: warning: useless type qualifier in empty declaration };So, probably not good?
You should always test-build your patches, and they can never add new kernel warnings to the build, that's not allowed at all. So please do that next time, it should have shown you that this was not a good change.
And as you have found out, checkpatch.pl is a dumb tool, you still have to think when you use it. And if you know C, you will know that the change you made makes no sense at all :)
thanks,
greg k-h
Quoted 70 lines · Greg KH
Quoted 56 lines · Arthur Brainville
Quoted 25 lines · Greg KH
Quoted 13 lines · Arthur Brainville (Ybalrid)
According to checkpatch.pl,
comedi_lrangeshould be declared asconst structinstead ofstructindriver/staging/comedidev.hSigned-off-by Arthur Brainville (Ybalrid) <[email protected]>--- drivers/staging/comedi/comedidev.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/staging/comedi/comedidev.h +0
-0drivers/staging/comedi/comedidev.h extern const struct comedi_lrange range_unknown; · line 629
Quoted 8 lines
drivers/staging/comedi/comedidev.h +1
-1@@ -623,7 +623,7 @@ extern const struct comedi_lrange range_unknown;* There may also be a flag that indicates the minimum and maximum are merely * scale factors for an unknown, external reference. */ -struct comedi_lrange { +const struct comedi_lrange {int length;struct comedi_krange range[]; };Huh? Please explain how this change is correct.
Quoted 1 line
greg k-h
First of all, thanks for taking the time to reply! Well, sorry if I did something wrong, I'm a newbie here, so let me explain:
When checking a bunch of files with /script/checkpatch.pl -f on the staging directory, it gave me this output:
Quoted 9 lines
WARNING: struct
comedi_lrangeshould normally be const #626: FILE:drivers/staging/comedi/comedidev.h:626:
+structcomedi_lrange{total: 0 errors, 1 warnings, 6 checks, 1043 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.For this specific header.
Declaring it as const struct fixes that coding style warning, and doesn't break the build but, AFAIK isn't actually meaningfull since it's declaring a struct, but not any variable of type "
comedi_lrange" at this point. And it built fine.
I was watching an old talk (from you) about how you can send a patch to correct this kind of little things, so I tried.Looking further into it, it seems that this change makes GCC trigger the following warning in any file that #include it :
Quoted 7 lines
Quoted 5 lines
In file included from drivers/staging/comedi//comedi_usb.h:24:0,
from drivers/staging/comedi//comedi_usb.c:21: drivers/staging/comedi//comedidev.h:629:1: warning: useless type qualifier in empty declaration };So, probably not good?
You should always test-build your patches, and they can never add new kernel warnings to the build, that's not allowed at all. So please do that next time, it should have shown you that this was not a good change.
Quoted 7 lines
And as you have found out, checkpatch.pl is a dumb tool, you still have to think when you use it. And if you know C, you will know that the change you made makes no sense at all :)
thanks,
greg k-h
Lesson learned!
(It did build. But well, I don't know what I was thinking not paying attentions to theses warning. Shame on me!)
Thank you again for your patience Greg :)
Arthur Brainville