Re: [PATCH] pinctrl: imx: fix unsigned check if nfuncs with less than or equal zero

From: Linus Walleij
Date: Wed Mar 21 2018 - 04:49:43 EST


On Mon, Feb 26, 2018 at 2:14 PM, A.s. Dong <aisheng.dong@xxxxxxx> wrote:

>> - u32 nfuncs = 0;
>> - u32 i = 0;
>> + int nfuncs = 0;
>> + int i = 0;
>> bool flat_funcs;
>>
>
> I saw 'i', later used, is converted to u32 unconditionally. (GCC did not complain)
> e.g.
> radix_tree_insert
> imx_pinctrl_parse_functions
>
> And of_get_child_count seems can't return a minor value.
>
> So does something like below look better?
>
> diff --git a/drivers/pinctrl/freescale/pinctrl-imx.c b/drivers/pinctrl/freescale/pinctrl-imx.c
> index c976ffe..4259209 100644
> --- a/drivers/pinctrl/freescale/pinctrl-imx.c
> +++ b/drivers/pinctrl/freescale/pinctrl-imx.c
> @@ -612,7 +612,7 @@ static int imx_pinctrl_probe_dt(struct platform_device *pdev,
> nfuncs = 1;
> } else {
> nfuncs = of_get_child_count(np);
> - if (nfuncs <= 0) {
> + if (nfuncs == 0) {

This makes more sense to me.

You can have zero functions but not negative number of functions.

Aisheng, can you send a patch like this? (Or is it already somewhere in
my inbox?)

Yours,
Linus Walleij