diff options
author | Stanley Chang <stanley_chang@realtek.com> | 2023-10-16 13:35:04 +0800 |
---|---|---|
committer | Chanwoo Choi <cw00.choi@samsung.com> | 2023-10-17 17:38:57 +0900 |
commit | b3edc3463d64bc469162138a6bec6913fbeef931 (patch) | |
tree | 81854916205bc217673dc205aaffe01c05cbb6f1 /drivers/extcon | |
parent | da886ba844791d11c9d1526fddf8607eb0198243 (diff) |
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.
Link: https://lore.kernel.org/all/20231016053510.28881-1-stanley_chang@realtek.com/
Fixes: 8a590d7371f0 ("extcon: add Realtek DHC RTD SoC Type-C driver")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/all/a469dd51-f5d5-4e8f-ba36-6c7cea046fb8@moroto.mountain/
Signed-off-by: Stanley Chang <stanley_chang@realtek.com>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Diffstat (limited to 'drivers/extcon')
-rw-r--r-- | drivers/extcon/extcon-rtk-type-c.c | 86 |
1 files 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); } |