Skip to contentSkip to conversation

pinctrl: pinmux: Don't free pins requested by other devices in pinmux_disable_setting.

PATCH In review Sonic Zhang 3 participants 5 messages Aug 14, 2013 Pin control

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 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.

---
 drivers/pinctrl/pinmux.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/pinctrl/pinmux.c +5 -5
index 88cc509..5f51588 100644
@@ -482,13 +482,13 @@ void pinmux_disable_setting(struct pinctrl_setting const *setting)
 				 pins[i]);
 			continue;
 		}
-		desc->mux_setting = NULL;
+		if (desc->mux_setting == &(setting->data.mux)) {
+			desc->mux_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);
 }
Signature · 1 line
1.8.2.3
#1 lore raw
Quoted 11 lines · Sonic Zhang

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.

Hm it makes some sense so patch applied.

That said I think we currently have drivers where a pin group mapped to a certain function in a certain setting *usually* don't overlap with pins in another group used with another function, and having it so seems racy, i.e. it will be some first-come-first-serve effect.

I will add a warning print.

Yours,
Linus Walleij

#2 lore raw
Quoted 16 lines · Linus Walleij
Quoted 11 lines · Sonic Zhang

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.

Hm it makes some sense so patch applied.

Quoted 7 lines

That said I think we currently have drivers where a pin group mapped to a certain function in a certain setting *usually* don't overlap with pins in another group used with another function, and having it so seems racy, i.e. it will be some first-come-first-serve effect.

I will add a warning print.

Surely there's a warning print already when the enable_setting() fails, so we don't need to do any more warning prints when the free_setting() cleans up after that?

#3 lore raw
Quoted 23 lines · Stephen Warren
Quoted 22 lines · Linus Walleij
Quoted 11 lines · Sonic Zhang

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.

Hm it makes some sense so patch applied.

That said I think we currently have drivers where a pin group mapped to a certain function in a certain setting *usually* don't overlap with pins in another group used with another function, and having it so seems racy, i.e. it will be some first-come-first-serve effect.

Quoted 5 lines
Quoted 1 line

I will add a warning print.

Surely there's a warning print already when the enable_setting() fails, so we don't need to do any more warning prints when the free_setting() cleans up after that?

Now I'm confused ... I added debug prints to pinmux_disable_setting() which is where the patch hits? free_setting() is just an empty function body still.

Yours,
Linus Walleij

#4 lore raw
Quoted 26 lines · Linus Walleij
Quoted 25 lines · Stephen Warren
Quoted 23 lines · Linus Walleij
Quoted 11 lines · Sonic Zhang

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.

Hm it makes some sense so patch applied.

That said I think we currently have drivers where a pin group mapped to a certain function in a certain setting *usually* don't overlap with pins in another group used with another function, and having it so seems racy, i.e. it will be some first-come-first-serve effect.

I will add a warning print.

Quoted 7 lines
Quoted 3 lines

Surely there's a warning print already when the enable_setting() fails, so we don't need to do any more warning prints when the free_setting() cleans up after that?

Now I'm confused ... I added debug prints to pinmux_disable_setting() which is where the patch hits? free_setting() is just an empty function body still.

I wrote the wrong function name; s/free_setting/disable_setting/ in what I wrote.