public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pinctrl: pinmux: Release all taken pins in pinmux_enable_setting error paths
@ 2012-11-10 13:53 Axel Lin
  2012-11-11 19:11 ` Linus Walleij
  0 siblings, 1 reply; 2+ messages in thread
From: Axel Lin @ 2012-11-10 13:53 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-kernel

Currently pinmux_enable_setting does not release all taken pins if
ops->enable() returns error. This patch ensures all taken pins are
released in any error paths.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/pinctrl/pinmux.c |   28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c
index 0ef01ee..1a00658 100644
--- a/drivers/pinctrl/pinmux.c
+++ b/drivers/pinctrl/pinmux.c
@@ -409,11 +409,7 @@ int pinmux_enable_setting(struct pinctrl_setting const *setting)
 			dev_err(pctldev->dev,
 				"could not request pin %d on device %s\n",
 				pins[i], pinctrl_dev_get_name(pctldev));
-			/* On error release all taken pins */
-			i--; /* this pin just failed */
-			for (; i >= 0; i--)
-				pin_free(pctldev, pins[i], NULL);
-			return -ENODEV;
+			goto err_pin_request;
 		}
 	}
 
@@ -429,8 +425,26 @@ int pinmux_enable_setting(struct pinctrl_setting const *setting)
 		desc->mux_setting = &(setting->data.mux);
 	}
 
-	return ops->enable(pctldev, setting->data.mux.func,
-			   setting->data.mux.group);
+	ret = ops->enable(pctldev, setting->data.mux.func,
+			  setting->data.mux.group);
+
+	if (ret)
+		goto err_enable;
+
+	return 0;
+
+err_enable:
+	for (i = 0; i < num_pins; i++) {
+		desc = pin_desc_get(pctldev, pins[i]);
+		if (desc)
+			desc->mux_setting = NULL;
+	}
+err_pin_request:
+	/* On error release all taken pins */
+	while (--i >= 0)
+		pin_free(pctldev, pins[i], NULL);
+
+	return ret;
 }
 
 void pinmux_disable_setting(struct pinctrl_setting const *setting)
-- 
1.7.9.5




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

* Re: [PATCH] pinctrl: pinmux: Release all taken pins in pinmux_enable_setting error paths
  2012-11-10 13:53 [PATCH] pinctrl: pinmux: Release all taken pins in pinmux_enable_setting error paths Axel Lin
@ 2012-11-11 19:11 ` Linus Walleij
  0 siblings, 0 replies; 2+ messages in thread
From: Linus Walleij @ 2012-11-11 19:11 UTC (permalink / raw)
  To: Axel Lin; +Cc: linux-kernel

On Sat, Nov 10, 2012 at 2:53 PM, Axel Lin <axel.lin@ingics.com> wrote:

> Currently pinmux_enable_setting does not release all taken pins if
> ops->enable() returns error. This patch ensures all taken pins are
> released in any error paths.
>
> Signed-off-by: Axel Lin <axel.lin@ingics.com>

Thanks a *lot* that's a pretty important fix Axel! :-)

Patch applied.

Yours,
Linus Walleij

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

end of thread, other threads:[~2012-11-11 19:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-10 13:53 [PATCH] pinctrl: pinmux: Release all taken pins in pinmux_enable_setting error paths Axel Lin
2012-11-11 19:11 ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox