lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <c2b7a88c-2a6d-49f6-974a-5f21915aea3c@kernel.org>
Date:   Tue, 17 Oct 2023 17:41:22 +0900
From:   Chanwoo Choi <chanwoo@...nel.org>
To:     Stanley Chang <stanley_chang@...ltek.com>,
        Chanwoo Choi <cw00.choi@...sung.com>
Cc:     Dan Carpenter <dan.carpenter@...aro.org>,
        MyungJoo Ham <myungjoo.ham@...sung.com>,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH extcon-next] extcon: realtek: add the error handler for
 nvmem_cell_read

On 23. 10. 16. 14:35, Stanley Chang wrote:
> There are following smatch warning:
> drivers/extcon/extcon-rtk-type-c.c:905 __updated_type_c_parameter_by_efuse()
> error: 'buf' dereferencing possible ERR_PTR()
> 
> The nvmem_cell_read may fail to read. So, driver must handle failure cases.
> 
> Fixes: 8a590d7371f0 ("extcon: add Realtek DHC RTD SoC Type-C driver")
> Reported-by: Dan Carpenter <dan.carpenter@...aro.org>
> Closes: https://lore.kernel.org/all/a469dd51-f5d5-4e8f-ba36-6c7cea046fb8@moroto.mountain/
> Signed-off-by: Stanley Chang <stanley_chang@...ltek.com>
> ---
>  drivers/extcon/extcon-rtk-type-c.c | 86 +++++++++++++++---------------
>  1 file changed, 44 insertions(+), 42 deletions(-)
> 
> diff --git a/drivers/extcon/extcon-rtk-type-c.c b/drivers/extcon/extcon-rtk-type-c.c
> index 00465cfba23e..a592bab77538 100644
> --- a/drivers/extcon/extcon-rtk-type-c.c
> +++ b/drivers/extcon/extcon-rtk-type-c.c
> @@ -901,25 +901,26 @@ static int __updated_type_c_parameter_by_efuse(struct type_c_data *type_c)
>  		int value_mask = (BIT(value_size) - 1);
>  
>  		buf = nvmem_cell_read(cell, &buf_size);
> -
> -		cc1_0p2v = get_value((buf[0] >> value_size * 0) & value_mask);
> -		cc1_0p8v = get_value((buf[0] >> value_size * 1) & value_mask);
> -		cc1_2p6v = get_value((buf[1] >> value_size * 0) & value_mask);
> -		cc1_0p66v = get_value((buf[1] >> value_size * 1) & value_mask);
> -		cc1_1p23v = get_value((buf[2] >> value_size * 0) & value_mask);
> -
> -		cc2_0p2v = get_value((buf[3] >> value_size * 0) & value_mask);
> -		cc2_0p8v = get_value((buf[3] >> value_size * 1) & value_mask);
> -		cc2_2p6v = get_value((buf[4] >> value_size * 0) & value_mask);
> -		cc2_0p66v = get_value((buf[4] >> value_size * 1) & value_mask);
> -		cc2_1p23v = get_value((buf[5] >> value_size * 0) & value_mask);
> -
> -		cc1_4p7k = get_value((buf[6] >> value_size * 0) & value_mask);
> -		cc1_12k = get_value((buf[6] >> value_size * 1) & value_mask);
> -		cc2_4p7k = get_value((buf[7] >> value_size * 0) & value_mask);
> -		cc2_12k = get_value((buf[7] >> value_size * 1) & value_mask);
> -
> -		kfree(buf);
> +		if (!IS_ERR(buf)) {
> +			cc1_0p2v = get_value((buf[0] >> value_size * 0) & value_mask);
> +			cc1_0p8v = get_value((buf[0] >> value_size * 1) & value_mask);
> +			cc1_2p6v = get_value((buf[1] >> value_size * 0) & value_mask);
> +			cc1_0p66v = get_value((buf[1] >> value_size * 1) & value_mask);
> +			cc1_1p23v = get_value((buf[2] >> value_size * 0) & value_mask);
> +
> +			cc2_0p2v = get_value((buf[3] >> value_size * 0) & value_mask);
> +			cc2_0p8v = get_value((buf[3] >> value_size * 1) & value_mask);
> +			cc2_2p6v = get_value((buf[4] >> value_size * 0) & value_mask);
> +			cc2_0p66v = get_value((buf[4] >> value_size * 1) & value_mask);
> +			cc2_1p23v = get_value((buf[5] >> value_size * 0) & value_mask);
> +
> +			cc1_4p7k = get_value((buf[6] >> value_size * 0) & value_mask);
> +			cc1_12k = get_value((buf[6] >> value_size * 1) & value_mask);
> +			cc2_4p7k = get_value((buf[7] >> value_size * 0) & value_mask);
> +			cc2_12k = get_value((buf[7] >> value_size * 1) & value_mask);
> +
> +			kfree(buf);
> +		}
>  		nvmem_cell_put(cell);
>  	}
>  
> @@ -984,29 +985,30 @@ static int __updated_type_c_parameter_by_efuse_v2(struct type_c_data *type_c)
>  		int value_mask = (BIT(value_size) - 1);
>  
>  		buf = nvmem_cell_read(cell, &buf_size);
> -
> -		value_size = 5;
> -		value_mask = (BIT(value_size) - 1);
> -		cc1_4p7k = buf[0] & value_mask;
> -		cc1_12k = buf[1] & value_mask;
> -		cc2_4p7k = buf[2] & value_mask;
> -		cc2_12k = buf[3] & value_mask;
> -
> -		value_size = 4;
> -		value_mask = (BIT(value_size) - 1);
> -		cc1_0p2v = (buf[4] >> value_size * 0) & value_mask;
> -		cc1_0p66v = (buf[4] >> value_size * 1) & value_mask;
> -		cc1_0p8v = (buf[5] >> value_size * 0) & value_mask;
> -		cc1_1p23v = (buf[5] >> value_size * 1) & value_mask;
> -		cc1_2p6v = (buf[6] >> value_size * 0) & value_mask;
> -
> -		cc2_0p2v = (buf[6] >> value_size * 1) & value_mask;
> -		cc2_0p66v = (buf[7] >> value_size * 0) & value_mask;
> -		cc2_0p8v = (buf[7] >> value_size * 1) & value_mask;
> -		cc2_1p23v = (buf[8] >> value_size * 0) & value_mask;
> -		cc2_2p6v = (buf[8] >> value_size * 1) & value_mask;
> -
> -		kfree(buf);
> +		if (!IS_ERR(buf)) {
> +			value_size = 5;
> +			value_mask = (BIT(value_size) - 1);
> +			cc1_4p7k = buf[0] & value_mask;
> +			cc1_12k = buf[1] & value_mask;
> +			cc2_4p7k = buf[2] & value_mask;
> +			cc2_12k = buf[3] & value_mask;
> +
> +			value_size = 4;
> +			value_mask = (BIT(value_size) - 1);
> +			cc1_0p2v = (buf[4] >> value_size * 0) & value_mask;
> +			cc1_0p66v = (buf[4] >> value_size * 1) & value_mask;
> +			cc1_0p8v = (buf[5] >> value_size * 0) & value_mask;
> +			cc1_1p23v = (buf[5] >> value_size * 1) & value_mask;
> +			cc1_2p6v = (buf[6] >> value_size * 0) & value_mask;
> +
> +			cc2_0p2v = (buf[6] >> value_size * 1) & value_mask;
> +			cc2_0p66v = (buf[7] >> value_size * 0) & value_mask;
> +			cc2_0p8v = (buf[7] >> value_size * 1) & value_mask;
> +			cc2_1p23v = (buf[8] >> value_size * 0) & value_mask;
> +			cc2_2p6v = (buf[8] >> value_size * 1) & value_mask;
> +
> +			kfree(buf);
> +		}
>  		nvmem_cell_put(cell);
>  	}
>  

Applied it. Thanks.

-- 
Best Regards,
Samsung Electronics
Chanwoo Choi

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