Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp104397ybp; Thu, 3 Oct 2019 10:49:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqxvQuAn1znEiVOnlfNFnJBvMNN0RzgXgILa6yvEiR+qlE3K2fsI4bXAYJ/TGJi8GkrwmffU X-Received: by 2002:a17:906:d154:: with SMTP id br20mr8942637ejb.79.1570124971836; Thu, 03 Oct 2019 10:49:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570124971; cv=none; d=google.com; s=arc-20160816; b=wBeMGMmNwsl6pvLajPibuOPNNiG7ZdZL6GjPxR42lWJqIn8qfZwZxgrzMeuBBaRwVM 7xQYcNLCyuaE6SuhJAJ0Y9Uq0c2fn2NyH1hSCgNwyJ1s/LDcsEO++2PdIkAow/USFCo0 DFD3VHLuFblz04FCzM0qeZCXdfrUimL3Uj9Kzi/PQdqhd8dC/mnER+uEVHgqa7HTP+yE qzPe5BpsQOCR5isV43ttz+5BuEGRLWZukqzgWWVBkW3K6uTXGL53ggFT4ldlKk7DpJIe r56BwIRtDTEHntNx0ngq5PfeCVpS8B0kNf0AKJXeH5THW/HJxb9qSfEH4Bp9OvR8vhzF +8sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:message-id:date:subject:cc:from :ironport-phdr:ironport-sdr:dkim-signature; bh=7xuYVaL6kMkVdyoXuZH4xe6VghxajLsnhwu8EUF2ekg=; b=lIJrZQLFujen4lmYvfyi3WCNp2QBMrgtmutIlF/drIA8MH3/kuF9Z6nxGJQOHneY/y uhhiEwRsrbKD2ciLkS+EUg3KFk2YxpDQiUa738Rl5+tgLcCaIwtVrON7XHyQ9LlLPB24 ybXIBp50T3I6aJ6hSTjUU6zzPEC/H5jWQ//UbrMZg6yQe0N1Bxt3g3tffehHm9WfgaY8 jFLWAb9VkeI2Ktw/SMCFMQgVAT6T6H9Wd8e6L5ErZ4AsfMZBy5odAJpVqyuvOk7WfGmh hAzJcyXCInzqbjVyMnPXovbQB1zuGO9iRatxqvSN1anIKn/QCz9O76DrEcVWOclihLHt fXYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@ucr.edu header.s=selector3 header.b=AHQhjqzN; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ucr.edu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i10si2110733ede.101.2019.10.03.10.49.07; Thu, 03 Oct 2019 10:49:31 -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=@ucr.edu header.s=selector3 header.b=AHQhjqzN; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ucr.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730429AbfJCR3J (ORCPT + 99 others); Thu, 3 Oct 2019 13:29:09 -0400 Received: from mx4.ucr.edu ([138.23.248.66]:38989 "EHLO mx4.ucr.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729235AbfJCR3H (ORCPT ); Thu, 3 Oct 2019 13:29:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=ucr.edu; i=@ucr.edu; q=dns/txt; s=selector3; t=1570123745; x=1601659745; h=from:to:cc:subject:date:message-id; bh=Mr/HQci3u3rRGYq/s4Glr5VxHGEGmVqkkQJmECKmcB4=; b=AHQhjqzNc2UfyZ+3qMvQ+o4JhiYWCMHZ22bWMQAPB/yT4qS/kRwkPBkz Iaaxy9AguSgN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F+db7Zcd8DWG?= =?us-ascii?q?ZNQtpdWylHD4O5bosPFPEBPeder4nyulAAswKwDhSiBOPu1DBIgmL51rA+3+?= =?us-ascii?q?kvDQ3K2QotFM8MvnvJttX4LKccX/6owqfGzjvNaOhb1Svh5IXSbhwsu+2AUa?= =?us-ascii?q?52fMHMyUcvDQTFjlCIpIPnPjOU1+QNs3Wc7+F9Uu+ui28mqwFrrTiu2ssglo?= =?us-ascii?q?fEi5kIyl/Y7yV12pg6KsClSENiZ9OvDZhetzmCOodoXs8vR3tktSU6x7Ecp5?= =?us-ascii?q?K3YScHxI45yxLDd/CLa5WE7xPnWeqLPzt1inJodKihixuz60StyOLxW8+p21?= =?us-ascii?q?hQtCVFiMPDtnUV2hzW7ciIV+Vy81+62TaKywDT8uZEIV0olabDK54u3Lowlp?= =?us-ascii?q?0LvETGBCD2mUH2gLaOdkUg5+Sk8urnbqv6qpOALYN0hQb+MqMhmsy7H+s0KB?= =?us-ascii?q?QBX2+e+eik1b3j+1P2QKlSg/EojqXUtIrWKMcbq6KjHQNZz4ku5wyhAzu6zN?= =?us-ascii?q?gUhXwHI0hEeBKDgYjpIVbOIPXgAPa/glWskC1kx/HaMrH9DJjANWXDn6v7fb?= =?us-ascii?q?pn9UFT1RczwchF551IErEBPO7zWkjpudzcDx85NRG0wun+BNV+yIweQ2SPDb?= =?us-ascii?q?GdMK7Jr1+I6fwgI/OWaI8Wpjn9Mf4l6ODqjXMjnl8dZ6apjtM5cne9S8VnMU?= =?us-ascii?q?WEZjK4k8UBGGZS5lEWUefwzlCOTGgAND6JQ6sg62RjW8qdBoDZS9Xo3+SM?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A2HdCgAaL5Zdh8jWVdFlHgEGEoFcCwK?= =?us-ascii?q?DXEwQjSSGLAEBBosmgQmFeoMLhSiBewEIAQEBDAEBLQIBAYRAgkgjNQgOAgM?= =?us-ascii?q?JAQEFAQEBAQEFBAEBAhABAQEIDQkIKYVAQgEMAYFqKYM1CxYVUoEVAQUBNSI?= =?us-ascii?q?5gkcBgXYUBaIkgQM8jCUziGYBCQ2BSAkBCIEiAYc0hFmBEIEHhGGEKIM9gkQ?= =?us-ascii?q?EgTcBAQGLPQeJZ3CVYgEGAoIRFIF4kxQnhDyJP4tEAS2MEpsdAgoHBg8jgTA?= =?us-ascii?q?BghBNJYFsCoFEUBAUgVsOCRWOLiEzgQiCc41iAQ?= X-IPAS-Result: =?us-ascii?q?A2HdCgAaL5Zdh8jWVdFlHgEGEoFcCwKDXEwQjSSGLAEBB?= =?us-ascii?q?osmgQmFeoMLhSiBewEIAQEBDAEBLQIBAYRAgkgjNQgOAgMJAQEFAQEBAQEFB?= =?us-ascii?q?AEBAhABAQEIDQkIKYVAQgEMAYFqKYM1CxYVUoEVAQUBNSI5gkcBgXYUBaIkg?= =?us-ascii?q?QM8jCUziGYBCQ2BSAkBCIEiAYc0hFmBEIEHhGGEKIM9gkQEgTcBAQGLPQeJZ?= =?us-ascii?q?3CVYgEGAoIRFIF4kxQnhDyJP4tEAS2MEpsdAgoHBg8jgTABghBNJYFsCoFEU?= =?us-ascii?q?BAUgVsOCRWOLiEzgQiCc41iAQ?= X-IronPort-AV: E=Sophos;i="5.67,253,1566889200"; d="scan'208";a="80465613" Received: from mail-pl1-f200.google.com ([209.85.214.200]) by smtpmx4.ucr.edu with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 03 Oct 2019 10:29:03 -0700 Received: by mail-pl1-f200.google.com with SMTP id f8so2169228plj.10 for ; Thu, 03 Oct 2019 10:29:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=7xuYVaL6kMkVdyoXuZH4xe6VghxajLsnhwu8EUF2ekg=; b=g3fXJ7mHA78bTmyoi4z/IIoTj4FmcHL2235+LeWeNz9oySobqrZCKoDytP+3z+IVsy TMaAA86Dw1F1zirzTSZ7c7Ta8fMrhsEQoUeJGNWF8LyjxoQhHenbjxP1BjYwYiDyOOBm 7bVMSjscO7R1QQhwVb+eFq4BkKu1yMqG/fh2sjM1k81J1Nidq9TY5RVX/V0dmwTgsYTy tZxBwLsmdU605HGgv2RhOygpcraM1QsG0H3u0MSSHTvNqO01zgWBO5H3FZiE/RwEjjKD FEs7341kGNVCSUqP78fjNsLpMvUPmROAf/QrXpkAXCVRWU3pyG/rBSuaI2YZs7/IA5NU L/Dw== X-Gm-Message-State: APjAAAVSau8Q9GuL+TeRRSYMW841Wiqmtzxw5Ath7bhutHPM0zUUtNM+ 7P0jaHuxIGlMJ8EyhPqmm3AqCYaE75HuZaSzhI9eSLxUE7k9Hv1pykP73FlKOAdnz+SmWL3PlfK qczJZFmnkfH3ubnJPzGkGmB1u+w== X-Received: by 2002:a17:902:82cb:: with SMTP id u11mr10426926plz.313.1570123743271; Thu, 03 Oct 2019 10:29:03 -0700 (PDT) X-Received: by 2002:a17:902:82cb:: with SMTP id u11mr10426899plz.313.1570123742854; Thu, 03 Oct 2019 10:29:02 -0700 (PDT) Received: from Yizhuo.cs.ucr.edu (yizhuo.cs.ucr.edu. [169.235.26.74]) by smtp.googlemail.com with ESMTPSA id c62sm4638873pfa.92.2019.10.03.10.29.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2019 10:29:01 -0700 (PDT) From: Yizhuo Cc: csong@cs.ucr.edu, zhiyunq@cs.ucr.edu, Yizhuo , Sebastian Reichel , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] power: supply: max17042_battery: fix some usage of uninitialized variables Date: Thu, 3 Oct 2019 10:29:48 -0700 Message-Id: <20191003172948.15834-1-yzhai003@ucr.edu> X-Mailer: git-send-email 2.17.1 To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Several functions in this file are trying to use regmap_read() to initialize the specific variable, however, if regmap_read() fails, the variable could be uninitialized but used directly, which is potentially unsafe. The return value of regmap_read() should be checked and handled. The same case also happens in function max17042_thread_handler() but it needs more effort to patch. Signed-off-by: Yizhuo --- drivers/power/supply/max17042_battery.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c index e6a2dacaa730..b897776a2749 100644 --- a/drivers/power/supply/max17042_battery.c +++ b/drivers/power/supply/max17042_battery.c @@ -675,8 +675,12 @@ static void max17042_reset_vfsoc0_reg(struct max17042_chip *chip) { unsigned int vfSoc; struct regmap *map = chip->regmap; + int ret; + + ret = regmap_read(map, MAX17042_VFSOC, &vfSoc); + if (ret) + return; - regmap_read(map, MAX17042_VFSOC, &vfSoc); regmap_write(map, MAX17042_VFSOC0Enable, VFSOC0_UNLOCK); max17042_write_verify_reg(map, MAX17042_VFSOC0, vfSoc); regmap_write(map, MAX17042_VFSOC0Enable, VFSOC0_LOCK); @@ -686,12 +690,18 @@ static void max17042_load_new_capacity_params(struct max17042_chip *chip) { u32 full_cap0, rep_cap, dq_acc, vfSoc; u32 rem_cap; + int ret; struct max17042_config_data *config = chip->pdata->config_data; struct regmap *map = chip->regmap; - regmap_read(map, MAX17042_FullCAP0, &full_cap0); - regmap_read(map, MAX17042_VFSOC, &vfSoc); + ret = regmap_read(map, MAX17042_FullCAP0, &full_cap0); + if (ret) + return; + + ret = regmap_read(map, MAX17042_VFSOC, &vfSoc); + if (ret) + return; /* fg_vfSoc needs to shifted by 8 bits to get the * perc in 1% accuracy, to get the right rem_cap multiply @@ -1108,7 +1118,12 @@ static int max17042_probe(struct i2c_client *client, if (!client->irq) regmap_write(chip->regmap, MAX17042_SALRT_Th, 0xff00); - regmap_read(chip->regmap, MAX17042_STATUS, &val); + ret = regmap_read(chip->regmap, MAX17042_STATUS, &val); + if (ret) { + dev_err(&client->dev, "Failed to get MAX17042_STATUS.\n"); + return ret; + } + if (val & STATUS_POR_BIT) { INIT_WORK(&chip->work, max17042_init_worker); ret = devm_add_action(&client->dev, max17042_stop_work, chip); -- 2.17.1