Skip to contentSkip to conversation

pinctrl: single: fix a never true comparison

PATCH New Dario Binacchi 3 participants 3 messages Apr 22, 2021 – Apr 27, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index 48bdd0f6f5..7e1c5bb0a5 100644
@@ -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
#1 lore raw

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.

---

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 +0 -0
index 48bdd0f6f5..7e1c5bb0a5 100644

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 -1
 			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
Signature · 3 lines
Regards,
Pratyush Yadav
Texas Instruments Inc.
#2 lore raw

PATCH v2 1/1 pinctrl: single: fix a never true comparison

In reply to Dario Binacchi
Quoted 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.

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>