Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2249169ybd; Mon, 24 Jun 2019 03:17:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqxs3kgDIojLfZREZAoORlBk/PLv9IZ0TTgl3TTwfyZ8eXDDWOh/onLIXxWtfOt2cJUSPjAS X-Received: by 2002:a17:90a:2525:: with SMTP id j34mr24580906pje.11.1561371426978; Mon, 24 Jun 2019 03:17:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561371426; cv=none; d=google.com; s=arc-20160816; b=QvLEwEzVkA2O7D5NHBR58uqFA2EmejPET0PyBKKep3KMphL7fs4aLUkFSGJe1tlrUj m2b6kBOBJTz82ePej1NanGDRmLb7r+u3YJd3CMJMbZT3jKgNMJ+i7bH+oz9xk/CDBTWc Lp86oA1ly+0kz6GyTqqpp69AyMtzuvCSqy4E1wiQVFxVNLOjdjVzWBKfbqvy1LI0q9fX pPPTzr2FXEcjE9MSd/yP6WyR6PUl3pcxBzsGTa310YK/uo8fC0e6ylG/Aln+efpLemTR PGzdAJPx2EHJ7yyh2v5Ov7//qvKFd/JFvRME6YfiI5UXHjY4zAWA+xVz4Qm4clzlNmkb 1jrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=AdK2scuyV1T/djM+DN1UDUqc6pnDhQ2SUSJ5Lnmby2o=; b=HtZxJsB1IcM512RfmWaKYONWJJEvc9ba9KkrncWjimNeHQ527Vs53y3iei6Kq2Niq3 Kt8gIhF8YR5RxL3PeoddZ6VSQaAlkQ/kkQoO4tmvvuQcoJLFE0ElRxI/qXnAaSF31lKv aRT+ZS3PBALVvquImXX5siix6UPa7En2nvQUmhrqpMPFmPBg0xQSLoPKqoSdyNkwtcVq Wdbk0FTJDz29VDOsRMrHXqH4+UgBJfOG9yx9p8wLC36IEY57amPVPw59Kl6ZVRp3tAR2 Eo6RVJq01KdoZ0wCKSR40r5dT+ycImAzIv5uOwRfAOWzGzas5jWE9a8eHFhkhtA8dKsW pqsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SDoljyoU; 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 h125si10416040pfb.176.2019.06.24.03.16.51; Mon, 24 Jun 2019 03:17:06 -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=pass header.i=@kernel.org header.s=default header.b=SDoljyoU; 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 S1729156AbfFXKQc (ORCPT + 99 others); Mon, 24 Jun 2019 06:16:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:54012 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730745AbfFXKQa (ORCPT ); Mon, 24 Jun 2019 06:16:30 -0400 Received: from localhost (f4.8f.5177.ip4.static.sl-reverse.com [119.81.143.244]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6A25B205ED; Mon, 24 Jun 2019 10:16:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561371389; bh=R3kte9HSML48BOOzKcfTRnplU35ZZNXwoKZwq5oQrNY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SDoljyoUSr9fk5S89fSIpDA/BYr/C2njJtJ+BdKMQ0+L5NIp9uI/ptNkocCBXH1bV dX2HEb4PQSWiccUHmiqxbYGLB0rLiio/7xSBJe4aatGgqompAxX+yOyA6Iyo2pGDCs dL0Jwdmx7F9fosNmuOnI9ZVCiOr8HeAcE5bF16jU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Robert Hancock , Guenter Roeck , Sasha Levin Subject: [PATCH 5.1 086/121] hwmon: (pmbus/core) Treat parameters as paged if on multiple pages Date: Mon, 24 Jun 2019 17:56:58 +0800 Message-Id: <20190624092325.227711362@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190624092320.652599624@linuxfoundation.org> References: <20190624092320.652599624@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 4a60570dce658e3f8885bbcf852430b99f65aca5 ] Some chips have attributes which exist on more than one page but the attribute is not presently marked as paged. This causes the attributes to be generated with the same label, which makes it impossible for userspace to tell them apart. Marking all such attributes as paged would result in the page suffix being added regardless of whether they were present on more than one page or not, which might break existing setups. Therefore, we add a second check which treats the attribute as paged, even if not marked as such, if it is present on multiple pages. Fixes: b4ce237b7f7d ("hwmon: (pmbus) Introduce infrastructure to detect sensors and limit registers") Signed-off-by: Robert Hancock Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin --- drivers/hwmon/pmbus/pmbus_core.c | 34 ++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index 2e2b5851139c..cd24b375df1e 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -1230,7 +1230,8 @@ static int pmbus_add_sensor_attrs_one(struct i2c_client *client, const struct pmbus_driver_info *info, const char *name, int index, int page, - const struct pmbus_sensor_attr *attr) + const struct pmbus_sensor_attr *attr, + bool paged) { struct pmbus_sensor *base; bool upper = !!(attr->gbit & 0xff00); /* need to check STATUS_WORD */ @@ -1238,7 +1239,7 @@ static int pmbus_add_sensor_attrs_one(struct i2c_client *client, if (attr->label) { ret = pmbus_add_label(data, name, index, attr->label, - attr->paged ? page + 1 : 0); + paged ? page + 1 : 0); if (ret) return ret; } @@ -1271,6 +1272,30 @@ static int pmbus_add_sensor_attrs_one(struct i2c_client *client, return 0; } +static bool pmbus_sensor_is_paged(const struct pmbus_driver_info *info, + const struct pmbus_sensor_attr *attr) +{ + int p; + + if (attr->paged) + return true; + + /* + * Some attributes may be present on more than one page despite + * not being marked with the paged attribute. If that is the case, + * then treat the sensor as being paged and add the page suffix to the + * attribute name. + * We don't just add the paged attribute to all such attributes, in + * order to maintain the un-suffixed labels in the case where the + * attribute is only on page 0. + */ + for (p = 1; p < info->pages; p++) { + if (info->func[p] & attr->func) + return true; + } + return false; +} + static int pmbus_add_sensor_attrs(struct i2c_client *client, struct pmbus_data *data, const char *name, @@ -1284,14 +1309,15 @@ static int pmbus_add_sensor_attrs(struct i2c_client *client, index = 1; for (i = 0; i < nattrs; i++) { int page, pages; + bool paged = pmbus_sensor_is_paged(info, attrs); - pages = attrs->paged ? info->pages : 1; + pages = paged ? info->pages : 1; for (page = 0; page < pages; page++) { if (!(info->func[page] & attrs->func)) continue; ret = pmbus_add_sensor_attrs_one(client, data, info, name, index, page, - attrs); + attrs, paged); if (ret) return ret; index++; -- 2.20.1