pinctrl: devicetree: Fix pctldev pointer overwrite

Message ID 1528390293-8022-1-git-send-email-festevam@gmail.com
State New
Headers show
Series
  • pinctrl: devicetree: Fix pctldev pointer overwrite
Related show

Commit Message

Fabio Estevam June 7, 2018, 4:51 p.m.
From: Fabio Estevam <fabio.estevam@nxp.com>

Commit b89405b6102f ("pinctrl: devicetree: Fix dt_to_map_one_config
handling of hogs") causes the pinctrl hog pins to not get initialized
on i.MX platforms leaving them with the IOMUX settings untouched.

This causes several regressions on i.MX such as:

- OV5640 camera driver can not be probed anymore on imx6qdl-sabresd
because the camera clock pin is in a pinctrl_hog group and since
its pinctrl initialization is skipped, the camera clock is kept
in GPIO functionality instead of CLK_CKO function.

- Audio stopped working on imx6qdl-wandboard and imx53-qsb for
the same reason.

Richard Fitzgerald explains the problem:

"I see the bug. If the hog node isn't a 1st level child of the pinctrl
parent node it will go around the for(;;) loop again but on the first
pass I overwrite pctldev with the result of
get_pinctrl_dev_from_of_node() so it doesn't point to the pinctrl driver
any more."

Fix the issue by stashing the original pctldev so it doesn't
get overwritten.

Fixes:  b89405b6102f ("pinctrl: devicetree: Fix dt_to_map_one_config handling of hogs")
Cc: <stable@vger.kernel.org>
Reported-by: Mika Penttilä <mika.penttila@nextfour.com>
Reported-by: Steve Longerbeam <slongerbeam@gmail.com>
Suggested-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
---
 drivers/pinctrl/devicetree.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Dong Aisheng June 8, 2018, 5:38 a.m. | #1
PiAtLS0tLU9yaWdpbmFsIE1lc3NhZ2UtLS0tLQ0KPiBGcm9tOiBGYWJpbyBFc3RldmFtIFttYWls
dG86ZmVzdGV2YW1AZ21haWwuY29tXQ0KPiBTZW50OiBGcmlkYXksIEp1bmUgOCwgMjAxOCAxMjo1
MiBBTQ0KPiBUbzogbGludXMud2FsbGVpakBsaW5hcm8ub3JnDQo+I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RybF9kZXYgKnBjdGxkZXYsDQo+ICsJCQkJc3RydWN0IHBpbmN0cmxfZGV2ICpob2dfcGN0bGRl
diwNCj4gIAkJCQljb25zdCBjaGFyICpzdGF0ZW5hbWUsDQo+ICAJCQkJc3RydWN0IGRldmljZV9u
b2RlICpucF9jb25maWcpDQo+ICB7DQo+ICsJc3RydWN0IHBpbmN0cmxfZGV2ICpwY3RsZGV2ID0g
TlVMTDsNCj4gIAlzdHJ1Y3QgZGV2aWNlX25vZGUgKm5wX3BjdGxkZXY7DQo+ICAJY29uc3Qgc3Ry
dWN0IHBpbmN0cmxfb3BzICpvcHM7DQo+ICAJaW50IHJldDsNCj4gQEAgLTEyMyw4ICsxMjQsMTAg
QEAgc3RhdGljIGludCBkdF90b19tYXBfb25lX2NvbmZpZyhzdHJ1Y3QgcGluY3RybCAqcCwNCj4g
IAkJCXJldHVybiAtRVBST0JFX0RFRkVSOw0KPiAgCQl9DQo+ICAJCS8qIElmIHdlJ3JlIGNyZWF0
aW5nIGEgaG9nIHdlIGNhbiB1c2UgdGhlIHBhc3NlZCBwY3RsZGV2ICovDQo+IC0JCWlmIChwY3Rs
ZGV2ICYmIChucF9wY3RsZGV2ID09IHAtPmRldi0+b2Zfbm9kZSkpDQo+ICsJCWlmIChob2dfcGN0
bGRldiAmJiAobnBfcGN0bGRldiA9PSBwLT5kZXYtPm9mX25vZGUpKSB7DQo+ICsJCQlwY3RsZGV2
ID0gaG9nX3BjdGxkZXY7DQo+ICAJCQlicmVhazsNCj4gKwkJfQ0KPiAgCQlwY3RsZGV2ID0gZ2V0
X3BpbmN0cmxfZGV2X2Zyb21fb2Zfbm9kZShucF9wY3RsZGV2KTsNCj4gIAkJaWYgKHBjdGxkZXYp
DQo+ICAJCQlicmVhazsNCj4gLS0NCj4gMi43LjQNCg0K
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Richard Fitzgerald June 8, 2018, 9:06 a.m. | #2
On 07/06/18 17:51, Fabio Estevam wrote:
> From: Fabio Estevam <fabio.estevam@nxp.com>
> 
> Commit b89405b6102f ("pinctrl: devicetree: Fix dt_to_map_one_config
> handling of hogs") causes the pinctrl hog pins to not get initialized
> on i.MX platforms leaving them with the IOMUX settings untouched.
> 
> This causes several regressions on i.MX such as:
> 
> - OV5640 camera driver can not be probed anymore on imx6qdl-sabresd
> because the camera clock pin is in a pinctrl_hog group and since
> its pinctrl initialization is skipped, the camera clock is kept
> in GPIO functionality instead of CLK_CKO function.
> 
> - Audio stopped working on imx6qdl-wandboard and imx53-qsb for
> the same reason.
> 
> Richard Fitzgerald explains the problem:
> 
> "I see the bug. If the hog node isn't a 1st level child of the pinctrl
> parent node it will go around the for(;;) loop again but on the first
> pass I overwrite pctldev with the result of
> get_pinctrl_dev_from_of_node() so it doesn't point to the pinctrl driver
> any more."
> 
> Fix the issue by stashing the original pctldev so it doesn't
> get overwritten.
> 
> Fixes:  b89405b6102f ("pinctrl: devicetree: Fix dt_to_map_one_config handling of hogs")
> Cc: <stable@vger.kernel.org>
> Reported-by: Mika Penttilä <mika.penttila@nextfour.com>
> Reported-by: Steve Longerbeam <slongerbeam@gmail.com>
> Suggested-by: Richard Fitzgerald <rf@opensource.cirrus.com>
> Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
> ---
>   drivers/pinctrl/devicetree.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pinctrl/devicetree.c b/drivers/pinctrl/devicetree.c
> index b601039..c4aa411 100644
> --- a/drivers/pinctrl/devicetree.c
> +++ b/drivers/pinctrl/devicetree.c
> @@ -101,10 +101,11 @@ struct pinctrl_dev *of_pinctrl_get(struct device_node *np)
>   }
>   
>   static int dt_to_map_one_config(struct pinctrl *p,
> -				struct pinctrl_dev *pctldev,
> +				struct pinctrl_dev *hog_pctldev,
>   				const char *statename,
>   				struct device_node *np_config)
>   {
> +	struct pinctrl_dev *pctldev = NULL;
>   	struct device_node *np_pctldev;
>   	const struct pinctrl_ops *ops;
>   	int ret;
> @@ -123,8 +124,10 @@ static int dt_to_map_one_config(struct pinctrl *p,
>   			return -EPROBE_DEFER;
>   		}
>   		/* If we're creating a hog we can use the passed pctldev */
> -		if (pctldev && (np_pctldev == p->dev->of_node))
> +		if (hog_pctldev && (np_pctldev == p->dev->of_node)) {
> +			pctldev = hog_pctldev;
>   			break;
> +		}
>   		pctldev = get_pinctrl_dev_from_of_node(np_pctldev);
>   		if (pctldev)
>   			break;
> 

Thanks for creating this patch. Looks ok to me.

Reviewed-by: Richard Fitzgerald <rf@opensource.cirrus.com>
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Linus Walleij June 13, 2018, 11 a.m. | #3
On Thu, Jun 7, 2018 at 6:51 PM, Fabio Estevam <festevam@gmail.com> wrote:

> From: Fabio Estevam <fabio.estevam@nxp.com>
>
> Commit b89405b6102f ("pinctrl: devicetree: Fix dt_to_map_one_config
> handling of hogs") causes the pinctrl hog pins to not get initialized
> on i.MX platforms leaving them with the IOMUX settings untouched.
>
> This causes several regressions on i.MX such as:
>
> - OV5640 camera driver can not be probed anymore on imx6qdl-sabresd
> because the camera clock pin is in a pinctrl_hog group and since
> its pinctrl initialization is skipped, the camera clock is kept
> in GPIO functionality instead of CLK_CKO function.
>
> - Audio stopped working on imx6qdl-wandboard and imx53-qsb for
> the same reason.
>
> Richard Fitzgerald explains the problem:
>
> "I see the bug. If the hog node isn't a 1st level child of the pinctrl
> parent node it will go around the for(;;) loop again but on the first
> pass I overwrite pctldev with the result of
> get_pinctrl_dev_from_of_node() so it doesn't point to the pinctrl driver
> any more."
>
> Fix the issue by stashing the original pctldev so it doesn't
> get overwritten.
>
> Fixes:  b89405b6102f ("pinctrl: devicetree: Fix dt_to_map_one_config handling of hogs")
> Cc: <stable@vger.kernel.org>
> Reported-by: Mika Penttilä <mika.penttila@nextfour.com>
> Reported-by: Steve Longerbeam <slongerbeam@gmail.com>
> Suggested-by: Richard Fitzgerald <rf@opensource.cirrus.com>
> Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>

Patch applied for fixes with the ACKs!

Thanks for digging into this and fixing it up!

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/drivers/pinctrl/devicetree.c b/drivers/pinctrl/devicetree.c
index b601039..c4aa411 100644
--- a/drivers/pinctrl/devicetree.c
+++ b/drivers/pinctrl/devicetree.c
@@ -101,10 +101,11 @@  struct pinctrl_dev *of_pinctrl_get(struct device_node *np)
 }
 
 static int dt_to_map_one_config(struct pinctrl *p,
-				struct pinctrl_dev *pctldev,
+				struct pinctrl_dev *hog_pctldev,
 				const char *statename,
 				struct device_node *np_config)
 {
+	struct pinctrl_dev *pctldev = NULL;
 	struct device_node *np_pctldev;
 	const struct pinctrl_ops *ops;
 	int ret;
@@ -123,8 +124,10 @@  static int dt_to_map_one_config(struct pinctrl *p,
 			return -EPROBE_DEFER;
 		}
 		/* If we're creating a hog we can use the passed pctldev */
-		if (pctldev && (np_pctldev == p->dev->of_node))
+		if (hog_pctldev && (np_pctldev == p->dev->of_node)) {
+			pctldev = hog_pctldev;
 			break;
+		}
 		pctldev = get_pinctrl_dev_from_of_node(np_pctldev);
 		if (pctldev)
 			break;