Skip to contentSkip to conversation

pinctrl: fix Null pointer dereference

PATCH In review clingfei 3 participants 3 messages Oct 3, 2024

Subsystems (4)
lore
Share & tools
lore

clingfei

author
#0 lore raw

PATCH 1/1 pinctrl: fix Null pointer dereference

pinmux_generic_get_function may returns NULL, and its retval is dereferenced without check, which will cause a null pointer dereference.

---
 drivers/pinctrl/pinctrl-th1520.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pinctrl/pinctrl-th1520.c +2 -0
index 1bb78b212fd5..9331f4462480 100644
@@ -798,6 +798,8 @@ static int th1520_pinmux_set_mux(struct pinctrl_dev *pctldev,
 	struct th1520_pinctrl *thp = pinctrl_dev_get_drvdata(pctldev);
 	const struct function_desc *func = pinmux_generic_get_function(pctldev, fsel);
 
+	if (!func)
+		return -EINVAL;
 	return th1520_pinmux_set(thp, thp->desc.pins[gsel].number,
 				 (uintptr_t)thp->desc.pins[gsel].drv_data & TH1520_PAD_MUXDATA,
 				 (uintptr_t)func->data);
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 23 lines · clingfei

pinmux_generic_get_function may returns NULL, and its retval is dereferenced without check, which will cause a null pointer dereference.

---
 drivers/pinctrl/pinctrl-th1520.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pinctrl/pinctrl-th1520.c +2 -0
index 1bb78b212fd5..9331f4462480 100644
@@ -798,6 +798,8 @@ static int th1520_pinmux_set_mux(struct pinctrl_dev *pctldev,
 	struct th1520_pinctrl *thp = pinctrl_dev_get_drvdata(pctldev);
 	const struct function_desc *func = pinmux_generic_get_function(pctldev, fsel);
 
+	if (!func)
+		return -EINVAL;
 	return th1520_pinmux_set(thp, thp->desc.pins[gsel].number,
 				 (uintptr_t)thp->desc.pins[gsel].drv_data & TH1520_PAD_MUXDATA,
 				 (uintptr_t)func->data);
Signature · 1 line
2.34.1

Thanks for fixing the formating in the previous attempt.

As Kees Bakker noted [1], I failed to have this check in my v3 patch series. This fix makes pinctrl-th1520 behave the same as other drivers that call pinmux_generic_get_function() like pinctrl-single. I have applied your patch and the driver still works as expected on my LPi4a.

Hopefully Linus can apply this fix on top of my v3 series.

-Drew

[1] https://lore.kernel.org/lkml/[email protected]/