Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp22381pxt; Thu, 5 Aug 2021 16:46:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4lYnXNsjizLQMK7DtFQirx/VPiA6WNQaBQ2+iNwv6qCuyWvpEX+eAHqcI8wS8vUCwKXKJ X-Received: by 2002:a5e:dd49:: with SMTP id u9mr535283iop.102.1628207167580; Thu, 05 Aug 2021 16:46:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628207167; cv=none; d=google.com; s=arc-20160816; b=vdOfs+KMokvGagiM/Bl3QWg3ltQtyyT9EWLG1ZB7b0EwAmhGwYXDpBbpz7vqJ4BXUD GD/bgktfaUjoxh82Q3jUTBBe9fK7jEiu4725o6Kqez8qPn/Kj7V9jPZCZLBq8aCGrXAe FU9DQNCk406ZqZrFbKU7zlqTCcOFoUhkgiA2KzGjHogqpXEm4Nq/ebevYlC9G7pwXmhQ 5TZwqwbjQgrAJa6KYhtN2uD7UVftSXzUzKFlYlKXdMcBJ2RoKzn691VJTQEfDLnueGve 7kHEMNa9dQKD75KmPB32U648iQOG7HrE2zZ1R4YhjO4KEQ78pqBhra09pWyQO4K7kk42 WKPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=hgh8n/mlJ2BWgXVr9IEapn30lUSRxQYBbXEgYVfExsI=; b=1CkdqF7uzfsRL8xKznsVUXct7qY6HWwSAphmcj6IsrujWSuOElPoe6J5AGV88IUQCz tkN2a788DAg/R1epnmDThxlCUZeycAlskeqAC5XFc81SxFmpPiwXPBl2WKKGsQo+5NCW 57FkR+EsACgO9CRRDonvFmU+wNoPL87FRFiPYSLVutWi80axFGB8FKLQsPA9KwLpKTyv ee+f/pyl5c5LYD2kzOj06flvv19W9Dj4gKlq9/lWPZzJGL1+GWTeND61cg9QfdRYJqo8 JVqVZ2c/chOHMWeEK/I2QLpv9vLmhzgSKiy2OBEVpZN71YF7uj5g62ZFJ5OVri9HWy/W vbaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=S4dR9GzV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r17si7873803iov.104.2021.08.05.16.45.55; Thu, 05 Aug 2021 16:46:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=S4dR9GzV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240369AbhHERtZ (ORCPT + 99 others); Thu, 5 Aug 2021 13:49:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:36746 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236276AbhHERtZ (ORCPT ); Thu, 5 Aug 2021 13:49:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9177960EEA; Thu, 5 Aug 2021 17:49:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1628185750; bh=hgh8n/mlJ2BWgXVr9IEapn30lUSRxQYBbXEgYVfExsI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=S4dR9GzVij9XR2qNakG0ENKTKKely4MQG5DFuH95wJ67k62Pdes6YwV4oUx5fKqX4 bW/mIC7UmNY/rq2bHtfrYvyHBjt/4BG9oq25K/MtRfRoIbipwY9HAQyqX+YrY+RqCw N3U3LxnIda1nantkXBMivAMJSqJHT8I5Ri2dqKSHmKhjE4C4dUAN2vkIC2liQ7p246 4uDUbLZ70gbtQy85TBWjM/7h9IO3etzRFXzEMiYw+3t1wscYta3MGLElWFx++gYBpG 2YxfotWf/tbPB6f6jCRkoQ67eB4WmwSti3EU5Nt89Ort8YOclXwUNsgbm+7awJwNfl AFq2gLeht/mwA== Received: by earth.universe (Postfix, from userid 1000) id 959BF3C0C9B; Thu, 5 Aug 2021 19:49:08 +0200 (CEST) Date: Thu, 5 Aug 2021 19:49:08 +0200 From: Sebastian Reichel To: Li Tuo Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, baijiaju1990@gmail.com, "Jett.Zhou" Subject: Re: [BUG] power: supply: 88pm860x_battery: possible uninitialized-variable access in measure_vbatt() Message-ID: <20210805174908.ctg6n5iwmg5izap3@earth.universe> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="zwujtqsremn5py5a" Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --zwujtqsremn5py5a Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable [adding Jett Zhou to Cc who introduced the driver] Hi, On Wed, Jul 28, 2021 at 06:24:12PM +0800, Li Tuo wrote: > Our static analysis tool finds a possible uninitialized-variable access in > the 88pm860x_battery driver in Linux 5.14.0-rc3: >=20 > In calc_soc(): > 369:=A0=A0=A0 int ocv; > 376:=A0=A0=A0 switch (state) { > 380:=A0=A0=A0 case OCV_MODE_SLEEP: > 381:=A0=A0=A0=A0=A0=A0=A0 ret =3D measure_vbatt(info, OCV_MODE_SLEEP, &oc= v); >=20 > In measure_vbatt(struct pm860x_battery_info *info, int state, int *data) > 176:=A0=A0=A0 switch (state) { > 184:=A0=A0=A0 case OCV_MODE_SLEEP: > 201:=A0=A0=A0=A0=A0=A0=A0 *data =3D ((*data & 0xff) * 27 * 25) >> 9; >=20 > If the variable state is OCV_MODE_SLEEP, the function measure_vbatt() is > called with the argument &ocv, and the corresponding parameter is data. > Thus *data is uninitialized but it is used at line 201. >=20 > I am not quite sure whether this possible uninitialized-variable access is > real and how to fix it if it is real. > Any feedback would be appreciated, thanks! >=20 > Reported-by: TOTE Robot I suppose the code is suppose to look like this: 201:=A0=A0=A0=A0=A0=A0=A0 *data =3D ((ret & 0xff) * 27 * 25) >> 9; Considering quite some code is spent before to setup ret, which is never used. I don't have the device (nor datasheets) though. Considering the driver has only seen trivial cleanups over the last 9 years, maybe it can just be removed? -- Sebastian --zwujtqsremn5py5a Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEE72YNB0Y/i3JqeVQT2O7X88g7+poFAmEMJI4ACgkQ2O7X88g7 +poT7g//cufoD1ZEZiJECh7O3127FFRZoHWb8mwwyL0inJP58K532Nb0i6r3bq2u muv8YJmrgTynrMdvWx1tlZwoD6GaYmCUE9c0h4v9j9m782XGJIH0KLx8RrlkxXii b461y9Bj1SHE6jwxy4p7BML3ensp/zGJb7GS2RZnhpZqwVURYctl8zasAnyTff8N i00EH4G8ehrl2fcT5V1WzK0AxB3DVX205DPGqNLLijHBRcS8P/wxNQZP5S79C5fO DUikpsVmg4DGR5btCQo2Oh7axWAPpKfgUGOlDQUT1vYJzxciOCWinv/4GMRT31uC JiMjeeiaGXaLXSGTA1lZe25U0XLt1RSieGhns+jgrLke2x9B3NSklJBo087cZyJ8 e3XavBvLPXg2Ttz2pgRmq3UdmzkYTBpLVEBb4p9WIb9w95LNI8fSqZJVu+YszCN/ KKkUWxRzK6469nYdsp0Wq+y9eUU35lesn7EKIes6OGGclapAEy013ndyUW01mKm5 nq1dK8GWarCIOpVBT09EvhZp6tbFHVL19om+TGJ8POFnKUigI/mLA6O4mJLltiqd 7TMgY4VF3FOWzAhimxakMvy3Innst/gy7D4+JiJttbtDG92M9yoW1MN4O1GX+H+c ffWJjRlxzajLhDEwAJeG/J4uhGosT1TjuF7HnCoysB9/gUIUfBQ= =TU6k -----END PGP SIGNATURE----- --zwujtqsremn5py5a--