media: v4l2-device.h: Explicitly compare grpmask to zero in v4l2_device_mask_call_all
PATCH 1/1 media: v4l2-device.h: Explicitly compare grpmask to zero in v4l2_device_mask_call_all
When building with Clang + -Wtautological-constant-compare, several of the ivtv drivers warn along the lines of:
drivers/media/pci/cx18/cx18-driver.c:1005:21: warning: converting the result of '<<' to a boolean always evaluates to true [-Wtautological-constant-compare]
cx18_call_hw(cx, CX18_HW_GPIO_RESET_CTRL,
^
drivers/media/pci/cx18/cx18-cards.h:18:37: note: expanded from macro
'CX18_HW_GPIO_RESET_CTRL'
#define CX18_HW_GPIO_RESET_CTRL (1 << 6)
^1 warning generated.
This is because the shift operation is implicitly converted to a boolean in v4l2_device_mask_call_all before being negated. This can be solved by just comparing the mask result to 0 explicity so that there is no boolean conversion.
---
I am aware that there is suddenly a style mismatch (some macros using !(grpmask) and this one using (grpmask) == 0) but I chose to display the minimal fix. If you want me to update all the macros to use this style, I'd be happy to in a followup patch.
There are 19 of these warnings in the drivers/media/pci folder, which can be seen here:
https://github.com/ClangBuiltLinux/linux/issues/488#issuecomment-545218125
This is the simplest fix but if you all prefer an alternative one, I would be happy to see/review/test it. The ultimate goal is to get -Wtautological-compare enabled because there are several subwarnings that would be helpful to have and right now they are all disabled:
https://github.com/ClangBuiltLinux/linux/issues/488
include/media/v4l2-device.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/media/v4l2-device.h +2 -2
@@ -431,8 +431,8 @@ static inline bool v4l2_device_supports_requests(struct v4l2_device *v4l2_dev)struct v4l2_subdev *__sd; \ \__v4l2_device_call_subdevs_p (v4l2_dev, __sd, \ - !(grpmsk) || (__sd->grp_id & (grpmsk)), o, f , \ - ##args); \ + (grpmsk) ==0 || (__sd->grp_id & (grpmsk)), o, \ + f , ##args); \ }while (0 )/**
Signature · 1 line
2.24.0.rc1
Quoted 13 lines · Nathan Chancellor
When building with Clang + -Wtautological-constant-compare, several of the ivtv drivers warn along the lines of:
drivers/media/pci/cx18/cx18-driver.c:1005:21: warning: converting the result of '<<' to a boolean always evaluates to true [-Wtautological-constant-compare]cx18_call_hw(cx, CX18_HW_GPIO_RESET_CTRL, ^ drivers/media/pci/cx18/cx18-cards.h:18:37: note: expanded from macro 'CX18_HW_GPIO_RESET_CTRL' #define CX18_HW_GPIO_RESET_CTRL (1 << 6) ^
Quoted 5 lines
1 warning generated.
This is because the shift operation is implicitly converted to a boolean in
v4l2_device_mask_call_allbefore being negated. This can be solved by just comparing the mask result to 0 explicity so that there is no
s/explicity/explicitly/
Harmless enough change, thanks for the patch, and sorry for taking so long to review.
Quoted 42 lines
boolean conversion.
Signed-off-by Nathan Chancellor <[email protected]>---
I am aware that there is suddenly a style mismatch (some macros using !(grpmask) and this one using (grpmask) == 0) but I chose to display the minimal fix. If you want me to update all the macros to use this style, I'd be happy to in a followup patch.
There are 19 of these warnings in the
drivers/media/pcifolder, which can be seen here:https://github.com/ClangBuiltLinux/linux/issues/488#issuecomment-545218125
This is the simplest fix but if you all prefer an alternative one, I would be happy to see/review/test it. The ultimate goal is to get -Wtautological-compare enabled because there are several subwarnings that would be helpful to have and right now they are all disabled:
https://github.com/ClangBuiltLinux/linux/issues/488
include/media/v4l2-device.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)include/media/v4l2-device.h +2
-3@@ -431,8 +431,8 @@ static inline bool v4l2_device_supports_requests(struct v4l2_device *v4l2_dev)struct v4l2_subdev *__sd; \ \__v4l2_device_call_subdevs_p (v4l2_dev, __sd, \ - !(grpmsk) || (__sd->grp_id & (grpmsk)), o, f , \ - ##args); \ + (grpmsk) ==0 || (__sd->grp_id & (grpmsk)), o, \ + f , ##args); \ }while (0 )/** --
Signature · 2 lines
Thanks, ~Nick Desaulniers
PATCH v2 1/1 media: v4l2-device.h: Explicitly compare grpmask to zero in v4l2_device_mask_call_all
In reply to Nathan ChancellorWhen building with Clang + -Wtautological-constant-compare, several of the ivtv drivers warn along the lines of:
drivers/media/pci/cx18/cx18-driver.c:1005:21: warning: converting the result of '<<' to a boolean always evaluates to true [-Wtautological-constant-compare]
cx18_call_hw(cx, CX18_HW_GPIO_RESET_CTRL,
^
drivers/media/pci/cx18/cx18-cards.h:18:37: note: expanded from macro
'CX18_HW_GPIO_RESET_CTRL'
#define CX18_HW_GPIO_RESET_CTRL (1 << 6)
^1 warning generated.
This is because the shift operation is implicitly converted to a boolean in v4l2_device_mask_call_all before being negated. This can be solved by just comparing the mask result to 0 explicitly so that there is no boolean conversion.
---
v1 -> v2: https://lore.kernel.org/lkml/[email protected]/
* Fix typo in commit message
* Add Nick's Reviewed-by.
include/media/v4l2-device.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/media/v4l2-device.h +2 -2
@@ -431,8 +431,8 @@ static inline bool v4l2_device_supports_requests(struct v4l2_device *v4l2_dev)struct v4l2_subdev *__sd; \ \__v4l2_device_call_subdevs_p (v4l2_dev, __sd, \ - !(grpmsk) || (__sd->grp_id & (grpmsk)), o, f , \ - ##args); \ + (grpmsk) ==0 || (__sd->grp_id & (grpmsk)), o, \ + f , ##args); \ }while (0 )/**
Signature · 1 line
2.24.0
Bumping for review.
Quoted 51 lines · Nathan Chancellor
When building with Clang + -Wtautological-constant-compare, several of the ivtv drivers warn along the lines of:
drivers/media/pci/cx18/cx18-driver.c:1005:21: warning: converting the result of '<<' to a boolean always evaluates to true [-Wtautological-constant-compare]cx18_call_hw(cx, CX18_HW_GPIO_RESET_CTRL, ^ drivers/media/pci/cx18/cx18-cards.h:18:37: note: expanded from macro 'CX18_HW_GPIO_RESET_CTRL' #define CX18_HW_GPIO_RESET_CTRL (1 << 6) ^1 warning generated.
This is because the shift operation is implicitly converted to a boolean in
v4l2_device_mask_call_allbefore being negated. This can be solved by just comparing the mask result to 0 explicitly so that there is no boolean conversion.Reviewed-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>---
v1 -> v2: https://lore.kernel.org/lkml/[email protected]/
* Fix typo in commit message
* Add Nick's Reviewed-by.include/media/v4l2-device.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)include/media/v4l2-device.h +2
-3@@ -431,8 +431,8 @@ static inline bool v4l2_device_supports_requests(struct v4l2_device *v4l2_dev)struct v4l2_subdev *__sd; \ \__v4l2_device_call_subdevs_p (v4l2_dev, __sd, \ - !(grpmsk) || (__sd->grp_id & (grpmsk)), o, f , \ - ##args); \ + (grpmsk) ==0 || (__sd->grp_id & (grpmsk)), o, \ + f , ##args); \ }while (0 )/** -- 2.24.0
Signature · 2 lines
Thanks, ~Nick Desaulniers
(Adding Hans)
Hi Nathan, Nick,
Thanks for the patch (and the patience).
Quoted 3 lines · Nathan Chancellor
When building with Clang + -Wtautological-constant-compare, several of the ivtv drivers warn along the lines of:
Nitpick: s/ivtv/ivtv and cx18
Quoted 9 lines
drivers/media/pci/cx18/cx18-driver.c:1005:21: warning: converting the result of '<<' to a boolean always evaluates to true [-Wtautological-constant-compare]cx18_call_hw(cx, CX18_HW_GPIO_RESET_CTRL, ^ drivers/media/pci/cx18/cx18-cards.h:18:37: note: expanded from macro 'CX18_HW_GPIO_RESET_CTRL' #define CX18_HW_GPIO_RESET_CTRL (1 << 6) ^
Quoted 7 lines
1 warning generated.
This is because the shift operation is implicitly converted to a boolean in
v4l2_device_mask_call_allbefore being negated. This can be solved by just comparing the mask result to 0 explicitly so that there is no boolean conversion.
Perhaps it's interesting to mention the reason for this change, which you mentioned as a comment before:
"""
The ultimate goal is to get
-Wtautological-compare enabled because there are several subwarnings that would be helpful to have and right now they are all disabled. """
Quoted 18 lines
Reviewed-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>---
v1 -> v2: https://lore.kernel.org/lkml/[email protected]/
* Fix typo in commit message
* Add Nick's Reviewed-by.include/media/v4l2-device.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)include/media/v4l2-device.h +0
-0
include/media/v4l2-device.h static inline bool v4l2_device_supports_requests(struct v4l2_device *v4l2_dev) · line 438
Quoted 10 lines
include/media/v4l2-device.h +2
-2@@ -431,8 +431,8 @@ static inline bool v4l2_device_supports_requests(struct v4l2_device *v4l2_dev)struct v4l2_subdev *__sd; \ \__v4l2_device_call_subdevs_p (v4l2_dev, __sd, \ - !(grpmsk) || (__sd->grp_id & (grpmsk)), o, f , \ - ##args); \ + (grpmsk) ==0 || (__sd->grp_id & (grpmsk)), o, \ + f , ##args); \ }while (0 )/**
The change is small enough and if it helps enabling helpful warnings, then it seems a good idea.
For consistency, it would be good to also patch the other case(s).
Thanks,
Ezequiel
PATCH v3 1/1 media: v4l2-device.h: Explicitly compare grp{id,mask} to zero in v4l2_device macros
In reply to Nathan ChancellorWhen building with Clang + -Wtautological-constant-compare, several of the ivtv and cx18 drivers warn along the lines of:
drivers/media/pci/cx18/cx18-driver.c:1005:21: warning: converting the result of '<<' to a boolean always evaluates to true [-Wtautological-constant-compare]
cx18_call_hw(cx, CX18_HW_GPIO_RESET_CTRL,
^
drivers/media/pci/cx18/cx18-cards.h:18:37: note: expanded from macro
'CX18_HW_GPIO_RESET_CTRL'
#define CX18_HW_GPIO_RESET_CTRL (1 << 6)
^1 warning generated.
This warning happens because the shift operation is implicitly converted to a boolean in v4l2_device_mask_call_all before being negated. This can be solved by just comparing the mask result to 0 explicitly so that there is no boolean conversion. The ultimate goal is to enable -Wtautological-compare globally because there are several subwarnings that would be helpful to have.
For visual consistency and avoidance of these warnings in the future, all of the implicitly boolean conversions in the v4l2_device macros are converted to explicit ones as well.
---
v1 -> v2: https://lore.kernel.org/lkml/[email protected]/
* Fix typo in commit message
* Add Nick's Reviewed-by.
v2 -> v3: https://lore.kernel.org/lkml/[email protected]/
* Improve reasoning for change (Ezequiel)
* Patch all implicit boolean conversions (Ezequiel)
* Add Ezequiel's reviewed-by.
include/media/v4l2-device.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
include/media/v4l2-device.h +6 -6
@@ -371,7 +371,7 @@ static inline bool v4l2_device_supports_requests(struct v4l2_device *v4l2_dev)struct v4l2_subdev *__sd; \ \__v4l2_device_call_subdevs_p (v4l2_dev, __sd, \ - !(grpid) || __sd->grp_id == (grpid), o, f , \ + (grpid) == 0 || __sd->grp_id == (grpid), o, f , \ ##args); \ }while (0 )
@@ -403,7 +403,7 @@ static inline bool v4l2_device_supports_requests(struct v4l2_device *v4l2_dev) ({ \struct v4l2_subdev *__sd; \__v4l2_device_call_subdevs_until_err_p (v4l2_dev, __sd, \ - !(grpid) || __sd->grp_id == (grpid), o, f , \ + (grpid) == 0 || __sd->grp_id == (grpid), o, f , \ ##args); \ })
@@ -431,8 +431,8 @@ static inline bool v4l2_device_supports_requests(struct v4l2_device *v4l2_dev)struct v4l2_subdev *__sd; \ \__v4l2_device_call_subdevs_p (v4l2_dev, __sd, \ - !(grpmsk) || (__sd->grp_id & (grpmsk)), o, f , \ - ##args); \ + (grpmsk) ==0 || (__sd->grp_id & (grpmsk)), o, \ + f , ##args); \ }while (0 )/**
@@ -462,8 +462,8 @@ static inline bool v4l2_device_supports_requests(struct v4l2_device *v4l2_dev) ({ \struct v4l2_subdev *__sd; \__v4l2_device_call_subdevs_until_err_p (v4l2_dev, __sd, \ - !(grpmsk) || (__sd->grp_id & (grpmsk)), o, f , \ - ##args); \ + (grpmsk) ==0 || (__sd->grp_id & (grpmsk)), o, \ + f , ##args); \ })
Signature · 1 line
2.24.0