2013-08-12 06:07:43

by Sonic Zhang

[permalink] [raw]
Subject: [PATCH v2] pinctrl: pinmux: Don't free pins requested by other devices in pinmux_disable_setting.

From: Sonic Zhang <[email protected]>

One peripheral may share part of its pins with the 2nd
peripheral and the other pins with the 3rd. If it requests all pins
when part of them has already be requested and owned by the 2nd
peripheral, this request fails and pinmux_disable_setting() is called.
The pinmux_disable_setting() frees all pins of the first peripheral
without checking if the pin is owned by itself or the 2nd, which
results in the malfunction of the 2nd peripheral driver.

Signed-off-by: Sonic Zhang <[email protected]>
---
drivers/pinctrl/core.h | 1 +
drivers/pinctrl/pinmux.c | 18 ++++++++++++------
2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/drivers/pinctrl/core.h b/drivers/pinctrl/core.h
index 75476b3..a24e889 100644
--- a/drivers/pinctrl/core.h
+++ b/drivers/pinctrl/core.h
@@ -154,6 +154,7 @@ struct pin_desc {
const char *mux_owner;
const struct pinctrl_setting_mux *mux_setting;
const char *gpio_owner;
+ const struct pinctrl_setting *owning_setting
#endif
};

diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c
index 88cc509..c32a77b 100644
--- a/drivers/pinctrl/pinmux.c
+++ b/drivers/pinctrl/pinmux.c
@@ -428,6 +428,7 @@ int pinmux_enable_setting(struct pinctrl_setting const *setting)
continue;
}
desc->mux_setting = &(setting->data.mux);
+ desc->owning_setting = setting;
}

ret = ops->enable(pctldev, setting->data.mux.func,
@@ -441,8 +442,10 @@ int pinmux_enable_setting(struct pinctrl_setting const *setting)
err_enable:
for (i = 0; i < num_pins; i++) {
desc = pin_desc_get(pctldev, pins[i]);
- if (desc)
+ if (desc) {
desc->mux_setting = NULL;
+ desc->owning_setting = NULL;
+ }
}
err_pin_request:
/* On error release all taken pins */
@@ -480,15 +483,18 @@ void pinmux_disable_setting(struct pinctrl_setting const *setting)
dev_warn(pctldev->dev,
"could not get pin desc for pin %d\n",
pins[i]);
+ /* And release the pin */
+ pin_free(pctldev, pins[i], NULL);
continue;
}
- desc->mux_setting = NULL;
+ if (desc->owning_setting == setting) {
+ desc->mux_setting = NULL;
+ desc->owning_setting = NULL;
+ /* And release the pin */
+ pin_free(pctldev, pins[i], NULL);
+ }
}

- /* And release the pins */
- for (i = 0; i < num_pins; i++)
- pin_free(pctldev, pins[i], NULL);
-
if (ops->disable)
ops->disable(pctldev, setting->data.mux.func, setting->data.mux.group);
}
--
1.8.2.3


2013-08-12 17:38:54

by Stephen Warren

[permalink] [raw]
Subject: Re: [PATCH v2] pinctrl: pinmux: Don't free pins requested by other devices in pinmux_disable_setting.

On 08/12/2013 12:10 AM, Sonic Zhang wrote:
> From: Sonic Zhang <[email protected]>
>
> One peripheral may share part of its pins with the 2nd
> peripheral and the other pins with the 3rd. If it requests all pins
> when part of them has already be requested and owned by the 2nd
> peripheral, this request fails and pinmux_disable_setting() is called.
> The pinmux_disable_setting() frees all pins of the first peripheral
> without checking if the pin is owned by itself or the 2nd, which
> results in the malfunction of the 2nd peripheral driver.

This patch looks conceptually fine at a quick glance, but ...

> diff --git a/drivers/pinctrl/core.h b/drivers/pinctrl/core.h

> @@ -154,6 +154,7 @@ struct pin_desc {
> const char *mux_owner;
> const struct pinctrl_setting_mux *mux_setting;
> const char *gpio_owner;
> + const struct pinctrl_setting *owning_setting

... I think you can use the existing "mux_setting" field instead of
adding a new "owning_setting" field.