All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tony Lindgren <tony@atomide.com>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Andy Shevchenko <andy.shevchenko@gmail.com>,
	Christ van Willegen <cvwillegen@gmail.com>,
	Haojian Zhuang <haojian.zhuang@linaro.org>,
	"H . Nikolaus Schaller" <hns@goldelico.com>,
	Paul Cercueil <paul@crapouillou.net>,
	Sean Wang <sean.wang@mediatek.com>,
	Jacopo Mondi <jacopo+renesas@jmondi.org>
Subject: [PATCH 4/5] pinctrl: rza1: Fix selector use for groups and functions
Date: Thu,  5 Jul 2018 02:10:17 -0700	[thread overview]
Message-ID: <20180705091018.60524-5-tony@atomide.com> (raw)
In-Reply-To: <20180705091018.60524-1-tony@atomide.com>

We must use a mutex around the generic_add functions and save the
function and group selector in case we need to remove them. Otherwise
the selector use will be racy for deferred probe at least.

Fixes: 5a49b644b307 ("pinctrl: Renesas RZ/A1 pin and gpio controller")
Reported-by: H. Nikolaus Schaller <hns@goldelico.com>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Christ van Willegen <cvwillegen@gmail.com>
Cc: Haojian Zhuang <haojian.zhuang@linaro.org>
Cc: H. Nikolaus Schaller <hns@goldelico.com>
Cc: Paul Cercueil <paul@crapouillou.net>
Cc: Sean Wang <sean.wang@mediatek.com>
Acked-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Tony Lindgren <tony@atomide.com>
---
 drivers/pinctrl/pinctrl-rza1.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-rza1.c b/drivers/pinctrl/pinctrl-rza1.c
--- a/drivers/pinctrl/pinctrl-rza1.c
+++ b/drivers/pinctrl/pinctrl-rza1.c
@@ -1006,6 +1006,7 @@ static int rza1_dt_node_to_map(struct pinctrl_dev *pctldev,
 	const char *grpname;
 	const char **fngrps;
 	int ret, npins;
+	int gsel, fsel;
 
 	npins = rza1_dt_node_pin_count(np);
 	if (npins < 0) {
@@ -1055,18 +1056,19 @@ static int rza1_dt_node_to_map(struct pinctrl_dev *pctldev,
 	fngrps[0] = grpname;
 
 	mutex_lock(&rza1_pctl->mutex);
-	ret = pinctrl_generic_add_group(pctldev, grpname, grpins, npins,
-					NULL);
-	if (ret) {
+	gsel = pinctrl_generic_add_group(pctldev, grpname, grpins, npins,
+					 NULL);
+	if (gsel < 0) {
 		mutex_unlock(&rza1_pctl->mutex);
-		return ret;
+		return gsel;
 	}
 
-	ret = pinmux_generic_add_function(pctldev, grpname, fngrps, 1,
-					  mux_confs);
-	if (ret)
+	fsel = pinmux_generic_add_function(pctldev, grpname, fngrps, 1,
+					   mux_confs);
+	if (fsel < 0) {
+		ret = fsel;
 		goto remove_group;
-	mutex_unlock(&rza1_pctl->mutex);
+	}
 
 	dev_info(rza1_pctl->dev, "Parsed function and group %s with %d pins\n",
 				 grpname, npins);
@@ -1083,15 +1085,15 @@ static int rza1_dt_node_to_map(struct pinctrl_dev *pctldev,
 	(*map)->data.mux.group = np->name;
 	(*map)->data.mux.function = np->name;
 	*num_maps = 1;
+	mutex_unlock(&rza1_pctl->mutex);
 
 	return 0;
 
 remove_function:
-	mutex_lock(&rza1_pctl->mutex);
-	pinmux_generic_remove_last_function(pctldev);
+	pinmux_generic_remove_function(pctldev, fsel);
 
 remove_group:
-	pinctrl_generic_remove_last_group(pctldev);
+	pinctrl_generic_remove_group(pctldev, gsel);
 	mutex_unlock(&rza1_pctl->mutex);
 
 	dev_info(rza1_pctl->dev, "Unable to parse function and group %s\n",
-- 
2.17.1

  parent reply	other threads:[~2018-07-05  9:10 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-05  9:10 [PATCHv3 0/5] pinctrl fixes for generic functions and groups Tony Lindgren
2018-07-05  9:10 ` [PATCH 1/5] pinctrl: core: Return selector to the pinctrl driver Tony Lindgren
2018-07-05  9:10 ` [PATCH 2/5] pinctrl: pinmux: " Tony Lindgren
2018-07-05  9:10 ` [PATCH 3/5] pinctrl: single: Fix group and function selector use Tony Lindgren
2018-07-05  9:10 ` Tony Lindgren [this message]
2018-07-05  9:10 ` [PATCH 5/5] pinctrl: core: Remove broken remove_last group and pinmux functions Tony Lindgren
2018-07-05 13:28 ` [PATCHv3 0/5] pinctrl fixes for generic functions and groups H. Nikolaus Schaller
2018-07-05 13:55 ` Andy Shevchenko
2018-07-09 12:59 ` Linus Walleij
2018-07-09 13:11   ` Tony Lindgren
  -- strict thread matches above, loose matches on Subject: below --
2018-06-19  9:31 [PATCHv2 " Tony Lindgren
2018-06-19  9:31 ` [PATCH 4/5] pinctrl: rza1: Fix selector use for groups and functions Tony Lindgren
2018-06-15 11:11 [PATCH 0/5] pinctrl fixes for generic functions and groups Tony Lindgren
2018-06-15 11:11 ` [PATCH 4/5] pinctrl: rza1: Fix selector use for groups and functions Tony Lindgren
2018-06-19  4:16   ` jacopo mondi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180705091018.60524-5-tony@atomide.com \
    --to=tony@atomide.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=cvwillegen@gmail.com \
    --cc=haojian.zhuang@linaro.org \
    --cc=hns@goldelico.com \
    --cc=jacopo+renesas@jmondi.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paul@crapouillou.net \
    --cc=sean.wang@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.