Skip to contentSkip to conversation

pinctrl: rzn1: Fix check for used MDIO bus

PATCH Superseded Phil Edworthy 2 participants 3 messages Oct 12, 2018 – Oct 15, 2018 Pin control

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pinctrl: rzn1: Fix check for used MDIO bus

This fixes the check for unused mdio bus setting and the following static checker warning:
drivers/pinctrl/pinctrl-rzn1.c:198 rzn1_pinctrl_mdio_select()
warn: always true condition '(ipctl->mdio_func[mdio] >= 0) => (0-u32max >= 0)'

---
 drivers/pinctrl/pinctrl-rzn1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/pinctrl-rzn1.c +1 -1
index ce05e3a00be2..f688f3a29dfd 100644
@@ -195,7 +195,7 @@ static void rzn1_hw_set_lock(struct rzn1_pinctrl *ipctl, u8 lock, u8 value)
 static void rzn1_pinctrl_mdio_select(struct rzn1_pinctrl *ipctl, int mdio,
 				     u32 func)
 {
-	if (ipctl->mdio_func[mdio] >= 0 && ipctl->mdio_func[mdio] != func)
+	if (ipctl->mdio_func[mdio] != -1 && ipctl->mdio_func[mdio] != func)
 		dev_warn(ipctl->dev, "conflicting setting for mdio%d!\n", mdio);
 	ipctl->mdio_func[mdio] = func;
 
Signature · 1 line
2.17.1
#1 lore raw

Hi Phil,

Quoted 16 lines · Phil Edworthy

This fixes the check for unused mdio bus setting and the following static checker warning:
drivers/pinctrl/pinctrl-rzn1.c:198 rzn1_pinctrl_mdio_select()
warn: always true condition '(ipctl->mdio_func[mdio] >= 0) => (0-u32max >= 0)'

---
 drivers/pinctrl/pinctrl-rzn1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/pinctrl-rzn1.c +0 -0
index ce05e3a00be2..f688f3a29dfd 100644

drivers/pinctrl/pinctrl-rzn1.c static void rzn1_hw_set_lock(struct rzn1_pinctrl *ipctl, u8 lock, u8 value) · line 201

Quoted 8 lines
drivers/pinctrl/pinctrl-rzn1.c +1 -1
@@ -195,7 +195,7 @@ static void rzn1_hw_set_lock(struct rzn1_pinctrl *ipctl, u8 lock, u8 value)
 static void rzn1_pinctrl_mdio_select(struct rzn1_pinctrl *ipctl, int mdio,
 				     u32 func)
 {
-	if (ipctl->mdio_func[mdio] >= 0 && ipctl->mdio_func[mdio] != func)
+	if (ipctl->mdio_func[mdio] != -1 && ipctl->mdio_func[mdio] != func)
 		dev_warn(ipctl->dev, "conflicting setting for mdio%d!\n", mdio);
 	ipctl->mdio_func[mdio] = func;
 

MY understanding here is that the static checker complains because you are comparing a variable of unsigned type to negative values, and indeed you are treating mdio_func as signed in the driver code.

mdio_func is defined as:

struct rzn1_pinctrl {
        ...
	u32 mdio_func[2];
        ...
};

Then in probe function mdio_func gets intialized as:

	ipctl->mdio_func[0] = -1;
	ipctl->mdio_func[1] = -1;

I think you could safely make mdio_func integers, or either define an INVALID value ( > 0), intialize them it that value and check against it for validity.

Thanks
j

Quoted 3 lines

--
2.17.1

#2 lore raw

HI Jacopo,

Quoted 42 lines · On 15 October 2018 08:54 jacopo mondi wrote:
Quoted 18 lines · Phil Edworthy

This fixes the check for unused mdio bus setting and the following static checker warning:
drivers/pinctrl/pinctrl-rzn1.c:198 rzn1_pinctrl_mdio_select()
warn: always true condition '(ipctl->mdio_func[mdio] >= 0) => (0-u32max
= 0)'

---
 drivers/pinctrl/pinctrl-rzn1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
(quoted diff) +0 -0

b/drivers/pinctrl/pinctrl-rzn1.c index ce05e3a00be2..f688f3a29dfd 100644

drivers/pinctrl/pinctrl-rzn1.c static void rzn1_hw_set_lock(struct rzn1_pinctrl · line 195

Quoted 1 line
drivers/pinctrl/pinctrl-rzn1.c +0 -0
@@ -195,7 +195,7 @@ static void rzn1_hw_set_lock(struct rzn1_pinctrl
 *ipctl, u8 lock, u8 value)  static void rzn1_pinctrl_mdio_select(struct

rzn1_pinctrl *ipctl, int mdio,

drivers/pinctrl/pinctrl-rzn1.c static void rzn1_hw_set_lock(struct rzn1_pinctrl *ipctl, u8 lock, u8 value)

Quoted 5 lines
drivers/pinctrl/pinctrl-rzn1.c +1 -1
 				     u32 func)
 {
-	if (ipctl->mdio_func[mdio] >= 0 && ipctl->mdio_func[mdio] != func)
+	if (ipctl->mdio_func[mdio] != -1 && ipctl->mdio_func[mdio] != func)
 		dev_warn(ipctl->dev, "conflicting setting for mdio%d!\n",

mdio);

drivers/pinctrl/pinctrl-rzn1.c static void rzn1_hw_set_lock(struct rzn1_pinctrl *ipctl, u8 lock, u8 value) · line 201

Quoted 2 lines
drivers/pinctrl/pinctrl-rzn1.c +0 -0
 	ipctl->mdio_func[mdio] = func;
 

MY understanding here is that the static checker complains because you are comparing a variable of unsigned type to negative values, and indeed you are treating mdio_func as signed in the driver code.

mdio_func is defined as:

struct rzn1_pinctrl {
        ...
	u32 mdio_func[2];
        ...
};
Quoted 8 lines

Then in probe function mdio_func gets intialized as:

	ipctl->mdio_func[0] = -1;
	ipctl->mdio_func[1] = -1;

I think you could safely make mdio_func integers, or either define an INVALID value ( > 0), intialize them it that value and check against it for validity.

You are right, I shouldn't rely on the implicit typecast from -1 to uint. I'll send an updated patch to fix this.

Thanks
Phil