Re: [PATCH RESEND] pinctrl: single: fix potential NULL dereference in pcs_get_function()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 21 Aug 2024 14:21:32 +0800 Ma Ke <make24@xxxxxxxxxxx> wrote:

> pinmux_generic_get_function() can return NULL and the pointer 'function'
> was dereferenced without checking against NULL. Add checking of pointer
> 'function' in pcs_get_function().
> 
> Found by code review.
> 
> ...
>
> --- a/drivers/pinctrl/pinctrl-single.c
> +++ b/drivers/pinctrl/pinctrl-single.c
> @@ -345,6 +345,8 @@ static int pcs_get_function(struct pinctrl_dev *pctldev, unsigned pin,
>  		return -ENOTSUPP;
>  	fselector = setting->func;
>  	function = pinmux_generic_get_function(pctldev, fselector);
> +	if (!function)
> +		return -EINVAL;
>  	*func = function->data;
>  	if (!(*func)) {
>  		dev_err(pcs->dev, "%s could not find function%i\n",

Maybe.  Or maybe pinmux_generic_get_function() must always return a
valid pointer, in which case

	BUG_ON(!function);

is an appropriate thing.  But a null-pointer deref gives us the same
info, so no change is needed.

btw, pinmux_generic_get_function() is funny:

	if (!function)
		return NULL;

	return function;






[Index of Archives]     [Linux Arm (vger)]     [ARM Kernel]     [ARM MSM]     [Linux Tegra]     [Linux WPAN Networking]     [Linux Wireless Networking]     [Maemo Users]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux