tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 9d2f6060fe4c3b49d0cdc1dce1c99296f33379c8
commit: 8f2fa4726faf01094d7a5be7bd0c120c565f54d9 hwmon: (jc42) Convert register access and caching to regmap/regcache
date: 3 weeks ago
config: parisc-randconfig-m041-20221219
compiler: hppa-linux-gcc (GCC) 12.1.0
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
smatch warnings:
drivers/hwmon/jc42.c:477 jc42_readable_reg() warn: always true condition '(reg >= 0) => (0-u32max >= 0)'
vim +477 drivers/hwmon/jc42.c
474
475 static bool jc42_readable_reg(struct device *dev, unsigned int reg)
476 {
> 477 return (reg >= JC42_REG_CAP && reg <= JC42_REG_DEVICEID) ||
478 reg == JC42_REG_SMBUS;
479 }
480
--
0-DAY CI Kernel Test Service
https://01.org/lkp
Hi Guenter et al.,
On Thu, Dec 22, 2022 at 3:36 PM kernel test robot <[email protected]> wrote:
[...]
> 475 static bool jc42_readable_reg(struct device *dev, unsigned int reg)
> 476 {
> > 477 return (reg >= JC42_REG_CAP && reg <= JC42_REG_DEVICEID) ||
> 478 reg == JC42_REG_SMBUS;
The bot is right: we can omit "reg >= JC42_REG_CAP" as it's already
covered by the fact that:
- the reg variable is unsigned, which means the lower limit is zero
- reg <= JC42_REG_DEVICEID covers the upper limit
Before I send a patch I'd like to hear if removal of "reg >=
JC42_REG_CAP" makes sense to other people.
Best regards,
Martin
On Thu, Dec 22, 2022 at 10:20:13PM +0100, Martin Blumenstingl wrote:
> Hi Guenter et al.,
>
> On Thu, Dec 22, 2022 at 3:36 PM kernel test robot <[email protected]> wrote:
> [...]
> > 475 static bool jc42_readable_reg(struct device *dev, unsigned int reg)
> > 476 {
> > > 477 return (reg >= JC42_REG_CAP && reg <= JC42_REG_DEVICEID) ||
> > 478 reg == JC42_REG_SMBUS;
> The bot is right: we can omit "reg >= JC42_REG_CAP" as it's already
> covered by the fact that:
> - the reg variable is unsigned, which means the lower limit is zero
> - reg <= JC42_REG_DEVICEID covers the upper limit
>
> Before I send a patch I'd like to hear if removal of "reg >=
> JC42_REG_CAP" makes sense to other people.
>
The bot keeps complaining about it. Yes, it is technically unnecessary,
but I left it in on purpose to indicate that JC42_REG_CAP is the first
register and that it wasn't forgotten. Any modern C compiler notices
that the check is unnecessary and drops it, so there is no runtime penalty.
This is one of those situations where I'd like to have a means to tell
the checker to please stop complaining.
Guenter
Hi Guenter,
On Fri, Dec 23, 2022 at 12:41 AM Guenter Roeck <[email protected]> wrote:
>
> On Thu, Dec 22, 2022 at 10:20:13PM +0100, Martin Blumenstingl wrote:
> > Hi Guenter et al.,
> >
> > On Thu, Dec 22, 2022 at 3:36 PM kernel test robot <[email protected]> wrote:
> > [...]
> > > 475 static bool jc42_readable_reg(struct device *dev, unsigned int reg)
> > > 476 {
> > > > 477 return (reg >= JC42_REG_CAP && reg <= JC42_REG_DEVICEID) ||
> > > 478 reg == JC42_REG_SMBUS;
> > The bot is right: we can omit "reg >= JC42_REG_CAP" as it's already
> > covered by the fact that:
> > - the reg variable is unsigned, which means the lower limit is zero
> > - reg <= JC42_REG_DEVICEID covers the upper limit
> >
> > Before I send a patch I'd like to hear if removal of "reg >=
> > JC42_REG_CAP" makes sense to other people.
> >
>
> The bot keeps complaining about it. Yes, it is technically unnecessary,
> but I left it in on purpose to indicate that JC42_REG_CAP is the first
> register and that it wasn't forgotten. Any modern C compiler notices
> that the check is unnecessary and drops it, so there is no runtime penalty.
Thanks for your feedback. Since I had to double check the bot's
complaint I'll just keep this as-is (and not send any patch for this
at all).
> This is one of those situations where I'd like to have a means to tell
> the checker to please stop complaining.
I see, in some cases this may be an actual logic error (for example:
accidentally using an unsigned data type instead of a signed one).
Best regards,
Martin