Skip to contentSkip to conversation

vsprintf: remove redundant %pCn format specifier

PATCH Superseded Luca Ceresoli 5 participants 13 messages Mar 7, 2025 – Mar 10, 2025

Subsystems (7)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover vsprintf: remove redundant %pCn format specifier

There are two printk format specifiers for clocks: %pC and %pCn, and they print exactly the same string. The reason for having two is not totally clear (see discussion in patch 2), but there seem to be no advantage in having two instead of one.

Definitely having two without properly documenting they do the same creates misunderstandings [0].

Since %pCn is used in a single place, replace it with %pC and remove %pCn to simplify such format specifiers implementation and avoid misunderstandings.

[0] https://lore.kernel.org/dri-devel/[email protected]/

---
Luca Ceresoli (2):
thermal: bcm2835: use %pC instead of %pCn
vsprintf: remove redundant and unused %pCn format specifier

 Documentation/core-api/printk-formats.rst  |  3 +--
 drivers/thermal/broadcom/bcm2835_thermal.c |  2 +-
 lib/vsprintf.c                             | 10 ++--------
 3 files changed, 4 insertions(+), 11 deletions(-)

---
base-commit: 7eb172143d5508b4da468ed59ee857c6e5e01da6
change-id: 20250307-vsprintf-pcn-8a43e3b0d43e

Best regards,

Signature · 1 line
Luca Ceresoli <[email protected]>
#1 lore raw

PATCH 1/2 thermal: bcm2835: use %pC instead of %pCn

The %pC and %pCn printk format specifiers produce the exact same string. In preparation for removing %pCn, use %pC.

---
 drivers/thermal/broadcom/bcm2835_thermal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thermal/broadcom/bcm2835_thermal.c +1 -1
index 7fbba2233c4c12e14090832a62784e1500c0ab79..685a5aee5e0dfb113638313a9086721beae09db3 100644
@@ -192,7 +192,7 @@ static int bcm2835_thermal_probe(struct platform_device *pdev)
 	rate = clk_get_rate(data->clk);
 	if ((rate < 1920000) || (rate > 5000000))
 		dev_warn(dev,
-			 "Clock %pCn running at %lu Hz is outside of the recommended range: 1.92 to 5MHz\n",
+			 "Clock %pC running at %lu Hz is outside of the recommended range: 1.92 to 5MHz\n",
 			 data->clk, rate);
 
 	/* register of thermal sensor and get info from DT */
Signature · 1 line
2.48.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] thermal: bcm2835: use %pC instead of %pCn

Quoted 4 lines · Luca Ceresoli

The %pC and %pCn printk format specifiers produce the exact same string. In preparation for removing %pCn, use %pC.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#3 lore raw

Re: [PATCH 1/2] thermal: bcm2835: use %pC instead of %pCn

In reply to Luca Ceresoli
Quoted 5 lines · Luca Ceresoli

The %pC and %pCn printk format specifiers produce the exact same string. In preparation for removing %pCn, use %pC.

---

Applied patch 1/2

Thanks!

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#4 lore raw

PATCH 2/2 vsprintf: remove redundant and unused %pCn format specifier

In reply to Luca Ceresoli

%pC and %pCn print the same string, and commit 900cca294425 ("lib/vsprintf:
add %pC{,n,r} format specifiers for clocks") introducing them does not clarify any intended difference. It can be assumed %pC is a default for %pCn as some other specifiers do, but not all are consistent with this policy. Moreover there is now no other suffix other than 'n', which makes a default not really useful.

All users in the kernel were using %pC except for one which has been converted. So now remove %pCn and all the unnecessary extra code and documentation.

---
 Documentation/core-api/printk-formats.rst |  3 +--
 lib/vsprintf.c                            | 10 ++--------
 2 files changed, 3 insertions(+), 10 deletions(-)
Documentation/core-api/printk-formats.rst +1 -2
index ecccc0473da9c10f45f2464566f690472c61401e..f3009e6ec80a864c330c8812efcd82c12f4066b3 100644
@@ -571,9 +571,8 @@ struct clk
 ::
 
 	%pC	pll1
-	%pCn	pll1
 
-For printing struct clk structures. %pC and %pCn print the name of the clock
+For printing struct clk structures. %pC prints the name of the clock
 (Common Clock Framework) or a unique 32-bit ID (legacy clock framework).
 
 Passed by reference.
lib/vsprintf.c +2 -8
index 56fe96319292674c9f79559cf78dd0d99d1a1f06..143d55cb1c12acac21a6c6bafd255437e878f280 100644
@@ -1969,15 +1969,11 @@ char *clock(char *buf, char *end, struct clk *clk, struct printf_spec spec,
 	if (check_pointer(&buf, end, clk, spec))
 		return buf;
 
-	switch (fmt[1]) {
-	case 'n':
-	default:
 #ifdef CONFIG_COMMON_CLK
-		return string(buf, end, __clk_get_name(clk), spec);
+	return string(buf, end, __clk_get_name(clk), spec);
 #else
-		return ptr_to_id(buf, end, clk, spec);
+	return ptr_to_id(buf, end, clk, spec);
 #endif
-	}
 }
 
 static
@@ -2382,8 +2378,6 @@ char *rust_fmt_argument(char *buf, char *end, void *ptr);
  *      T    time64_t
  * - 'C' For a clock, it prints the name (Common Clock Framework) or address
  *       (legacy clock framework) of the clock
- * - 'Cn' For a clock, it prints the name (Common Clock Framework) or address
- *        (legacy clock framework) of the clock
  * - 'G' For flags to be printed as a collection of symbolic strings that would
  *       construct the specific value. Supported flags given by option:
  *       p page flags (see struct page) given as pointer to unsigned long
Signature · 1 line
2.48.1
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] vsprintf: remove redundant and unused %pCn format specifier

