Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp3041716rdb; Wed, 15 Nov 2023 20:19:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IESJZMQcnn7IDVOjZbQkdhtmK598EWng/gnulI5UgUtP3HyhET/hInKjPL1xR0Gzni64ISu X-Received: by 2002:a05:6a20:8e22:b0:161:aef5:6395 with SMTP id y34-20020a056a208e2200b00161aef56395mr703071pzj.24.1700108359630; Wed, 15 Nov 2023 20:19:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700108359; cv=none; d=google.com; s=arc-20160816; b=viGviKx2Jl2femejn7MdPaooPwqtAl7YMXijv2/kuj4z+FrjrfEI+1nn3627sl0ctn aTIM7pi+IMwAJFF9sWnsw+XGM47xJYSEa9SgKF9fEo7cauJYUnEUxeoCMr/aCuo7t8Q8 KU6oQS1bTASIRHgMoPaLbKoaMrR4E02TVVqZA740FtLr70gU8NwCGbI4AohYAykbFtq6 pTY/lBMLfSHXKCXBqX6V2dXe3TFkiw4TVqKDXC6+HpFBNNKlP2n47LX+xjhAmYkAX1ik QLxYX+9tqMe1/16g5zHNxxpv9sNS4+R09mp6WufOuVtheaKn5jhXbPeUWLHc8viM1dx8 apTg== 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=fmzvE/TJhv2SxC7iQ55a7Y+I/V+nTKBqv13i5QeRzg4=; fh=R348R2TY2CrAf/RYOLlrXDbA1akDUp18hyO6mP4BTz4=; b=PYQbLulV8UuElm2E/iVWBEQadJIk1aTba9RJ7qABhYI21/FKXnwLpSkE8rfMliAhvz Xa7y8VrR8sxCr6NjHckPfLBYop5tXZMWW5uvHCNSx/A327jvrixkXuDTXh/W37l9PL2Y o5aec0GTx1q6imxWvyW6nWheafNf1hjwoM0ckVOKkyrjFpj21VrsFYje1/jciSJWgt++ ArY72NS6ql7/77Amh3Kc20LAsfAfnrhWlD3gevCNiXuT051ZvKstf/VugtMBEpFIQy4b kd06LoOvamy1ubN2Z701wYaqNer2b7mZa0XEpF5OKo9ZJraEORJJAgBhokTS9NIRw5Ij P7FQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id fc34-20020a056a002e2200b006c339c0cc08si11476282pfb.196.2023.11.15.20.19.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 20:19:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 402E180DECF7; Wed, 15 Nov 2023 20:19:18 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344645AbjKPETR (ORCPT + 99 others); Wed, 15 Nov 2023 23:19:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230207AbjKPETP (ORCPT ); Wed, 15 Nov 2023 23:19:15 -0500 Received: from mail.nfschina.com (unknown [42.101.60.195]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 0F791196; Wed, 15 Nov 2023 20:19:10 -0800 (PST) Received: from localhost.localdomain (unknown [180.167.10.98]) by mail.nfschina.com (Maildata Gateway V2.8.8) with ESMTPA id 1FDC2605DAF55; Thu, 16 Nov 2023 12:19:02 +0800 (CST) X-MD-Sfrom: suhui@nfschina.com X-MD-SrcIP: 180.167.10.98 From: Su Hui To: sre@kernel.org, nathan@kernel.org, ndesaulniers@google.com, trix@redhat.com Cc: Su Hui , r-rivera-matos@ti.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, kernel-janitors@vger.kernel.org Subject: [PATCH] power: supply: bq256xx: fix some problem in bq256xx_hw_init Date: Thu, 16 Nov 2023 12:18:23 +0800 Message-Id: <20231116041822.1378758-1-suhui@nfschina.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,RDNS_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 15 Nov 2023 20:19:18 -0800 (PST) smatch complains that there is a buffer overflow and clang complains 'ret' is never read. Smatch error: drivers/power/supply/bq256xx_charger.c:1578 bq256xx_hw_init() error: buffer overflow 'bq256xx_watchdog_time' 4 <= 4 Clang static checker: Value stored to 'ret' is never read. Add check for buffer overflow and error code from regmap_update_bits(). Fixes: 32e4978bb920 ("power: supply: bq256xx: Introduce the BQ256XX charger driver") Signed-off-by: Su Hui --- drivers/power/supply/bq256xx_charger.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/bq256xx_charger.c b/drivers/power/supply/bq256xx_charger.c index 789a31bd70c3..1a935bc88510 100644 --- a/drivers/power/supply/bq256xx_charger.c +++ b/drivers/power/supply/bq256xx_charger.c @@ -1574,13 +1574,16 @@ static int bq256xx_hw_init(struct bq256xx_device *bq) wd_reg_val = i; break; } - if (bq->watchdog_timer > bq256xx_watchdog_time[i] && + if (i + 1 < BQ256XX_NUM_WD_VAL && + bq->watchdog_timer > bq256xx_watchdog_time[i] && bq->watchdog_timer < bq256xx_watchdog_time[i + 1]) wd_reg_val = i; } ret = regmap_update_bits(bq->regmap, BQ256XX_CHARGER_CONTROL_1, BQ256XX_WATCHDOG_MASK, wd_reg_val << BQ256XX_WDT_BIT_SHIFT); + if (ret) + return ret; ret = power_supply_get_battery_info(bq->charger, &bat_info); if (ret == -ENOMEM) -- 2.30.2