Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4DB4BC19775 for ; Wed, 24 Nov 2021 12:16:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243967AbhKXMTB (ORCPT ); Wed, 24 Nov 2021 07:19:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:47100 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243572AbhKXMOL (ORCPT ); Wed, 24 Nov 2021 07:14:11 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id A6B7E610D2; Wed, 24 Nov 2021 12:09:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1637755754; bh=/kCIwFyoEiyl9hIRSwx3rTxQS0roK+ikSpTf9ftr4+0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WXh/i0v+m4JBCxc2way3cKhxiaG6bB3synqmmzPNlKdmU/EJIV2ig79fqqVnPPdJD Ttq9vX0neLbpj/A4epiKXi4zNYYIvX53Nil63tku4GeWyfe8tjla+3ZEq8hhzJ/GpQ rNqsadxbmliIBuDG3oy4QZwSCU+kSmWWnGGrB3nU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sebastian Krzyszkowiak , Krzysztof Kozlowski , Sebastian Reichel Subject: [PATCH 4.9 044/207] power: supply: max17042_battery: Prevent int underflow in set_soc_threshold Date: Wed, 24 Nov 2021 12:55:15 +0100 Message-Id: <20211124115705.362729174@linuxfoundation.org> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211124115703.941380739@linuxfoundation.org> References: <20211124115703.941380739@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sebastian Krzyszkowiak commit e660dbb68c6b3f7b9eb8b9775846a44f9798b719 upstream. max17042_set_soc_threshold gets called with offset set to 1, which means that minimum threshold value would underflow once SOC got down to 0, causing invalid alerts from the gauge. Fixes: e5f3872d2044 ("max17042: Add support for signalling change in SOC") Cc: Signed-off-by: Sebastian Krzyszkowiak Reviewed-by: Krzysztof Kozlowski Signed-off-by: Sebastian Reichel Signed-off-by: Greg Kroah-Hartman --- drivers/power/supply/max17042_battery.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/power/supply/max17042_battery.c +++ b/drivers/power/supply/max17042_battery.c @@ -752,7 +752,8 @@ static void max17042_set_soc_threshold(s regmap_read(map, MAX17042_RepSOC, &soc); soc >>= 8; soc_tr = (soc + off) << 8; - soc_tr |= (soc - off); + if (off < soc) + soc_tr |= soc - off; regmap_write(map, MAX17042_SALRT_Th, soc_tr); }