All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Len Brown <len.brown@intel.com>, Pavel Machek <pavel@ucw.cz>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Stephen Boyd <sboyd@codeaurora.org>,
	Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>,
	Nishanth Menon <nm@ti.com>, Dmitry Torokhov <dtor@chromium.org>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: [PATCH] PM / OPP: fix debugfs files for 64-bit
Date: Wed, 07 Oct 2015 09:35:41 +0200	[thread overview]
Message-ID: <5706174.BUsqiXljxZ@wuerfel> (raw)

The recently added debugfs support for OPP creates files using the
debugfs_create_bool() and debugfs_create_u32() interfaces, but
casts the data argument to u32*, which is broken on some architectures.

In case of debugfs_create_bool(), the API has changed as of 621a5f7ad9cd
("debugfs: Pass bool pointer to debugfs_create_bool()"), so we now get
a warning about the new interface in linux-next, which contains both
patches. Removing the cast makes it work in linux-next, and makes it
warn in cases where it does not work.

For debugfs_create_u32(), the current usage is broken on 64-bit
architectures when the values exceed the range of 32-bit variables
(which should not happen), or when the kernel is built for as
big-endian. This patch removes the casts and changes the types
to u32 to make them match and print the correct value on all
architectures.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: 5cb5fdbf38770 ("PM / OPP: Add debugfs support")
---
Found while building ARM allmodconfig

diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c
index 25f3efef24db..1cbc0acf831a 100644
--- a/drivers/base/power/opp/core.c
+++ b/drivers/base/power/opp/core.c
@@ -696,7 +696,7 @@ static int _opp_add(struct device *dev, struct dev_pm_opp *new_opp,
 			break;
 
 		/* Duplicate OPPs */
-		dev_warn(dev, "%s: duplicate OPPs detected. Existing: freq: %lu, volt: %lu, enabled: %d. New: freq: %lu, volt: %lu, enabled: %d\n",
+		dev_warn(dev, "%s: duplicate OPPs detected. Existing: freq: %u, volt: %u, enabled: %d. New: freq: %u, volt: %u, enabled: %d\n",
 			 __func__, opp->rate, opp->u_volt, opp->available,
 			 new_opp->rate, new_opp->u_volt, new_opp->available);
 
@@ -898,7 +898,7 @@ static int _opp_add_static_v2(struct device *dev, struct device_node *np)
 	/* OPP to select on device suspend */
 	if (of_property_read_bool(np, "opp-suspend")) {
 		if (dev_opp->suspend_opp)
-			dev_warn(dev, "%s: Multiple suspend OPPs found (%lu %lu)\n",
+			dev_warn(dev, "%s: Multiple suspend OPPs found (%u %u)\n",
 				 __func__, dev_opp->suspend_opp->rate,
 				 new_opp->rate);
 		else
@@ -910,7 +910,7 @@ static int _opp_add_static_v2(struct device *dev, struct device_node *np)
 
 	mutex_unlock(&dev_opp_list_lock);
 
-	pr_debug("%s: turbo:%d rate:%lu uv:%lu uvmin:%lu uvmax:%lu latency:%lu\n",
+	pr_debug("%s: turbo:%d rate:%u uv:%u uvmin:%u uvmax:%u latency:%u\n",
 		 __func__, new_opp->turbo, new_opp->rate, new_opp->u_volt,
 		 new_opp->u_volt_min, new_opp->u_volt_max,
 		 new_opp->clock_latency_ns);
diff --git a/drivers/base/power/opp/debugfs.c b/drivers/base/power/opp/debugfs.c
index 865cbfa24640..45436dabae8d 100644
--- a/drivers/base/power/opp/debugfs.c
+++ b/drivers/base/power/opp/debugfs.c
@@ -38,43 +38,42 @@ int opp_debug_create_one(struct dev_pm_opp *opp, struct device_opp *dev_opp)
 	char name[15];
 
 	/* Rate is unique to each OPP, use it to give opp-name */
-	sprintf(name, "opp:%lu", opp->rate);
+	sprintf(name, "opp:%u", opp->rate);
 
 	/* Create per-opp directory */
 	d = debugfs_create_dir(name, pdentry);
 	if (!d)
 		return -ENOMEM;
 
-	if (!debugfs_create_bool("available", S_IRUGO, d,
-				 (u32 *)&opp->available))
+	if (!debugfs_create_bool("available", S_IRUGO, d, &opp->available))
 		return -ENOMEM;
 
-	if (!debugfs_create_bool("dynamic", S_IRUGO, d, (u32 *)&opp->dynamic))
+	if (!debugfs_create_bool("dynamic", S_IRUGO, d, &opp->dynamic))
 		return -ENOMEM;
 
-	if (!debugfs_create_bool("turbo", S_IRUGO, d, (u32 *)&opp->turbo))
+	if (!debugfs_create_bool("turbo", S_IRUGO, d, &opp->turbo))
 		return -ENOMEM;
 
-	if (!debugfs_create_u32("rate_hz", S_IRUGO, d, (u32 *)&opp->rate))
+	if (!debugfs_create_u32("rate_hz", S_IRUGO, d, &opp->rate))
 		return -ENOMEM;
 
 	if (!debugfs_create_u32("u_volt_target", S_IRUGO, d,
-				(u32 *)&opp->u_volt))
+				&opp->u_volt))
 		return -ENOMEM;
 
 	if (!debugfs_create_u32("u_volt_min", S_IRUGO, d,
-				(u32 *)&opp->u_volt_min))
+				&opp->u_volt_min))
 		return -ENOMEM;
 
 	if (!debugfs_create_u32("u_volt_max", S_IRUGO, d,
-				(u32 *)&opp->u_volt_max))
+				&opp->u_volt_max))
 		return -ENOMEM;
 
