mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Richard Genoud <richard.genoud@gmail.com>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Axel Lin <axel.lin@ingics.com>,
	Stephen Warren <swarren@nvidia.com>,
	linux-kernel@vger.kernel.org,
	Richard Genoud <richard.genoud@gmail.com>
Subject: [PATCH] BUG: [RFC] pinctrl: pins are freed 2 times in pinctrl_bind_pins
Date: Wed, 20 Mar 2013 12:31:53 +0100	[thread overview]
Message-ID: <1363779113-8776-3-git-send-email-richard.genoud@gmail.com> (raw)
In-Reply-To: <1363779113-8776-1-git-send-email-richard.genoud@gmail.com>

If the function pinctrl_select_state() fails because one pin is already
taken elsewhere, pinmux_enable_setting makes all the necessary pin_free
calls (and not more than necessary).
The problem here is that devm_pinctrl_put() will be called on the pin
group, and each pin in this group has already been freed.

Example:
If a i2c function has already sucessfully taken pins 5 and 6.
And now, pinctrl_bind_pins() is called for function PHY (pins 3 4 5 6 7).
pinmux_enable_setting() will fail AND call pin_free on necessary pins.
But if devm_pinctrl_put() is called, it will call again pin_free on pins
3 4 5 6 7.
So, the pins 5 and 6 will be released (and pins 3 4 7 double freed).
Which means that even if the i2c function has claim the pins, they will
be available for other functions.

This patch simply doesn't call devm_pinctrl_put when
pinctrl_select_state fails, but I'm not sure it's the right thing to do.

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
---
 drivers/base/pinctrl.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/base/pinctrl.c b/drivers/base/pinctrl.c
index 67a274e..537406d 100644
--- a/drivers/base/pinctrl.c
+++ b/drivers/base/pinctrl.c
@@ -45,7 +45,7 @@ int pinctrl_bind_pins(struct device *dev)
 	ret = pinctrl_select_state(dev->pins->p, dev->pins->default_state);
 	if (ret) {
 		dev_dbg(dev, "failed to activate default pinctrl state\n");
-		goto cleanup_get;
+		goto cleanup_alloc; /* pins already un-muxed */
 	}
 
 	return 0;
-- 
1.7.2.5


  parent reply	other threads:[~2013-03-20 11:32 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-20 11:31 [PATCH] BUG: pinmux: release only taken pins on error Richard Genoud
2013-03-20 11:31 ` [PATCH] BUG: pinmux: forbid mux_usecount to be set at UINT_MAX Richard Genoud
2013-03-20 16:14   ` Stephen Warren
2013-03-20 16:59     ` Richard Genoud
2013-03-20 17:08       ` Stephen Warren
2013-03-21 11:21         ` Richard Genoud
2013-03-21 17:33           ` Stephen Warren
2013-03-21 18:28           ` Linus Walleij
2013-03-20 11:31 ` Richard Genoud [this message]
2013-03-20 16:23   ` [PATCH] BUG: [RFC] pinctrl: pins are freed 2 times in pinctrl_bind_pins Stephen Warren
2013-03-21 11:31     ` Richard Genoud
2013-03-20 13:21 ` [PATCH] BUG: pinmux: release only taken pins on error Axel Lin
2013-03-20 14:19   ` Richard Genoud

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=1363779113-8776-3-git-send-email-richard.genoud@gmail.com \
    --to=richard.genoud@gmail.com \
    --cc=axel.lin@ingics.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=swarren@nvidia.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome