Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2233398ybd; Mon, 24 Jun 2019 03:02:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqxeM3R/624rLKIH1fHU+7cSidtMo81xKJecOqWTAF/ToYDKBUxTCgFPnyncNvKIRq3tcAnJ X-Received: by 2002:a17:902:61:: with SMTP id 88mr66439020pla.50.1561370524606; Mon, 24 Jun 2019 03:02:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561370524; cv=none; d=google.com; s=arc-20160816; b=weEc8q/pI+dfcbgiY/RHD0Rna/7RqBlEpdVCrj/NjoaNlyxsIV9xUti4tNYcS/JqmW tTu9PEa4Ns5zjevmkC0tEoHN/twgtgXlva/GcOe6rVWmp1iaLC+LrtZyXZoOo21+xNtp Gg9mkc+npsYZKmGkxPX4mCDuhXcWpmJ2eOMzv1ONCpSq9V7ORq9bFLaUCmgdA6v7gbZ4 zVsbff8W/bOakJ6uNcyI0KsStWVdrTVc00zcLtrNAnCKo0FZeu33sYqCFzv/Ui8zkh/7 eSjKxHHof6qpqi0jFtxHF2S6cW7k3jjsVzk/pxxXvWwky0vE7d+Bu/pVI21KkZZasdQK FizQ== 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=ZzzKz4Q9KDHfmcHa39AsLyCvZ53MZ5G2YK8QiMWBDZU=; b=F1646QmQetYiXq0wF8Pb85foKXQ/yN13cWPdEnoy8XKfHzkPRNaQE6mL3bOYALFS1A 1Ghv8gyXrNHvtsoRsCcmSD2VTHlAjM5Ma4A2vZSwd4zi5MjYuh87FCk6MAWU7U/872VI +Uxm7s1v1te90kkMUkkth4w0K1zm/hG9fKWzAVeUdmkiimlBqJph+WYYiRlV3VyeQszt yt3kLuAjPamQR/Eat28ECEQtjXgGmvQHMCy4THmdHYgvqo+C3n7+qsD4Gdmwb6iYTfXD 9vysESd72iSlFE6EEGyCOfOfnMnyNBjgPRRDu5vS8XOrZeafVivYcy4E7Am62313Pz1T 6edA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Val+++lY; 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 f11si10139208pgl.402.2019.06.24.03.01.46; Mon, 24 Jun 2019 03:02:04 -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=Val+++lY; 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 S1729254AbfFXJ7m (ORCPT + 99 others); Mon, 24 Jun 2019 05:59:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:58924 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728513AbfFXJ7k (ORCPT ); Mon, 24 Jun 2019 05:59:40 -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 37B7D208CA; Mon, 24 Jun 2019 09:59:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561370379; bh=sehTHTNS7DM5sY0apoY8R4ulgNuUsVCxPhR1vEBgBcc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Val+++lYx1/ymKl02HF2QvagFShW5U9mKCp1WKqB78Tk6G3ft9tS0HaB/QV/y4PoR KQjgcEpuGBaqSFsLQKBYvwdfemYsy0EWbbblXzfn29ujsFbNKopRf6aMUT8egQnQZS jiLdcXAEUCe1TTmi0ldB9kBTnSdhdGX/JPVMCO2E= 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 4.14 37/51] hwmon: (pmbus/core) Treat parameters as paged if on multiple pages Date: Mon, 24 Jun 2019 17:56:55 +0800 Message-Id: <20190624092310.445377453@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190624092305.919204959@linuxfoundation.org> References: <20190624092305.919204959@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 924f3ca41c65..cb9064ac4977 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -1055,7 +1055,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 */ @@ -1063,7 +1064,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; } @@ -1096,6 +1097,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, @@ -1109,14 +1134,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