Re: [PATCH 0/2] Avoid -Wconstant-logical-operand in nsecs_to_jiffies_timeout()

2023-07-27 Thread Maira Canal

On 7/18/23 18:44, Nathan Chancellor wrote:

Hi all,

A proposed update to clang's -Wconstant-logical-operand [1] to warn when
the left hand side is a constant as well now triggers with the modulo
expression in nsecs_to_jiffies_timeout() when NSEC_PER_SEC is not a
multiple of HZ, such as CONFIG_HZ=300:

   drivers/gpu/drm/i915/gem/i915_gem_wait.c:189:24: warning: use of logical 
'&&' with constant operand [-Wconstant-logical-operand]
 189 | if (NSEC_PER_SEC % HZ &&
 | ~ ^
   drivers/gpu/drm/i915/gem/i915_gem_wait.c:189:24: note: use '&' for a bitwise 
operation
 189 | if (NSEC_PER_SEC % HZ &&
 |   ^~
 |   &
   drivers/gpu/drm/i915/gem/i915_gem_wait.c:189:24: note: remove constant to 
silence this warning
   1 warning generated.

   In file included from drivers/gpu/drm/v3d/v3d_debugfs.c:12:
   drivers/gpu/drm/v3d/v3d_drv.h:343:24: warning: use of logical '&&' with 
constant operand [-Wconstant-logical-operand]
 343 | if (NSEC_PER_SEC % HZ &&
 | ~ ^
   drivers/gpu/drm/v3d/v3d_drv.h:343:24: note: use '&' for a bitwise operation
 343 | if (NSEC_PER_SEC % HZ &&
 |   ^~
 |   &
   drivers/gpu/drm/v3d/v3d_drv.h:343:24: note: remove constant to silence this 
warning
   1 warning generated.

These patches add an explicit comparison to zero to make the
expression a boolean, which clears up the warning.

The patches have no real dependency on each other but I felt like they
made send together since it is the same code.

If these could go into mainline sooner rather than later to avoid
breaking builds that can hit this with CONFIG_WERROR, that would be
nice, but I won't insist since I don't think our own CI has builds that
has those conditions, but others might.

---
Nathan Chancellor (2):
   drm/v3d: Avoid -Wconstant-logical-operand in nsecs_to_jiffies_timeout()
   drm/i915: Avoid -Wconstant-logical-operand in nsecs_to_jiffies_timeout()


Applied both patches to drm-misc/drm-misc-next!

Best Regards,
- MaĆ­ra



  drivers/gpu/drm/i915/gem/i915_gem_wait.c | 2 +-
  drivers/gpu/drm/v3d/v3d_drv.h| 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
---
base-commit: fdf0eaf11452d72945af31804e2a1048ee1b574c
change-id: 
20230718-nsecs_to_jiffies_timeout-constant-logical-operand-4a944690f3e9

Best regards,


[PATCH 0/2] Avoid -Wconstant-logical-operand in nsecs_to_jiffies_timeout()

2023-07-18 Thread Nathan Chancellor
Hi all,

A proposed update to clang's -Wconstant-logical-operand [1] to warn when
the left hand side is a constant as well now triggers with the modulo
expression in nsecs_to_jiffies_timeout() when NSEC_PER_SEC is not a
multiple of HZ, such as CONFIG_HZ=300:

  drivers/gpu/drm/i915/gem/i915_gem_wait.c:189:24: warning: use of logical '&&' 
with constant operand [-Wconstant-logical-operand]
189 | if (NSEC_PER_SEC % HZ &&
| ~ ^
  drivers/gpu/drm/i915/gem/i915_gem_wait.c:189:24: note: use '&' for a bitwise 
operation
189 | if (NSEC_PER_SEC % HZ &&
|   ^~
|   &
  drivers/gpu/drm/i915/gem/i915_gem_wait.c:189:24: note: remove constant to 
silence this warning
  1 warning generated.

  In file included from drivers/gpu/drm/v3d/v3d_debugfs.c:12:
  drivers/gpu/drm/v3d/v3d_drv.h:343:24: warning: use of logical '&&' with 
constant operand [-Wconstant-logical-operand]
343 | if (NSEC_PER_SEC % HZ &&
| ~ ^
  drivers/gpu/drm/v3d/v3d_drv.h:343:24: note: use '&' for a bitwise operation
343 | if (NSEC_PER_SEC % HZ &&
|   ^~
|   &
  drivers/gpu/drm/v3d/v3d_drv.h:343:24: note: remove constant to silence this 
warning
  1 warning generated.

These patches add an explicit comparison to zero to make the
expression a boolean, which clears up the warning.

The patches have no real dependency on each other but I felt like they
made send together since it is the same code.

If these could go into mainline sooner rather than later to avoid
breaking builds that can hit this with CONFIG_WERROR, that would be
nice, but I won't insist since I don't think our own CI has builds that
has those conditions, but others might.

---
Nathan Chancellor (2):
  drm/v3d: Avoid -Wconstant-logical-operand in nsecs_to_jiffies_timeout()
  drm/i915: Avoid -Wconstant-logical-operand in nsecs_to_jiffies_timeout()

 drivers/gpu/drm/i915/gem/i915_gem_wait.c | 2 +-
 drivers/gpu/drm/v3d/v3d_drv.h| 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
---
base-commit: fdf0eaf11452d72945af31804e2a1048ee1b574c
change-id: 
20230718-nsecs_to_jiffies_timeout-constant-logical-operand-4a944690f3e9

Best regards,
-- 
Nathan Chancellor