pinctrl: check ops->pin_config_set in pinconf_set_config()

Message ID 1501815572-2792-1-git-send-email-yamada.masahiro@socionext.com
State Accepted
Commit 17a512486bab646109770f6577396810e83acfbb
Headers show

Commit Message

Masahiro Yamada Aug. 4, 2017, 2:59 a.m.
pinconf_set_config() is called by pinctrl_gpio_set_config().
If a GPIO driver is backed by a pinctrl driver and it does not
support .pin_config_set() hook, it causes NULL pointer dereference.

Fixes: 15381bc7c7f5 ("pinctrl: Allow configuration of pins from gpiolib based drivers")
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

---

 drivers/pinctrl/pinconf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.7.4

--
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

Comments

Mika Westerberg Aug. 4, 2017, 10:12 a.m. | #1
On Fri, Aug 04, 2017 at 11:59:32AM +0900, Masahiro Yamada wrote:
> pinconf_set_config() is called by pinctrl_gpio_set_config().

> If a GPIO driver is backed by a pinctrl driver and it does not

> support .pin_config_set() hook, it causes NULL pointer dereference.

> 

> Fixes: 15381bc7c7f5 ("pinctrl: Allow configuration of pins from gpiolib based drivers")

> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


Acked-by: Mika Westerberg <mika.westerberg@linux.intel.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

Patch

diff --git a/drivers/pinctrl/pinconf.c b/drivers/pinctrl/pinconf.c
index 92f363793f35..d3fe14394b73 100644
--- a/drivers/pinctrl/pinconf.c
+++ b/drivers/pinctrl/pinconf.c
@@ -205,7 +205,7 @@  int pinconf_set_config(struct pinctrl_dev *pctldev, unsigned pin,
 	const struct pinconf_ops *ops;
 
 	ops = pctldev->desc->confops;
-	if (!ops)
+	if (!ops || !ops->pin_config_set)
 		return -ENOTSUPP;
 
 	return ops->pin_config_set(pctldev, pin, configs, nconfigs);