Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3158923imm; Sun, 30 Sep 2018 13:17:32 -0700 (PDT) X-Google-Smtp-Source: ACcGV62FL7sAQR+5whVKD0zg9nbRLzq4S2lrhpbW9y9fZAJLB9ZK6lPypgxFxy23b530Jw9KAQPX X-Received: by 2002:a17:902:981:: with SMTP id 1-v6mr8490483pln.60.1538338652155; Sun, 30 Sep 2018 13:17:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538338652; cv=none; d=google.com; s=arc-20160816; b=hg/nm2b92fr0PqjHnYMu/o0AKRcTGf/5XRm7JEsEloZlThlcDbd4Qt2YM+KDJLtlQS BckRmoXNDVAegzEnn/+ykEZbll65WgRBAYxJ0+gWV5nJa6GffyhRQpyC3K32rAgqhe1E 9Lp7ykJbXMDnFTYQNkPIPHAEB2T0LxKv2i0s4hJti0AkfjL0TBV56upnRJst+yicBXDW iB+DfUPHKzVRmcMx89P2r34o3kxRecMkiIpyn5ncbDch/OelSLjT3WIWBWeMBcCcJOc4 3301V62wXTQJ1lZ4zl+nEA53llQ1f4ucp4QOBmAjZugwtrZxbYnvh7T88XGOYK8Q/bnJ et4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=oLLUhqPEap1txRpwou62s6vTWptORfcQ9fd8KeiocCs=; b=qwPmAITeS4eUcZCuneUxFUPJzIHLs0tTlPal/wVXdBwz9l18RThZFBYKOQzDmqmu0i GQzzQzseLGQfaZffBnNyGWCKruu5HrUWuzl4AFIG3S5mdOSex9wLrI21mmPJe4QvU3Dt UF0zaqY0BV3nbtl1DNbBIhaYp+fcr1tYFLoajj2vsdHaVuBfSmmf/n8+fI8xB31ZVQPT mx+LiOLfI3z4GgwztQ73fEbtjZOSyVS0O/qUT44udIJvf8t+PLec6V81tE0IzQdF2WGA l9+z7gviuiQ9rFIxrJFiPI9R0roGY0Z+6hN0up2aWbQQM7Ow+fkJEYXDPdg11nI7ouHJ UcpQ== ARC-Authentication-Results: i=1; mx.google.com; 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 64-v6si11147193plb.262.2018.09.30.13.16.50; Sun, 30 Sep 2018 13:17:32 -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; 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 S1728586AbeJACvK (ORCPT + 99 others); Sun, 30 Sep 2018 22:51:10 -0400 Received: from atrey.karlin.mff.cuni.cz ([195.113.26.193]:39323 "EHLO atrey.karlin.mff.cuni.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728534AbeJACvJ (ORCPT ); Sun, 30 Sep 2018 22:51:09 -0400 Received: by atrey.karlin.mff.cuni.cz (Postfix, from userid 512) id 56AD0807FB; Sun, 30 Sep 2018 22:16:43 +0200 (CEST) Date: Sun, 30 Sep 2018 22:16:42 +0200 From: Pavel Machek To: Andreas Kemnade Cc: sre@kernel.org, linux-pm@vger.kernel.org, linux-omap@vger.kernel.org, Discussions about the Letux Kernel , linux-kernel@vger.kernel.org Subject: Re: [PATCH RESEND] twl4030_charger: fix charging current out-of-bounds Message-ID: <20180930201642.GC23554@amd> References: <20180917052035.12234-1-andreas@kemnade.info> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Md/poaVZ8hnGTzuv" Content-Disposition: inline In-Reply-To: <20180917052035.12234-1-andreas@kemnade.info> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --Md/poaVZ8hnGTzuv Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon 2018-09-17 07:20:35, Andreas Kemnade wrote: > 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. Do you expect this to happen in practice? Too high current while charging seems bad, right? Cc: stable? Pavel > Signed-off-by: Andreas Kemnade > --- > drivers/power/supply/twl4030_charger.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) >=20 > diff --git a/drivers/power/supply/twl4030_charger.c b/drivers/power/suppl= y/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) > =20 > if (v < USB_MIN_VOLT) { > /* Back up and stop adjusting. */ > - bci->usb_cur -=3D USB_CUR_STEP; > + if (bci->usb_cur >=3D USB_CUR_STEP) > + bci->usb_cur -=3D USB_CUR_STEP; > bci->usb_cur_target =3D bci->usb_cur; > } else if (bci->usb_cur >=3D bci->usb_cur_target || > bci->usb_cur + USB_CUR_STEP > USB_MAX_CURRENT) { --=20 (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blo= g.html --Md/poaVZ8hnGTzuv Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAluxLyoACgkQMOfwapXb+vLUdQCcCw2lUChh9QF8KfmJ8mbNNEDq JHwAnRlP32MAnHnP4hLLBC0Zrzm5fO4Z =G8F0 -----END PGP SIGNATURE----- --Md/poaVZ8hnGTzuv--