Skip to contentSkip to conversation

rtc: sunplus: fix format string for printing resource

PATCH Applied Arnd Bergmann 4 participants 6 messages Jan 17, 2023 – Jan 23, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rtc: sunplus: fix format string for printing resource

From: Arnd Bergmann <[email protected]>

On 32-bit architectures with 64-bit resource_size_t, sp_rtc_probe() causes a compiler warning:

drivers/rtc/rtc-sunplus.c: In function 'sp_rtc_probe':
drivers/rtc/rtc-sunplus.c:243:33: error: format '%x' expects argument of type 'unsigned int', but argument 4 has type 'resource_size_t' {aka 'long long unsigned int'} [-Werror=format=]
243 | dev_dbg(&plat_dev->dev, "res = 0x%x, reg_base = 0x%lx\n",

      |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The best way to print a resource is the special %pR format string, and similarly to print a pointer we can use %p and avoid the cast.

Fixes fad6cbe9b2b4 ("rtc: Add driver for RTC in Sunplus SP7021")
---
 drivers/rtc/rtc-sunplus.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/rtc/rtc-sunplus.c +2 -2
index e8e2ab1103fc..4b578e4d44f6 100644
@@ -240,8 +240,8 @@ static int sp_rtc_probe(struct platform_device *plat_dev)
 	if (IS_ERR(sp_rtc->reg_base))
 		return dev_err_probe(&plat_dev->dev, PTR_ERR(sp_rtc->reg_base),
 					    "%s devm_ioremap_resource fail\n", RTC_REG_NAME);
-	dev_dbg(&plat_dev->dev, "res = 0x%x, reg_base = 0x%lx\n",
-		sp_rtc->res->start, (unsigned long)sp_rtc->reg_base);
+	dev_dbg(&plat_dev->dev, "res = %pR, reg_base = %p\n",
+		sp_rtc->res, sp_rtc->reg_base);
 
 	sp_rtc->irq = platform_get_irq(plat_dev, 0);
 	if (sp_rtc->irq < 0)
Signature · 1 line
2.39.0
#1 lore raw
Quoted 5 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

On 32-bit architectures with 64-bit resource_size_t, sp_rtc_probe() causes a compiler warning:

Quoted 8 lines

drivers/rtc/rtc-sunplus.c: In function 'sp_rtc_probe':
drivers/rtc/rtc-sunplus.c:243:33: error: format '%x' expects argument of type 'unsigned int', but argument 4 has type 'resource_size_t' {aka 'long long unsigned int'} [-Werror=format=]
243 | dev_dbg(&plat_dev->dev, "res = 0x%x, reg_base = 0x%lx\n",

      |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The best way to print a resource is the special %pR format string, and similarly to print a pointer we can use %p and avoid the cast.

I got this one this morning, which one is more correct? :)
https://lore.kernel.org/all/[email protected]/

Quoted 24 lines
Fixes fad6cbe9b2b4 ("rtc: Add driver for RTC in Sunplus SP7021")
---
 drivers/rtc/rtc-sunplus.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/rtc/rtc-sunplus.c +2 -2
index e8e2ab1103fc..4b578e4d44f6 100644
@@ -240,8 +240,8 @@ static int sp_rtc_probe(struct platform_device *plat_dev)
 	if (IS_ERR(sp_rtc->reg_base))
 		return dev_err_probe(&plat_dev->dev, PTR_ERR(sp_rtc->reg_base),
 					    "%s devm_ioremap_resource fail\n", RTC_REG_NAME);
-	dev_dbg(&plat_dev->dev, "res = 0x%x, reg_base = 0x%lx\n",
-		sp_rtc->res->start, (unsigned long)sp_rtc->reg_base);
+	dev_dbg(&plat_dev->dev, "res = %pR, reg_base = %p\n",
+		sp_rtc->res, sp_rtc->reg_base);
 
 	sp_rtc->irq = platform_get_irq(plat_dev, 0);
 	if (sp_rtc->irq < 0)
Signature · 1 line
2.39.0
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#2 lore raw
Quoted 11 lines · Alexandre Belloni
Quoted 10 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

On 32-bit architectures with 64-bit resource_size_t, sp_rtc_probe() causes a compiler warning:

drivers/rtc/rtc-sunplus.c: In function 'sp_rtc_probe':
drivers/rtc/rtc-sunplus.c:243:33: error: format '%x' expects argument of type 'unsigned int', but argument 4 has type 'resource_size_t' {aka 'long long unsigned int'} [-Werror=format=]
243 | dev_dbg(&plat_dev->dev, "res = 0x%x, reg_base = 0x%lx\n",

      |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 6 lines
Quoted 3 lines

The best way to print a resource is the special %pR format string, and similarly to print a pointer we can use %p and avoid the cast.

I got this one this morning, which one is more correct? :)
https://lore.kernel.org/all/[email protected]/

I prefer my handling of res->start and Arnd's no-cast handling of reg_base. IMO using "%pR" prints too much info, but that's more up to the file's author or maintainer...

How's that? :)

Quoted 25 lines
Quoted 24 lines
Fixes fad6cbe9b2b4 ("rtc: Add driver for RTC in Sunplus SP7021")
---
 drivers/rtc/rtc-sunplus.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/rtc/rtc-sunplus.c +2 -2
index e8e2ab1103fc..4b578e4d44f6 100644
@@ -240,8 +240,8 @@ static int sp_rtc_probe(struct platform_device *plat_dev)
 	if (IS_ERR(sp_rtc->reg_base))
 		return dev_err_probe(&plat_dev->dev, PTR_ERR(sp_rtc->reg_base),
 					    "%s devm_ioremap_resource fail\n", RTC_REG_NAME);
-	dev_dbg(&plat_dev->dev, "res = 0x%x, reg_base = 0x%lx\n",
-		sp_rtc->res->start, (unsigned long)sp_rtc->reg_base);
+	dev_dbg(&plat_dev->dev, "res = %pR, reg_base = %p\n",
+		sp_rtc->res, sp_rtc->reg_base);
 
 	sp_rtc->irq = platform_get_irq(plat_dev, 0);
 	if (sp_rtc->irq < 0)
Signature · 1 line
2.39.0
Signature · 1 line
~Randy
#3 lore raw
Quoted 12 lines · Randy Dunlap
Quoted 11 lines · Alexandre Belloni
Quoted 10 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

On 32-bit architectures with 64-bit resource_size_t, sp_rtc_probe() causes a compiler warning:

drivers/rtc/rtc-sunplus.c: In function 'sp_rtc_probe':
drivers/rtc/rtc-sunplus.c:243:33: error: format '%x' expects argument of type 'unsigned int', but argument 4 has type 'resource_size_t' {aka 'long long unsigned int'} [-Werror=format=]
243 | dev_dbg(&plat_dev->dev, "res = 0x%x, reg_base = 0x%lx\n",

      |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

The best way to print a resource is the special %pR format string, and similarly to print a pointer we can use %p and avoid the cast.

I got this one this morning, which one is more correct? :)
https://lore.kernel.org/all/[email protected]/

Both are equally correct, it's just a preference.

Quoted 3 lines

I prefer my handling of res->start and Arnd's no-cast handling of reg_base. IMO using "%pR" prints too much info, but that's more up to the file's author or maintainer...

Right, I could have equally well picked the %pap version, and just went for brevity in the source. It's only pr_debug(), so very few users are going to actually see the output.

Arnd

#4 lore raw
Quoted 22 lines · Arnd Bergmann
Quoted 12 lines · Randy Dunlap
Quoted 11 lines · Alexandre Belloni
Quoted 10 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

On 32-bit architectures with 64-bit resource_size_t, sp_rtc_probe() causes a compiler warning:

drivers/rtc/rtc-sunplus.c: In function 'sp_rtc_probe':
drivers/rtc/rtc-sunplus.c:243:33: error: format '%x' expects argument of type 'unsigned int', but argument 4 has type 'resource_size_t' {aka 'long long unsigned int'} [-Werror=format=]
243 | dev_dbg(&plat_dev->dev, "res = 0x%x, reg_base = 0x%lx\n",

      |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

The best way to print a resource is the special %pR format string, and similarly to print a pointer we can use %p and avoid the cast.

I got this one this morning, which one is more correct? :)
https://lore.kernel.org/all/[email protected]/

Both are equally correct, it's just a preference.

Quoted 7 lines
Quoted 3 lines

I prefer my handling of res->start and Arnd's no-cast handling of reg_base. IMO using "%pR" prints too much info, but that's more up to the file's author or maintainer...

Right, I could have equally well picked the %pap version, and just went for brevity in the source. It's only pr_debug(), so very few users are going to actually see the output.

Alexandre, sounds like you should just go with Arnd's patch.

Signature · 1 line
~Randy
maintainer Applied
#5 lore raw
In reply to Arnd Bergmann
Quoted 9 lines · Arnd Bergmann

On 32-bit architectures with 64-bit resource_size_t, sp_rtc_probe() causes a compiler warning:

drivers/rtc/rtc-sunplus.c: In function 'sp_rtc_probe':
drivers/rtc/rtc-sunplus.c:243:33: error: format '%x' expects argument of type 'unsigned int', but argument 4 has type 'resource_size_t' {aka 'long long unsigned int'} [-Werror=format=]
243 | dev_dbg(&plat_dev->dev, "res = 0x%x, reg_base = 0x%lx\n",

      |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[...]

Applied, thanks!

[1/1] rtc: sunplus: fix format string for printing resource

      commit: 08279468a294d8c996a657ecc9e51bd5c084c75d
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com