* Re: drivers/hwmon/jc42.c:477 jc42_readable_reg() warn: always true condition '(reg >= 0) => (0-u32max >= 0)' [not found] <202212222251.Xacx8c4D-lkp@intel.com> @ 2022-12-22 21:20 ` Martin Blumenstingl 2022-12-22 23:41 ` Guenter Roeck 0 siblings, 1 reply; 3+ messages in thread From: Martin Blumenstingl @ 2022-12-22 21:20 UTC (permalink / raw) To: Guenter Roeck; +Cc: kernel test robot, oe-kbuild-all, linux-kernel, linux-hwmon Hi Guenter et al., On Thu, Dec 22, 2022 at 3:36 PM kernel test robot <lkp@intel.com> 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 ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: drivers/hwmon/jc42.c:477 jc42_readable_reg() warn: always true condition '(reg >= 0) => (0-u32max >= 0)' 2022-12-22 21:20 ` drivers/hwmon/jc42.c:477 jc42_readable_reg() warn: always true condition '(reg >= 0) => (0-u32max >= 0)' Martin Blumenstingl @ 2022-12-22 23:41 ` Guenter Roeck 2022-12-25 14:18 ` Martin Blumenstingl 0 siblings, 1 reply; 3+ messages in thread From: Guenter Roeck @ 2022-12-22 23:41 UTC (permalink / raw) To: Martin Blumenstingl Cc: kernel test robot, oe-kbuild-all, linux-kernel, linux-hwmon 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 <lkp@intel.com> 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 ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: drivers/hwmon/jc42.c:477 jc42_readable_reg() warn: always true condition '(reg >= 0) => (0-u32max >= 0)' 2022-12-22 23:41 ` Guenter Roeck @ 2022-12-25 14:18 ` Martin Blumenstingl 0 siblings, 0 replies; 3+ messages in thread From: Martin Blumenstingl @ 2022-12-25 14:18 UTC (permalink / raw) To: Guenter Roeck; +Cc: kernel test robot, oe-kbuild-all, linux-kernel, linux-hwmon Hi Guenter, On Fri, Dec 23, 2022 at 12:41 AM Guenter Roeck <linux@roeck-us.net> 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 <lkp@intel.com> 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 ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-12-25 14:18 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <202212222251.Xacx8c4D-lkp@intel.com> 2022-12-22 21:20 ` drivers/hwmon/jc42.c:477 jc42_readable_reg() warn: always true condition '(reg >= 0) => (0-u32max >= 0)' Martin Blumenstingl 2022-12-22 23:41 ` Guenter Roeck 2022-12-25 14:18 ` Martin Blumenstingl
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).