LKML Archive mirror
 help / color / mirror / Atom feed
* [PATCH] pinctrl: fix error path in pinconf_map_to_setting()
@ 2012-03-12 20:41 Linus Walleij
  2012-03-12 21:04 ` Stephen Warren
  0 siblings, 1 reply; 2+ messages in thread
From: Linus Walleij @ 2012-03-12 20:41 UTC (permalink / raw
  To: linux-kernel, linux-arm-kernel
  Cc: Stephen Warren, Shawn Guo, Thomas Abraham, Dong Aisheng,
	Rajendra Nayak, Haojian Zhuang, Linus Walleij

From: Linus Walleij <linus.walleij@linaro.org>

The code was using the union member
setting->data.configs.group_or_pin to store a potential
error code, but since that member is unsigned the
< 0 comparison was not true, letting errors pass thru,
ending up as mapped to pin "-22". Fix this up and print
the error.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/pinctrl/pinconf.c |   27 +++++++++++++++++----------
 1 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/drivers/pinctrl/pinconf.c b/drivers/pinctrl/pinconf.c
index 247b9f2..f9c9cd1 100644
--- a/drivers/pinctrl/pinconf.c
+++ b/drivers/pinctrl/pinconf.c
@@ -282,21 +282,28 @@ int pinconf_map_to_setting(struct pinctrl_map const *map,
 			  struct pinctrl_setting *setting)
 {
 	struct pinctrl_dev *pctldev = setting->pctldev;
+	int ret;
 
 	switch (setting->type) {
 	case PIN_MAP_TYPE_CONFIGS_PIN:
-		setting->data.configs.group_or_pin =
-			pin_get_from_name(pctldev,
-					  map->data.configs.group_or_pin);
-		if (setting->data.configs.group_or_pin < 0)
-			return setting->data.configs.group_or_pin;
+		ret = pin_get_from_name(pctldev,
+					map->data.configs.group_or_pin);
+		if (ret < 0) {
+			dev_err(pctldev->dev, "could not map pin config for \"%s\"",
+				map->data.configs.group_or_pin);
+			return ret;
+		}
+		setting->data.configs.group_or_pin = ret;
 		break;
 	case PIN_MAP_TYPE_CONFIGS_GROUP:
-		setting->data.configs.group_or_pin =
-			pinctrl_get_group_selector(pctldev,
-					map->data.configs.group_or_pin);
-		if (setting->data.configs.group_or_pin < 0)
-			return setting->data.configs.group_or_pin;
+		ret = pinctrl_get_group_selector(pctldev,
+					 map->data.configs.group_or_pin);
+		if (ret < 0) {
+			dev_err(pctldev->dev, "could not map group config for \"%s\"",
+				map->data.configs.group_or_pin);
+			return ret;
+		}
+		setting->data.configs.group_or_pin = ret;
 		break;
 	default:
 		return -EINVAL;
-- 
1.7.8


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] pinctrl: fix error path in pinconf_map_to_setting()
  2012-03-12 20:41 [PATCH] pinctrl: fix error path in pinconf_map_to_setting() Linus Walleij
@ 2012-03-12 21:04 ` Stephen Warren
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Warren @ 2012-03-12 21:04 UTC (permalink / raw
  To: Linus Walleij
  Cc: linux-kernel, linux-arm-kernel, Shawn Guo, Thomas Abraham,
	Dong Aisheng, Rajendra Nayak, Haojian Zhuang, Linus Walleij

On 03/12/2012 02:41 PM, Linus Walleij wrote:
> From: Linus Walleij <linus.walleij@linaro.org>
> 
> The code was using the union member
> setting->data.configs.group_or_pin to store a potential
> error code, but since that member is unsigned the
> < 0 comparison was not true, letting errors pass thru,

"thru" is a pet peeve of mine; it'd be great to spell this correctly as
"through".

> ending up as mapped to pin "-22". Fix this up and print
> the error.

Oops. Sorry about that.

> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
...
> -		setting->data.configs.group_or_pin =
> -			pin_get_from_name(pctldev,
> -					  map->data.configs.group_or_pin);
> -		if (setting->data.configs.group_or_pin < 0)
> -			return setting->data.configs.group_or_pin;
> +		ret = pin_get_from_name(pctldev,
> +					map->data.configs.group_or_pin);
> +		if (ret < 0) {

"ret" here is named "pin" other places pin_get_from_name() is called,
and that naming seems to make a bit more sense here too.

Otherwise,
Acked-by: Stephen Warren <swarren@wwwdotorg.org>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-03-12 21:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-12 20:41 [PATCH] pinctrl: fix error path in pinconf_map_to_setting() Linus Walleij
2012-03-12 21:04 ` Stephen Warren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).