-	if (!debugfs_create_u32("u_amp", S_IRUGO, d, (u32 *)&opp->u_amp))
+	if (!debugfs_create_u32("u_amp", S_IRUGO, d, &opp->u_amp))
 		return -ENOMEM;
 
 	if (!debugfs_create_u32("clock_latency_ns", S_IRUGO, d,
-				(u32 *)&opp->clock_latency_ns))
+				&opp->clock_latency_ns))
 		return -ENOMEM;
 
 	opp->dentry = d;
diff --git a/drivers/base/power/opp/opp.h b/drivers/base/power/opp/opp.h
index 0e4c27fb0c4a..ef573e650773 100644
--- a/drivers/base/power/opp/opp.h
+++ b/drivers/base/power/opp/opp.h
@@ -71,13 +71,13 @@ struct dev_pm_opp {
 	bool available;
 	bool dynamic;
 	bool turbo;
-	unsigned long rate;
+	u32 rate;
 
-	unsigned long u_volt;
-	unsigned long u_volt_min;
-	unsigned long u_volt_max;
-	unsigned long u_amp;
-	unsigned long clock_latency_ns;
+	u32 u_volt;
+	u32 u_volt_min;
+	u32 u_volt_max;
+	u32 u_amp;
+	u32 clock_latency_ns;
 
 	struct device_opp *dev_opp;
 	struct rcu_head rcu_head;


WARNING: multiple messages have this Message-ID (diff)
From: arnd@arndb.de (Arnd Bergmann)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] PM / OPP: fix debugfs files for 64-bit
Date: Wed, 07 Oct 2015 09:35:41 +0200	[thread overview]
Message-ID: <5706174.BUsqiXljxZ@wuerfel> (raw)

The recently added debugfs support for OPP creates files using the
debugfs_create_bool() and debugfs_create_u32() interfaces, but
casts the data argument to u32*, which is broken on some architectures.

In case of debugfs_create_bool(), the API has changed as of 621a5f7ad9cd
("debugfs: Pass bool pointer to debugfs_create_bool()"), so we now get
a warning about the new interface in linux-next, which contains both
patches. Removing the cast makes it work in linux-next, and makes it
warn in cases where it does not work.

For debugfs_create_u32(), the current usage is broken on 64-bit
architectures when the values exceed the range of 32-bit variables
(which should not happen), or when the kernel is built for as
big-endian. This patch removes the casts and changes the types
to u32 to make them match and print the correct value on all
architectures.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: 5cb5fdbf38770 ("PM / OPP: Add debugfs support")
---
Found while building ARM allmodconfig

diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c
index 25f3efef24db..1cbc0acf831a 100644
--- a/drivers/base/power/opp/core.c
+++ b/drivers/base/power/opp/core.c
@@ -696,7 +696,7 @@ static int _opp_add(struct device *dev, struct dev_pm_opp *new_opp,
 			break;
 
 		/* Duplicate OPPs */
-		dev_warn(dev, "%s: duplicate OPPs detected. Existing: freq: %lu, volt: %lu, enabled: %d. New: freq: %lu, volt: %lu, enabled: %d\n",
+		dev_warn(dev, "%s: duplicate OPPs detected. Existing: freq: %u, volt: %u, enabled: %d. New: freq: %u, volt: %u, enabled: %d\n",
 			 __func__, opp->rate, opp->u_volt, opp->available,
 			 new_opp->rate, new_opp->u_volt, new_opp->available);
 
@@ -898,7 +898,7 @@ static int _opp_add_static_v2(struct device *dev, struct device_node *np)
 	/* OPP to select on device suspend */
 	if (of_property_read_bool(np, "opp-suspend")) {
 		if (dev_opp->suspend_opp)
-			dev_warn(dev, "%s: Multiple suspend OPPs found (%lu %lu)\n",
+			dev_warn(dev, "%s: Multiple suspend OPPs found (%u %u)\n",
 				 __func__, dev_opp->suspend_opp->rate,
 				 new_opp->rate);
 		else
@@ -910,7 +910,7 @@ static int _opp_add_static_v2(struct device *dev, struct device_node *np)
 
 	mutex_unlock(&dev_opp_list_lock);
 
-	pr_debug("%s: turbo:%d rate:%lu uv:%lu uvmin:%lu uvmax:%lu latency:%lu\n",
+	pr_debug("%s: turbo:%d rate:%u uv:%u uvmin:%u uvmax:%u latency:%u\n",
 		 __func__, new_opp->turbo, new_opp->rate, new_opp->u_volt,
 		 new_opp->u_volt_min, new_opp->u_volt_max,
 		 new_opp->clock_latency_ns);
diff --git a/drivers/base/power/opp/debugfs.c b/drivers/base/power/opp/debugfs.c
index 865cbfa24640..45436dabae8d 100644
--- a/drivers/base/power/opp/debugfs.c
+++ b/drivers/base/power/opp/debugfs.c
@@ -38,43 +38,42 @@ int opp_debug_create_one(struct dev_pm_opp *opp, struct device_opp *dev_opp)
 	char name[15];
 
 	/* Rate is unique to each OPP, use it to give opp-name */
-	sprintf(name, "opp:%lu", opp->rate);
+	sprintf(name, "opp:%u", opp->rate);
 
 	/* Create per-opp directory */
 	d = debugfs_create_dir(name, pdentry);
 	if (!d)
 		return -ENOMEM;
 
-	if (!debugfs_create_bool("available", S_IRUGO, d,
-				 (u32 *)&opp->available))
+	if (!debugfs_create_bool("available", S_IRUGO, d, &opp->available))
 		return -ENOMEM;
 
-	if (!debugfs_create_bool("dynamic", S_IRUGO, d, (u32 *)&opp->dynamic))
+	if (!debugfs_create_bool("dynamic", S_IRUGO, d, &opp->dynamic))
 		return -ENOMEM;
 
-	if (!debugfs_create_bool("turbo", S_IRUGO, d, (u32 *)&opp->turbo))
+	if (!debugfs_create_bool("turbo", S_IRUGO, d, &opp->turbo))
 		return -ENOMEM;
 
-	if (!debugfs_create_u32("rate_hz", S_IRUGO, d, (u32 *)&opp->rate))
+	if (!debugfs_create_u32("rate_hz", S_IRUGO, d, &opp->rate))
 		return -ENOMEM;
 
 	if (!debugfs_create_u32("u_volt_target", S_IRUGO, d,
-				(u32 *)&opp->u_volt))
+				&opp->u_volt))
 		return -ENOMEM;
 
 	if (!debugfs_create_u32("u_volt_min", S_IRUGO, d,
-				(u32 *)&opp->u_volt_min))
+				&opp->u_volt_min))
 		return -ENOMEM;
 
 	if (!debugfs_create_u32("u_volt_max", S_IRUGO, d,
-				(u32 *)&opp->u_volt_max))
+				&opp->u_volt_max))
 		return -ENOMEM;
 
