Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2298045rdg; Sun, 15 Oct 2023 22:36:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE0hyVmk4gh2OrJePrmP19gYuJBNN8AYIa/yJTi3HL96AD0VleSHaMujq0gWLRE1JIjHkH3 X-Received: by 2002:a17:903:22c4:b0:1b7:f64b:379b with SMTP id y4-20020a17090322c400b001b7f64b379bmr10109076plg.17.1697434572351; Sun, 15 Oct 2023 22:36:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697434572; cv=none; d=google.com; s=arc-20160816; b=ZXsioxF1t7ec+SMe1gDMY0bdP3I50HKnXaykP7caJoZceziAn5/tmjtv5Sr3vzCgSj x/NGjRf1m5dIHkcuoh4TE/2Jm0AF0zkhhjM/eedK+6y8ZownZD7002RWxOJ4jpxtNUdB g3Hp0NLNkSanEasxWkLQn7TlpfBHidroMyRFCnH7w67v+2tvFWrf/ArkO7CrPfokqdUD DX1vc8cFPRn/GB/imUjumTYOdZPUst1r4SHr9Vwpv4lvQw/qBFCCw8BKTklscDy8b58Q 8XwSQfirLJ03x0wrS15L0xwmDvOkhwnASwmJrPKxEk65n55TBbONB7LLhLs3XT1iPNnj wL1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=LPAeC3m8sYKXV1OQT5lbkVtv+5LprtjT0uBNbb8ryCk=; fh=6bImDf0kHDIR3+CfkxCo62Peia2tv4sx2w3QSZ3gJHI=; b=dxEgF/CRoh58OjdRiULDsiUK9Xp4xyyv399fN3TNwVQc2jXgdGjVC01YKb7KyzGSPZ WiqLid6H3djiFHp25WrBZpwnJ47XRVr3lQ+Y/wJgyyItLl6x7yzFcYtijaFrJFh3Iwh5 nsrar/nvW/byKHFJjZ79j/kukBMqRSklvWPH2cAvUbazuwd5fELdIwirR54Gfx/jSMXB oZxM2JllfWCP9O5Yod7OtGGoqY2IBrwRK6Ab9eZNnRBq8rOQqR4Axe5Wr7EgV8FIxEwl dpfk/VDJ8jvIzehe/II43SgwfzbwbEUfn8ivcqlxzLdX3nMbuMlQYKUAi0j1wJSzOA90 j0SQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id t5-20020a170902a5c500b001c75866c987si9444155plq.584.2023.10.15.22.36.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 22:36:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 984CC8079DC1; Sun, 15 Oct 2023 22:36:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231805AbjJPFfu (ORCPT + 99 others); Mon, 16 Oct 2023 01:35:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231783AbjJPFfh (ORCPT ); Mon, 16 Oct 2023 01:35:37 -0400 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31A5911D for ; Sun, 15 Oct 2023 22:35:18 -0700 (PDT) X-SpamFilter-By: ArmorX SpamTrap 5.78 with qID 39G5ZBztC2174365, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexh36505.realtek.com.tw[172.21.6.25]) by rtits2.realtek.com.tw (8.15.2/2.93/5.92) with ESMTPS id 39G5ZBztC2174365 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 Oct 2023 13:35:11 +0800 Received: from RTEXMBS06.realtek.com.tw (172.21.6.99) by RTEXH36505.realtek.com.tw (172.21.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.32; Mon, 16 Oct 2023 13:35:12 +0800 Received: from RTEXH36506.realtek.com.tw (172.21.6.27) by RTEXMBS06.realtek.com.tw (172.21.6.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Mon, 16 Oct 2023 13:35:10 +0800 Received: from localhost.localdomain (172.21.252.101) by RTEXH36506.realtek.com.tw (172.21.6.27) with Microsoft SMTP Server id 15.1.2507.17 via Frontend Transport; Mon, 16 Oct 2023 13:35:10 +0800 From: Stanley Chang To: Chanwoo Choi CC: Stanley Chang , Dan Carpenter , MyungJoo Ham , Subject: [PATCH extcon-next] extcon: realtek: add the error handler for nvmem_cell_read Date: Mon, 16 Oct 2023 13:35:04 +0800 Message-ID: <20231016053510.28881-1-stanley_chang@realtek.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-KSE-ServerInfo: RTEXMBS06.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-Antivirus-Interceptor-Info: fallback X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-ServerInfo: RTEXH36505.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-Antivirus-Interceptor-Info: fallback X-KSE-AntiSpam-Interceptor-Info: fallback X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sun, 15 Oct 2023 22:36:09 -0700 (PDT) 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 Closes: https://lore.kernel.org/all/a469dd51-f5d5-4e8f-ba36-6c7cea046fb8@moroto.mountain/ Signed-off-by: Stanley Chang --- 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