2018-11-24 08:26:33

by Phil Edworthy

[permalink] [raw]
Subject: [PATCH] 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)'

Reported-by: Dan Carpenter <[email protected]>
Signed-off-by: Phil Edworthy <[email protected]>
---
v3:
- Split fixing the return var when calling of_get_child_count() into
a separate patch.
v2:
- Don't rely on rely on the implicit typecast from -1 to uint
---
drivers/pinctrl/pinctrl-rzn1.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pinctrl/pinctrl-rzn1.c b/drivers/pinctrl/pinctrl-rzn1.c
index 57886dcff53d..a04235e3bec4 100644
--- a/drivers/pinctrl/pinctrl-rzn1.c
+++ b/drivers/pinctrl/pinctrl-rzn1.c
@@ -112,7 +112,7 @@ struct rzn1_pinctrl {
struct rzn1_pinctrl_regs __iomem *lev2;
u32 lev1_protect_phys;
u32 lev2_protect_phys;
- u32 mdio_func[2];
+ int mdio_func[2];

struct rzn1_pin_group *groups;
unsigned int ngroups;
--
2.17.1



2018-11-24 08:27:49

by Phil Edworthy

[permalink] [raw]
Subject: [PATCH] pinctrl: rzn1: Fix of_get_child_count() error check

If we assign the result of of_get_child_count() to an unsigned int,
the code will not detect any errors. Therefore assign it to an int
instead.

Signed-off-by: Phil Edworthy <[email protected]>
---
drivers/pinctrl/pinctrl-rzn1.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pinctrl/pinctrl-rzn1.c b/drivers/pinctrl/pinctrl-rzn1.c
index a04235e3bec4..cc0e5aa9128a 100644
--- a/drivers/pinctrl/pinctrl-rzn1.c
+++ b/drivers/pinctrl/pinctrl-rzn1.c
@@ -810,8 +810,8 @@ static int rzn1_pinctrl_probe_dt(struct platform_device *pdev,
struct device_node *np = pdev->dev.of_node;
struct device_node *child;
unsigned int maxgroups = 0;
- unsigned int nfuncs = 0;
unsigned int i = 0;
+ int nfuncs = 0;
int ret;

nfuncs = of_get_child_count(np);
--
2.17.1


2018-11-24 08:30:46

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH] pinctrl: rzn1: Fix check for used MDIO bus

On Fri, Nov 23, 2018 at 11:54 AM Phil Edworthy
<[email protected]> wrote:
> 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)'
>
> Reported-by: Dan Carpenter <[email protected]>
> Signed-off-by: Phil Edworthy <[email protected]>
> ---
> v3:
> - Split fixing the return var when calling of_get_child_count() into
> a separate patch.
> v2:
> - Don't rely on rely on the implicit typecast from -1 to uint

Reviewed-by: Geert Uytterhoeven <[email protected]>
i.e. will queue in sh-pfc-for-v4.21.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2018-11-24 08:30:58

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH] pinctrl: rzn1: Fix of_get_child_count() error check

On Fri, Nov 23, 2018 at 11:54 AM Phil Edworthy
<[email protected]> wrote:
> If we assign the result of of_get_child_count() to an unsigned int,
> the code will not detect any errors. Therefore assign it to an int
> instead.

Note that currently of_get_child_count() never returns a negative
error code. But it does return int, not unsigned int.

> Signed-off-by: Phil Edworthy <[email protected]>

Reviewed-by: Geert Uytterhoeven <[email protected]>
i.e. will queue in sh-pfc-for-v4.21.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds