pinctrl: single: fix potential NULL dereference
authorMaxim Korotkov <korotkov.maxim.s@gmail.com>
Fri, 18 Nov 2022 10:43:32 +0000 (13:43 +0300)
committerLinus Walleij <linus.walleij@linaro.org>
Fri, 27 Jan 2023 12:43:55 +0000 (13:43 +0100)
Added checking of pointer "function" in pcs_set_mux().
pinmux_generic_get_function() can return NULL and the pointer
"function" was dereferenced without checking against NULL.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 571aec4df5b7 ("pinctrl: single: Use generic pinmux helpers for managing functions")
Signed-off-by: Maxim Korotkov <korotkov.maxim.s@gmail.com>
Reviewed-by: Tony Lindgren <tony@atomide.com>
Link: https://lore.kernel.org/r/20221118104332.943-1-korotkov.maxim.s@gmail.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/pinctrl/pinctrl-single.c

index 99c3745da4562037bc23f7e068fe53143593933c..190923757cda00db822bb22c84cd667116cc39c7 100644 (file)
@@ -372,6 +372,8 @@ static int pcs_set_mux(struct pinctrl_dev *pctldev, unsigned fselector,
        if (!pcs->fmask)
                return 0;
        function = pinmux_generic_get_function(pctldev, fselector);
+       if (!function)
+               return -EINVAL;
        func = function->data;
        if (!func)
                return -EINVAL;