Hi Luca,

Quoted 6 lines · Luca Ceresoli

%pC and %pCn print the same string, and commit 900cca294425 ("lib/vsprintf:
add %pC{,n,r} format specifiers for clocks") introducing them does not clarify any intended difference. It can be assumed %pC is a default for %pCn as some other specifiers do, but not all are consistent with this policy. Moreover there is now no other suffix other than 'n', which makes a default not really useful.

The original intention was indeed to serve as a default, like some other formats also have ("%pa[p]", %pOF[f]").

Quoted 5 lines

All users in the kernel were using %pC except for one which has been converted. So now remove %pCn and all the unnecessary extra code and documentation.

I guess this is a worthwhile cleanup.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#6 lore raw

Re: [PATCH 2/2] vsprintf: remove redundant and unused %pCn format specifier

In reply to Luca Ceresoli
Quoted 10 lines · Luca Ceresoli

%pC and %pCn print the same string, and commit 900cca294425 ("lib/vsprintf:
add %pC{,n,r} format specifiers for clocks") introducing them does not clarify any intended difference. It can be assumed %pC is a default for %pCn as some other specifiers do, but not all are consistent with this policy. Moreover there is now no other suffix other than 'n', which makes a default not really useful.

All users in the kernel were using %pC except for one which has been converted. So now remove %pCn and all the unnecessary extra code and documentation.

You seem forgot to update translation(s) of the documentation.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#7 lore raw

Re: [PATCH 2/2] vsprintf: remove redundant and unused %pCn format specifier

Hello Andy,

Quoted 8 lines · On Fri, 7 Mar 2025 19:17:26 +0200 Andy Shevchenko…
Quoted 7 lines · Luca Ceresoli

%pC and %pCn print the same string, and commit 900cca294425 ("lib/vsprintf:
add %pC{,n,r} format specifiers for clocks") introducing them does not clarify any intended difference. It can be assumed %pC is a default for %pCn as some other specifiers do, but not all are consistent with this policy. Moreover there is now no other suffix other than 'n', which makes a default not really useful.

Quoted 5 lines
Quoted 3 lines

All users in the kernel were using %pC except for one which has been converted. So now remove %pCn and all the unnecessary extra code and documentation.

You seem forgot to update translation(s) of the documentation.

I'm afraid I don't speak Chinese. :-)

For this specific change I think I could come up with an approximation of it, but the both the docs and git log suggest this is not expected.

Luca

Signature · 3 lines
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#8 lore raw

Re: [PATCH 2/2] vsprintf: remove redundant and unused %pCn format specifier

Quoted 10 lines · Luca Ceresoli
Quoted 8 lines · On Fri, 7 Mar 2025 19:17:26 +0200 Andy Shevchenko…
Quoted 7 lines · Luca Ceresoli

%pC and %pCn print the same string, and commit 900cca294425 ("lib/vsprintf:
add %pC{,n,r} format specifiers for clocks") introducing them does not clarify any intended difference. It can be assumed %pC is a default for %pCn as some other specifiers do, but not all are consistent with this policy. Moreover there is now no other suffix other than 'n', which makes a default not really useful.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

All users in the kernel were using %pC except for one which has been converted. So now remove %pCn and all the unnecessary extra code and documentation.

You seem forgot to update translation(s) of the documentation.

I'm afraid I don't speak Chinese. :-)

At bare minimum we can drop the same line in the list.
Also in such a case we may ask a Chinese speaking person to review / correct / suggest the changes. I would not leave a leftover as it will be forgotten so easily and documentation becomes not in sync.

Quoted 2 lines

For this specific change I think I could come up with an approximation of it, but the both the docs and git log suggest this is not expected.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#9 lore raw

Re: [PATCH 2/2] vsprintf: remove redundant and unused %pCn format specifier

Hello,

+To: Alex Shi, Yanteng Si (Chinese docs maintainers)
+Cc: Binbin Zhou (contributor to English version of printk-formats.rst)

Quoted 15 lines · On Mon, 10 Mar 2025 10:17:14 +0200 Andy Shevchenko…
Quoted 14 lines · Luca Ceresoli
Quoted 12 lines · On Fri, 7 Mar 2025 19:17:26 +0200 Andy Shevchenko…
Quoted 10 lines · Luca Ceresoli

%pC and %pCn print the same string, and commit 900cca294425 ("lib/vsprintf:
add %pC{,n,r} format specifiers for clocks") introducing them does not clarify any intended difference. It can be assumed %pC is a default for %pCn as some other specifiers do, but not all are consistent with this policy. Moreover there is now no other suffix other than 'n', which makes a default not really useful.

All users in the kernel were using %pC except for one which has been converted. So now remove %pCn and all the unnecessary extra code and documentation.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

You seem forgot to update translation(s) of the documentation.

I'm afraid I don't speak Chinese. :-)

At bare minimum we can drop the same line in the list.
Also in such a case we may ask a Chinese speaking person to review / correct / suggest the changes. I would not leave a leftover as it will be forgotten so easily and documentation becomes not in sync.

Alex Shi, Yanteng Si: what is the process to update the Chinese documentation after changes to the English one, considering I don't speak Chinese?

The documentation [0] seems to imply it will be done by you after the English documentation update, is it the case?

Otherwise, for this simple change, I can add a patch that looks like a somewhat correct one for Chinese:

@@ -523,9 +523,8 @@ clk结构体
::

%pC pll1
- %pCn pll1

-用于打印clk结构。%pC 和 %pCn 打印时钟的名称(通用时钟框架)或唯一的32位
+用于打印clk结构。%pC 打印时钟的名称(通用时钟框架)或唯一的32位
ID(传统时钟框架)。

通过引用传递。

Can you confirm the above is a correct change?

Luca

[0] https://docs.kernel.org/translations/index.html

Signature · 3 lines
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
maintainer Acked-by on v1 2/2
#10 lore raw

Re: [PATCH 2/2] vsprintf: remove redundant and unused %pCn format specifier

In reply to Luca Ceresoli

Quoting Luca Ceresoli (2025-03-07 03:19:08)

Quoted 7 lines

%pC and %pCn print the same string, and commit 900cca294425 ("lib/vsprintf:
add %pC{,n,r} format specifiers for clocks") introducing them does not clarify any intended difference. It can be assumed %pC is a default for %pCn as some other specifiers do, but not all are consistent with this policy. Moreover there is now no other suffix other than 'n', which makes a default not really useful.

Quoted 6 lines

All users in the kernel were using %pC except for one which has been converted. So now remove %pCn and all the unnecessary extra code and documentation.

---

#11 lore raw
In reply to Luca Ceresoli

Hi Luca,

Quoted 5 lines · Luca Ceresoli

There are two printk format specifiers for clocks: %pC and %pCn, and they print exactly the same string. The reason for having two is not totally clear (see discussion in patch 2), but there seem to be no advantage in having two instead of one.

Quoted 8 lines

Definitely having two without properly documenting they do the same creates misunderstandings [0].

Since %pCn is used in a single place, replace it with %pC and remove %pCn to simplify such format specifiers implementation and avoid misunderstandings.

[0] https://lore.kernel.org/dri-devel/[email protected]/

The link looks unrelated?

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#12 lore raw
Quoted 11 lines · On Fri, 7 Mar 2025 13:13:19 +0100 Geert Uytterhoeven <[email protected]>…

Hi Luca,

Quoted 8 lines · Luca Ceresoli

There are two printk format specifiers for clocks: %pC and %pCn, and they print exactly the same string. The reason for having two is not totally clear (see discussion in patch 2), but there seem to be no advantage in having two instead of one.

Definitely having two without properly documenting they do the same creates misunderstandings [0].

Quoted 7 lines
Quoted 5 lines

Since %pCn is used in a single place, replace it with %pC and remove %pCn to simplify such format specifiers implementation and avoid misunderstandings.

[0] https://lore.kernel.org/dri-devel/[email protected]/

The link looks unrelated?

Wrong link, sorry. The correct one
is: https://lore.kernel.org/dri-devel/[email protected]/

Luca

Signature · 3 lines
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com