-	if (!debugfs_create_u32("u_amp", S_IRUGO, d, (u32 *)&opp->u_amp))
+	if (!debugfs_create_u32("u_amp", S_IRUGO, d, &opp->u_amp))
 		return -ENOMEM;
 
 	if (!debugfs_create_u32("clock_latency_ns", S_IRUGO, d,
-				(u32 *)&opp->clock_latency_ns))
+				&opp->clock_latency_ns))
 		return -ENOMEM;
 
 	opp->dentry = d;
diff --git a/drivers/base/power/opp/opp.h b/drivers/base/power/opp/opp.h
index 0e4c27fb0c4a..ef573e650773 100644
--- a/drivers/base/power/opp/opp.h
+++ b/drivers/base/power/opp/opp.h
@@ -71,13 +71,13 @@ struct dev_pm_opp {
 	bool available;
 	bool dynamic;
 	bool turbo;
-	unsigned long rate;
+	u32 rate;
 
-	unsigned long u_volt;
-	unsigned long u_volt_min;
-	unsigned long u_volt_max;
-	unsigned long u_amp;
-	unsigned long clock_latency_ns;
+	u32 u_volt;
+	u32 u_volt_min;
+	u32 u_volt_max;
+	u32 u_amp;
+	u32 clock_latency_ns;
 
 	struct device_opp *dev_opp;
 	struct rcu_head rcu_head;

             reply	other threads:[~2015-10-07  7:36 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-07  7:35 Arnd Bergmann [this message]
2015-10-07  7:35 ` [PATCH] PM / OPP: fix debugfs files for 64-bit Arnd Bergmann
2015-10-07 10:59 ` Viresh Kumar
2015-10-07 10:59   ` Viresh Kumar
2015-10-07 11:03   ` Viresh Kumar
2015-10-07 11:03     ` Viresh Kumar
2015-10-07 11:07     ` Greg Kroah-Hartman
2015-10-07 11:07       ` Greg Kroah-Hartman
2015-10-07 11:21       ` Viresh Kumar
2015-10-07 11:21         ` Viresh Kumar
2015-10-07 12:57         ` Greg Kroah-Hartman
2015-10-07 12:57           ` Greg Kroah-Hartman
2015-10-07 13:03           ` Viresh Kumar
2015-10-07 13:03             ` Viresh Kumar
2015-10-07 13:03             ` Viresh Kumar
2015-10-07 17:19             ` Greg Kroah-Hartman
2015-10-07 17:19               ` Greg Kroah-Hartman
2015-10-07 17:27               ` Viresh Kumar
2015-10-07 17:27                 ` Viresh Kumar
2015-10-07 17:39                 ` Greg Kroah-Hartman
2015-10-07 17:39                   ` Greg Kroah-Hartman
2015-10-07 18:00                   ` Viresh Kumar
2015-10-07 18:00                     ` Viresh Kumar
2015-10-07 19:12             ` Arnd Bergmann
2015-10-07 19:12               ` Arnd Bergmann
2015-10-08  7:48               ` Viresh Kumar
2015-10-08  7:48                 ` Viresh Kumar
2015-10-08 14:25                 ` Alan Stern
2015-10-08 14:25                   ` Alan Stern
2015-10-08 14:25                   ` Alan Stern
2015-10-19 15:40                 ` Michael Turquette
2015-10-19 15:40                   ` Michael Turquette
2015-10-19 15:53                   ` Russell King - ARM Linux
2015-10-19 15:53                     ` Russell King - ARM Linux
2015-10-20 10:22                     ` Michael Turquette
2015-10-20 10:22                       ` Michael Turquette
2015-10-07 16:33         ` Russell King - ARM Linux
2015-10-07 16:33           ` Russell King - ARM Linux
2015-10-07 16:36           ` Viresh Kumar
2015-10-07 16:36             ` Viresh Kumar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5706174.BUsqiXljxZ@wuerfel \
    --to=arnd@arndb.de \
    --cc=b.zolnierkie@samsung.com \
    --cc=dtor@chromium.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=len.brown@intel.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=nm@ti.com \
    --cc=pavel@ucw.cz \
    --cc=rjw@rjwysocki.net \
    --cc=sboyd@codeaurora.org \
    --cc=viresh.kumar@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.