Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp384196pxt; Fri, 6 Aug 2021 04:31:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQUsrmdURtyC/ecUd3FCSQp3kGmWK3qGahf21EOs8O78UtSkhN2kdjsEeXPXwqNmFpqTb2 X-Received: by 2002:aa7:dada:: with SMTP id x26mr12441065eds.156.1628249463975; Fri, 06 Aug 2021 04:31:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628249463; cv=none; d=google.com; s=arc-20160816; b=rjzLEPvJs6rSTWAQ1sBElVgYr6a+JEolV9UokuZIEI32eRSaISzgb8mUhQqakn4n91 HZpyqeXkY83hYjdkdeSpS6sikkT1xrmxNT5Fx0xeUzuBhvZCGI9W8ts/6518ID1CtrW9 ip/IaHZM+WFX8BHDftW4yZV9Weh6rigYI6iXSmoM3L11Wbtk0YRSBbgsGs7zTuZGR95w Eh5ZprZGZtibKEONId/3DE91qbl6o7vMCYLHe/6KcjTprcKhBQUuHylPh1nj+CAnVLps UlR+yzlulLtJ0O4qv3BendKp6BrJhwouDv93ozbMCFs/ocAU1/PVeC8+3l4eFp7zdbb9 mC1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=fS+XTOKPP/A+4Ea3Vfvk2lusfIUrsBa+uJZOXKxOTBs=; b=i4XrBPQIhDE5eJrMNUdZXoWxrmIPvUe1gdL6GshRCv/+uwuc/VbVUGaElVMEAT0xZn ABRI9Acsz04Hz4yslLYHThQxburj8EEvU6xdoxZqFV6QyhtTQS27wA00DescGd3/OpvH rkKft/zDJt7HRhBAID71x3UnLHXpRosARQFGOLr5qPUIlAbGtPq3q4WU12UGlqF/8YKW s03NGIJqsa9oJm8R7w8JxjBNYq86TJ3IRDT7DEcv56bFUQn5e57UuXTmjdj3JoROBFtU mu3HZiKjqHJbJbFzL/qKgVt6yeg8BgKyI270DVzQmCONzgIgqoqjtxuFVMrOlhT1qp5y mfyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ONTPD9Lm; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cq4si8984023edb.74.2021.08.06.04.30.40; Fri, 06 Aug 2021 04:31:03 -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=@gmail.com header.s=20161025 header.b=ONTPD9Lm; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238926AbhHFDaQ (ORCPT + 99 others); Thu, 5 Aug 2021 23:30:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231173AbhHFDaP (ORCPT ); Thu, 5 Aug 2021 23:30:15 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99938C061798; Thu, 5 Aug 2021 20:29:57 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id mt6so14004607pjb.1; Thu, 05 Aug 2021 20:29:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=fS+XTOKPP/A+4Ea3Vfvk2lusfIUrsBa+uJZOXKxOTBs=; b=ONTPD9LmSno01aJOy1CjhKkYK3doqsHNZJrZJypUlYU/TnSa8zfSp1hgMhRtYwTIlq ffoizk7QD3R1/qUjFO1u3vDNlJFWDvgrSfY+yBrHMxgy2pPR/+1lfsCgB47FAIEBq/Z0 u0cijgJtcZG2L58LElWv5Dw+zz8MMtvFAIt2eur6osbqkGOV07jUP6c7sa23yruL/MP/ PvvaISEbIJcwiOgZQEj+pCdlMpY598g9v7h+lpjoSRYbDQtzsfOcsDxuu+6bMqCRGOwX 4iAzKeGCSrchlHPqDnpyZQ7NtexcrLUUPSU7XWisGSrph402NGg7B3B2OsVaIF9xGicX CEtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=fS+XTOKPP/A+4Ea3Vfvk2lusfIUrsBa+uJZOXKxOTBs=; b=Yx4ex47yUmX2BnWX35pIBkLIws/51OKl5zUntq6BPVJf+16BcFOcxG4/CCxsZE1QkY 9gnF3pjTTlR1M6zXI7M+hTri+oLG4Hjmn6mQAYg53JCz8cGm9Nh/iJwNHSkI9HMUmgD3 lGn74w2MH1l9uUXd5pisTVVm27NmQUSGId5Q7ekrpn5rhkCBThWQ98YO5KL6zUzTnWSx WZunY6tjBrSkcSflUKHU2+AnQ9Y2c2Jg5NBC0C1asyhUHMGo5oNEhFFbYww4TJ29ALai 86EoRzLZtNxOPMfYtWK/lD4rgUSJDxqAFQZdFqJfRKfIdE2M981AECxNdC+hDeUqGElb xtTA== X-Gm-Message-State: AOAM530ts6Iii6r0MbZsRrxLdp0fT7k8w4Su+CR4MjuDrZtQh5qkS+h+ bIoDnjrq/aXoJj5EeIMK2+w= X-Received: by 2002:a17:90a:4204:: with SMTP id o4mr18366892pjg.199.1628220597080; Thu, 05 Aug 2021 20:29:57 -0700 (PDT) Received: from [10.173.0.66] ([45.135.186.87]) by smtp.gmail.com with ESMTPSA id nr6sm962042pjb.39.2021.08.05.20.29.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 05 Aug 2021 20:29:56 -0700 (PDT) Subject: Re: [BUG] power: supply: 88pm860x_battery: possible uninitialized-variable access in measure_vbatt() To: Sebastian Reichel Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, baijiaju1990@gmail.com, "Jett.Zhou" References: <20210805174908.ctg6n5iwmg5izap3@earth.universe> From: Tuo Li Message-ID: <94bb8568-3f3b-b3af-c98f-9d9bf36528e1@gmail.com> Date: Fri, 6 Aug 2021 11:29:53 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <20210805174908.ctg6n5iwmg5izap3@earth.universe> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thanks for your feedback, and any further feedback about this problem would be appreciated. Best wishes, Tuo Li On 2021/8/6 1:49, Sebastian Reichel wrote: > [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: >> >> In calc_soc(): >> 369:??? int ocv; >> 376:??? switch (state) { >> 380:??? case OCV_MODE_SLEEP: >> 381:??????? ret = measure_vbatt(info, OCV_MODE_SLEEP, &ocv); >> >> In measure_vbatt(struct pm860x_battery_info *info, int state, int *data) >> 176:??? switch (state) { >> 184:??? case OCV_MODE_SLEEP: >> 201:??????? *data = ((*data & 0xff) * 27 * 25) >> 9; >> >> 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. >> >> 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! >> >> Reported-by: TOTE Robot > I suppose the code is suppose to look like this: > > 201:??????? *data = ((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