From patchwork Wed Oct 24 02:36:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 10654099 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 19A0613B5 for ; Wed, 24 Oct 2018 03:08:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EFC052A2D9 for ; Wed, 24 Oct 2018 03:08:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E10782A2E3; Wed, 24 Oct 2018 03:08:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E6172A2D9 for ; Wed, 24 Oct 2018 03:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725896AbeJXLeT (ORCPT ); Wed, 24 Oct 2018 07:34:19 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:36042 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725826AbeJXLeT (ORCPT ); Wed, 24 Oct 2018 07:34:19 -0400 Received: by mail-pg1-f195.google.com with SMTP id l6-v6so1625578pgp.3; Tue, 23 Oct 2018 20:08:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nsuYjcR1EiPlDCJ6JViUW3dlgy89BBd7N5H87xE87CE=; b=ubkKuQU2ptxlXeSTDT848h8n7RDmXT9J0x8RR9wqe7y571qSuE/IrY6xfBi1ybOTGt syDTlQNrvioVDWgJvJbUFFvUhn/4iYxyB+X07ZVK5rFdlv4Dpnu95nSQUXOzJIDSe+h8 zyy4EsSJzhYPX+veKAOnQ+UmQaxAzAXTVF84pk1tP5VBri9zORekoj5SKQtYf0GQpvcI eEEDcjVTVSdj3iaEgEKhuwB1P/E4CJrWEjTew89zxZa70R/gsPoP+l330fuIuOXAx2+j R84QnEMG/Ko50qNOPIEWRaSiO2E/NKe6AZSbHMrziZpA+rBfYGBgqc6nxVEwOUhgmE6q 4aVw== 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:in-reply-to :references; bh=nsuYjcR1EiPlDCJ6JViUW3dlgy89BBd7N5H87xE87CE=; b=S0u2SZOzgnrAvXb1fReMptKeaKAvH9bEbMNHoM9+mjnfjWVf8GCrOz9xVLA371C+sy uU/As1UvwpU8BwNcm+hTGxyBc1DRN5xSkd+763uyfpPkYoucDMK2UcETd5/aRYcpRozT iqSMOPPOQg/5okamZzGtAcwUuBwLBp5hnGr/2a6SHIpHJVKXoHpE7bDath09vPmX0QmC o6hdIuaundhQmZ/T8tjtGKz/LoU3cGetcrnvG8BykY0S3ql6/D+Mp4XN/f28J4exxs/V hRpni2W0vTErvq2al0+xNeiWNRygS8vYziA/upXqdyXxN4MSY9sOhlTkrkmvxHGlDSRZ L7sw== X-Gm-Message-State: AGRZ1gJhRZxZFSkYeePw4NC2V2i7li/4Y0cZqGwl5gaBLA/ybaK/G9Io pMuTQauj0LNdPT2Jv6Pf9g/c5opf X-Google-Smtp-Source: AJdET5cc0i8uCrPezrM5rd+Nk5MIEcEXua+GqjevguZVp7wx+xPrnyGvuIm7JgiMv+2A8Cl0djEUnQ== X-Received: by 2002:a65:4981:: with SMTP id r1-v6mr771496pgs.153.1540348590701; Tue, 23 Oct 2018 19:36:30 -0700 (PDT) Received: from Asurada-Nvidia.nvidia.com (thunderhill.nvidia.com. [216.228.112.22]) by smtp.gmail.com with ESMTPSA id n17-v6sm3606625pfj.84.2018.10.23.19.36.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Oct 2018 19:36:30 -0700 (PDT) From: Nicolin Chen To: jdelvare@suse.com, linux@roeck-us.net Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/5] hwmon: (ina3221) Check channel status for alarms attribute read Date: Tue, 23 Oct 2018 19:36:20 -0700 Message-Id: <20181024023623.4231-3-nicoleotsuka@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181024023623.4231-1-nicoleotsuka@gmail.com> References: <20181024023623.4231-1-nicoleotsuka@gmail.com> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There is nothing critically wrong to read these two attributes without having a is_enabled() check at this point. But reading the MASK_ENABLE register would clear the CVRF bit according to the datasheet. So it'd be safer to fence for disabled channels in order to add pm runtime feature. Signed-off-by: Nicolin Chen --- Changelog v1->v2: * Returned 0 for alert flags instead of -ENODATA drivers/hwmon/ina3221.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c index d61688f04594..26cdf3342d80 100644 --- a/drivers/hwmon/ina3221.c +++ b/drivers/hwmon/ina3221.c @@ -200,6 +200,12 @@ static int ina3221_read_curr(struct device *dev, u32 attr, return 0; case hwmon_curr_crit_alarm: case hwmon_curr_max_alarm: + /* No actual register read if channel is disabled */ + if (!ina3221_is_enabled(ina, channel)) { + /* Return 0 for alert flags */ + *val = 0; + return 0; + } ret = regmap_field_read(ina->fields[reg], ®val); if (ret) return ret;