Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pinctrl: th1520: Fix potential null pointer dereference on func

The initialization of muxtype deferences pointer func before func
is sanity checked with a null pointer check, hence we have a null
pointer deference issue. Fix this by only deferencing func with
the assignment to muxtype after func has been null pointer checked.

Fixes: 1fc30cd92770 ("pinctrl: th1520: Factor out casts")
Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
Reported-by: Kees Bakker <kees@ijzerbout.nl>
Acked-by: Drew Fustini <dfustini@tenstorrent.com>
Link: https://lore.kernel.org/20241016155655.334518-1-colin.i.king@gmail.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Colin Ian King and committed by
Linus Walleij
05214b06 22c91825

+2 -1
+2 -1
drivers/pinctrl/pinctrl-th1520.c
··· 803 803 { 804 804 struct th1520_pinctrl *thp = pinctrl_dev_get_drvdata(pctldev); 805 805 const struct function_desc *func = pinmux_generic_get_function(pctldev, fsel); 806 - enum th1520_muxtype muxtype = (uintptr_t)func->data; 806 + enum th1520_muxtype muxtype; 807 807 808 808 if (!func) 809 809 return -EINVAL; 810 810 811 + muxtype = (uintptr_t)func->data; 811 812 return th1520_pinmux_set(thp, thp->desc.pins[gsel].number, 812 813 th1520_pad_muxdata(thp->desc.pins[gsel].drv_data), 813 814 muxtype);