Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2246135ybd; Mon, 24 Jun 2019 03:14:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqxgC7qKCrq4P0RcBtzH7cJNMavBjGjFWolzEeuCFPtZ5S9mUTbhNQdRzpS0G7mCcAltXqRi X-Received: by 2002:a17:902:294a:: with SMTP id g68mr150274696plb.169.1561371240797; Mon, 24 Jun 2019 03:14:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561371240; cv=none; d=google.com; s=arc-20160816; b=UWYdnC4UyAmKcmGyr89HQwRCrZTGoqmq6qyVzFQYo+ZtwkYLHrMwj9PxfHIo+1eZWR BUK5UsCYnzbxZtFap/bUn0ZDPJ/Pemw2QMHACHxOLogZgh6FRGHM2T48rWcID3Y11IqW kYAXq++QsrFgsN1AAmCVHzF4FqNdtgccUAOjvr1tEZWV6+GenF/nPjDktwWidbjYMzro /IAQnIXxmYHJXhnSFBKNT97tmoDfx7jgg5hbvUHL62c0S/ouH+t6hUM8xR/oRgpGdsxZ KhE05XtgJ5NDFqpv4uSrXH9jeFh+/g95YO5niQ/W+Nsrh6NLbb19hLArMXYpYz39xXRs m0Bg== 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=zD/XW4fpIU66reekI3DD6gjNsELy559dWCrx8Esv/+ClwhwlvpbunNi9tLNuRseTSG hBPBq688RU2Z1x82eYZK49JlHnoJBgIxzeuTE3spO7NkyKwZUjyFE7/4ORiCQURezOv7 /SJK78U1/zLsizxsVgeJm6CMNuI2QoE0CBjTUH+I90jZqd2SUGgYsLd9g6rqtCBmzqKI aaBFqiWkJXpz/boSZs1W9fqFsZVtGq/Yqa8Wx73G4FwuH9vdgbzjsCCdoSZKx2J6cKOA aeztZzBRdvqbEoW+zptiePFcN3Jhv/T2utAkCtdIH3MB+0AV5Rgog5yZXX1QnV8dHHCm SisA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=m41bpsCG; 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 s34si10761544pjc.2.2019.06.24.03.13.44; Mon, 24 Jun 2019 03:14:00 -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=m41bpsCG; 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 S1730317AbfFXKM4 (ORCPT + 99 others); Mon, 24 Jun 2019 06:12:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:37198 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729883AbfFXKFR (ORCPT ); Mon, 24 Jun 2019 06:05:17 -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 A566320848; Mon, 24 Jun 2019 10:05:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561370717; bh=R3kte9HSML48BOOzKcfTRnplU35ZZNXwoKZwq5oQrNY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m41bpsCGSzLRweQaWlyXb4wTqvASBMy5dXgpv82V2a8Odr+btEXboScDNyQ4iOyE1 HPKHFRHaqC3SrJlLBx0ipqEE87z7xKOkQaoVY3LIG4dU7oQIOoliu0hZc6b5+Ir94J YOknodn/n4cOJ1+Iy53Q5WhEAGRX1kf8lOIaVFRQ= 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.19 65/90] hwmon: (pmbus/core) Treat parameters as paged if on multiple pages Date: Mon, 24 Jun 2019 17:56:55 +0800 Message-Id: <20190624092318.341639755@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190624092313.788773607@linuxfoundation.org> References: <20190624092313.788773607@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