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 for Android: free password hash cracker in your pocket
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20231016053510.28881-1-stanley_chang@realtek.com>
Date:   Mon, 16 Oct 2023 13:35:04 +0800
From:   Stanley Chang <stanley_chang@...ltek.com>
To:     Chanwoo Choi <cw00.choi@...sung.com>
CC:     Stanley Chang <stanley_chang@...ltek.com>,
        Dan Carpenter <dan.carpenter@...aro.org>,
        MyungJoo Ham <myungjoo.ham@...sung.com>,
        <linux-kernel@...r.kernel.org>
Subject: [PATCH extcon-next] extcon: realtek: add the error handler for nvmem_cell_read

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);
 	}
 
-- 
2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