pinctrl: single: fix potential NULL dereference

Message ID 20221118104332.943-1-korotkov.maxim.s@gmail.com
State New
Headers
Series pinctrl: single: fix potential NULL dereference |

Commit Message

Maxim Korotkov Nov. 18, 2022, 10:43 a.m. UTC
  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>
---
 drivers/pinctrl/pinctrl-single.c | 2 ++
 1 file changed, 2 insertions(+)
  

Comments

Tony Lindgren Nov. 18, 2022, 12:52 p.m. UTC | #1
* Maxim Korotkov <korotkov.maxim.s@gmail.com> [221118 10:33]:
> 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.

Reviewed-by: Tony Lindgren <tony@atomide.com>
  
Maxim Korotkov Jan. 25, 2023, 9:03 a.m. UTC | #2
Dear Linus,
Will this patch be applied or rejected?
best regards, Max

On 18.11.2022 15:52, Tony Lindgren wrote:
> * Maxim Korotkov <korotkov.maxim.s@gmail.com> [221118 10:33]:
>> 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.
> 
> Reviewed-by: Tony Lindgren <tony@atomide.com>
  
Linus Walleij Jan. 27, 2023, 12:44 p.m. UTC | #3
On Fri, Nov 18, 2022 at 11:43 AM Maxim Korotkov
<korotkov.maxim.s@gmail.com> wrote:

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

Patch applied for fixes.

Yours,
Linus Walleij
  

Patch

diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index 67bec7ea0f8b..5655a2da5413 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -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;