pinctrl: single: fix a never true comparison
Subsystems (2)
PATCH v2 1/1 pinctrl: single: fix a never true comparison
As reported by Coverity Scan for Das U-Boot, the 'less-than-zero' comparison of an unsigned value is never true.
---
Changes in v2:
- Balance quote in commit message
- Add review tag
drivers/pinctrl/pinctrl-single.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pinctrl/pinctrl-single.c +2 -2
@@ -295,7 +295,7 @@ static int single_configure_pins(struct udevice *dev, func->npins =0 ;for (n =0 ; n < count; n++, pins++) { offset =fdt32_to_cpu (pins->reg); -if (offset <0 || offset > pdata->offset) { +if (offset > pdata->offset) {dev_err (dev," invalid register offset 0x%x\n" , offset);continue ;
@@ -344,7 +344,7 @@ static int single_configure_bits(struct udevice *dev, func->npins =0 ;for (n =0 ; n < count; n++, pins++) { offset =fdt32_to_cpu (pins->reg); -if (offset <0 || offset > pdata->offset) { +if (offset > pdata->offset) {dev_dbg (dev," invalid register offset 0x%x\n" , offset);continue ;
Signature · 1 line
2.17.1
PATCH v2 1/1 pinctrl: single: fix a never true comparison
Quoted 20 lines · Dario Binacchi
As reported by Coverity Scan for Das U-Boot, the 'less-than-zero' comparison of an unsigned value is never true.
Signed-off-by Dario Binacchi <[email protected]>Reviewed-by Pratyush Yadav <[email protected]>---
Changes in v2:
- Balance quote in commit message
- Add review tagdrivers/pinctrl/pinctrl-single.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/pinctrl/pinctrl-single.c +0
-0
drivers/pinctrl/pinctrl-single.c static int single_configure_pins(struct udevice *dev, · line 298
Quoted 5 lines
drivers/pinctrl/pinctrl-single.c +1
-1@@ -295,7 +295,7 @@ static int single_configure_pins(struct udevice *dev, func->npins =0 ;for (n =0 ; n < count; n++, pins++) { offset =fdt32_to_cpu (pins->reg); -if (offset <0 || offset > pdata->offset) { +if (offset > pdata->offset) {
I went back and took a look at it again. The "offset < 0" comes from "reg < 0" in 9b884e79a6 (pinctrl: single: fix offset management, 2021-04-11), where reg is of type phys_addr_t. But phys_addr_t is also an unsigned value so I suppose the check was wrong to begin with. And fdt32_to_cpu() just does byte order conversions so it shouldn't return a negative value because there is no scope for failure.
So again, the patch looks good to me, but some added context for anyone interested.
Quoted 15 lines
drivers/pinctrl/pinctrl-single.c +1
-1dev_err (dev," invalid register offset 0x%x\n" , offset);continue ;@@ -344,7 +344,7 @@ static int single_configure_bits(struct udevice *dev, func->npins =0 ;for (n =0 ; n < count; n++, pins++) { offset =fdt32_to_cpu (pins->reg); -if (offset <0 || offset > pdata->offset) { +if (offset > pdata->offset) {dev_dbg (dev," invalid register offset 0x%x\n" , offset);continue ;Signature · 1 line
2.17.1
Signature · 3 lines
Regards, Pratyush Yadav Texas Instruments Inc.
PATCH v2 1/1 pinctrl: single: fix a never true comparison
In reply to Dario BinacchiQuoted 5 lines · Dario Binacchi
As reported by Coverity Scan for Das U-Boot, the 'less-than-zero' comparison of an unsigned value is never true.
Signed-off-by Dario Binacchi <[email protected]>Reviewed-by Pratyush Yadav <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210427/75048150/attachment.sig>