Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3565215imm; Sun, 16 Sep 2018 22:21:13 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZtdWkjiDHzAe0olWiQ4bo/6v7LiZp6riUVFX/Wupvil2bIR1rEpbU5qDTnqjtj762TZOtF X-Received: by 2002:a63:4c54:: with SMTP id m20-v6mr19322789pgl.292.1537161673617; Sun, 16 Sep 2018 22:21:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537161673; cv=none; d=google.com; s=arc-20160816; b=LTdqoGTVxUjUH74NfZGXi4Ab71xe/mK9Gw1xhq8n0RGffxauNh9sEFj17aCbHlWbD2 aq1GO0tlL/d+tu5RwpZuBZY1+PAvvlk/gfeEN7g20y087g9ruZkB3xKQv7D5XJiy3rnH ti+lyXYfP4EE3LINrDRZfObTyQ0xMHh26Et0oAtNSwWC2dXGCau4c/BbeScz/JnYeq7U 8UaV3BKhdK3WKGn49vmyNi5RTH8FU9VqixNKCN3vAZxv+0Ht4dc12s8MHq1Svtq94q2A GjCsQNdpnXcnYqmqU5APNPAxADL1Ew2hC6qJYaSbd1nSvB4vnmMzLhgPC/4oZx78NYbg Lbvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=IsFYNlXJJtrdYfgXiT30+ULZsYQjtHF7YUy5ZB5BR1k=; b=UysPLeaKKoh33iidAXFJ8pWAACi6CM+jq8WRt8qqTh4l1BOmD8o5eUQpxR9heaWGvl gaZzv+mFWG0Bk2n+PVOi2vq88kS50K6F4ZHf2n8XihvuelVFTUQh+4bK30yRfaS7CjK7 +WOvuuyf2BNrtY9+7wiegrQELxMQQrlZAAsOuyhR3xh8XBqHjVjqpB26talhIEaKOcgu H8tMbWazQgy3Lm5ImR2woKsDIztA5cT/9q5qsl6yKE3WgkHdfe6z++mcosSU9H2oYwuk apqzNOD+0FE5wqw9iA6x36mnO5S2res5gRWjnkPCXmKEGeH7myfTMbo1gEt5ecHaf0E8 pYPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kemnade.info header.s=20180802 header.b=KBxbIuP2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q74-v6si16963462pfq.32.2018.09.16.22.20.57; Sun, 16 Sep 2018 22:21:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@kemnade.info header.s=20180802 header.b=KBxbIuP2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728435AbeIQKqg (ORCPT + 99 others); Mon, 17 Sep 2018 06:46:36 -0400 Received: from mail.andi.de1.cc ([85.214.239.24]:40152 "EHLO h2641619.stratoserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726078AbeIQKqg (ORCPT ); Mon, 17 Sep 2018 06:46:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kemnade.info; s=20180802; h=Message-Id:Date:Subject:Cc:To:From:Sender: Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=IsFYNlXJJtrdYfgXiT30+ULZsYQjtHF7YUy5ZB5BR1k=; b=KBxbIuP2nV2on6/Q8M4fa0Pb4J A5cq1mjbSaoHRH+aIxSST1ZOtKWTAZdUKKrweXuMIaWjiKIADSm8KrzhNwsVXHnBHCl7c6bg7ucoi WUAgoEH76nyDkQp552Txi9NpT7tlftrebrehmiHJDKIESba5zR6WGM3Dum15V0JkK+jY=; Received: from p200300ccfbca24001a3da2fffebfd33a.dip0.t-ipconnect.de ([2003:cc:fbca:2400:1a3d:a2ff:febf:d33a] helo=aktux) by h2641619.stratoserver.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1g1lxo-0006Tb-Fy; Mon, 17 Sep 2018 07:20:48 +0200 Received: from andi by aktux with local (Exim 4.89) (envelope-from ) id 1g1lxn-0003CG-O8; Mon, 17 Sep 2018 07:20:47 +0200 From: Andreas Kemnade To: sre@kernel.org, linux-pm@vger.kernel.org, linux-omap@vger.kernel.org, Discussions about the Letux Kernel , linux-kernel@vger.kernel.org Cc: Andreas Kemnade Subject: [PATCH RESEND] twl4030_charger: fix charging current out-of-bounds Date: Mon, 17 Sep 2018 07:20:35 +0200 Message-Id: <20180917052035.12234-1-andreas@kemnade.info> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org the charging current uses unsigned int variables, if we step back if the current is still low, we would run into negative which means setting the target to a huge value. Better add checks here. Signed-off-by: Andreas Kemnade --- drivers/power/supply/twl4030_charger.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/twl4030_charger.c b/drivers/power/supply/twl4030_charger.c index b72838663872..c954b7234393 100644 --- a/drivers/power/supply/twl4030_charger.c +++ b/drivers/power/supply/twl4030_charger.c @@ -421,7 +421,8 @@ static void twl4030_current_worker(struct work_struct *data) if (v < USB_MIN_VOLT) { /* Back up and stop adjusting. */ - bci->usb_cur -= USB_CUR_STEP; + if (bci->usb_cur >= USB_CUR_STEP) + bci->usb_cur -= USB_CUR_STEP; bci->usb_cur_target = bci->usb_cur; } else if (bci->usb_cur >= bci->usb_cur_target || bci->usb_cur + USB_CUR_STEP > USB_MAX_CURRENT) { -- 2.11.0