Skip to contentSkip to conversation

pinctrl: fix signed vs unsigned conditionals inside pinmux_map_to_setting

PATCH In review John Crispin 4 participants 4 messages Apr 23, 2012 – Apr 24, 2012 1 message not in the archive Pin control

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 pinctrl: fix signed vs unsigned conditionals inside pinmux_map_to_setting

pinmux_map_to_setting() uses setting->data.mux.func/group to store the return code of pinmux_func_name_to_selector/pinctrl_get_group_selector(). However, struct pinctrl_setting_mux defines these elements as unsigned, resulting in all error codes getting lost. The conditionals following the assignments will always evaluate to false thus breaking the error paths.

This bug can be triggered by loading a pinmux group map from the devicetree with an invalid function/group string.

Cc Stephen Warren <[email protected]>
Cc Dong Aisheng <[email protected]>
---
 drivers/pinctrl/pinmux.c |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)
drivers/pinctrl/pinmux.c +8 -7
index c494c37..1056e68 100644
@@ -328,10 +328,10 @@ int pinmux_map_to_setting(struct pinctrl_map const *map,
 		return -EINVAL;
 	}
 
-	setting->data.mux.func =
-		pinmux_func_name_to_selector(pctldev, map->data.mux.function);
-	if (setting->data.mux.func < 0)
-		return setting->data.mux.func;
+	ret = pinmux_func_name_to_selector(pctldev, map->data.mux.function);
+	if (ret < 0)
+		return ret;
+	setting->data.mux.func = ret;
 
 	ret = pmxops->get_function_groups(pctldev, setting->data.mux.func,
 					  &groups, &num_groups);
@@ -355,9 +355,10 @@ int pinmux_map_to_setting(struct pinctrl_map const *map,
 		group = groups[0];
 	}
 
-	setting->data.mux.group = pinctrl_get_group_selector(pctldev, group);
-	if (setting->data.mux.group < 0)
-		return setting->data.mux.group;
+	ret = pinctrl_get_group_selector(pctldev, group);
+	if (ret < 0)
+		return ret;
+	setting->data.mux.group = ret;
 
 	ret = pctlops->get_group_pins(pctldev, setting->data.mux.group, &pins,
 				      &num_pins);
Signature · 1 line
1.7.9.1

A message that is not in the archive (sent off-list or not yet received): 1335200518-3640-1-git-send-email-blogic-p3rKhJxN3npAfugRpC6u6w@public.gmane.org

#2 lore raw
Quoted 6 lines · John Crispin

pinmux_map_to_setting() uses setting->data.mux.func/group to store the return code of pinmux_func_name_to_selector/pinctrl_get_group_selector(). However, struct pinctrl_setting_mux defines these elements as unsigned, resulting in all error codes getting lost. The conditionals following the assignments will always evaluate to false thus breaking the error paths.

Quoted 6 lines

This bug can be triggered by loading a pinmux group map from the devicetree with an invalid function/group string.

Cc Stephen Warren <[email protected]>
Cc Dong Aisheng <[email protected]>
Acked-by
#3 lore raw
In reply to a message not in the archive
Quoted 9 lines · John Crispin

pinmux_map_to_setting() uses setting->data.mux.func/group to store the return code of pinmux_func_name_to_selector/pinctrl_get_group_selector(). However, struct pinctrl_setting_mux defines these elements as unsigned, resulting in all error codes getting lost. The conditionals following the assignments will always evaluate to false thus breaking the error paths.

This bug can be triggered by loading a pinmux group map from the devicetree with an invalid function/group string.

Quoted 7 lines
Cc Stephen Warren <[email protected]>
Cc Dong Aisheng <[email protected]>
---
 drivers/pinctrl/pinmux.c |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)

Nice fix.

Regards
Dong Aisheng

#4 lore raw
In reply to a message not in the archive
Quoted 6 lines · John Crispin

pinmux_map_to_setting() uses setting->data.mux.func/group to store the return code of pinmux_func_name_to_selector/pinctrl_get_group_selector(). However, struct pinctrl_setting_mux defines these elements as unsigned, resulting in all error codes getting lost. The conditionals following the assignments will always evaluate to false thus breaking the error paths.

Quoted 6 lines

This bug can be triggered by loading a pinmux group map from the devicetree with an invalid function/group string.

Cc Stephen Warren <[email protected]>
Cc Dong Aisheng <[email protected]>

Applied with Stephen and Dong's ACKs, thanks!

New contributors to pinctrl, I love this :-)

Yours,
Linus Walleij