mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/9] lib: stackprot: fix type for %pS
@ 2025-05-27 20:13 Ahmad Fatoum
  2025-05-27 20:13 ` [PATCH 2/9] fastboot: use correct format specifier for size_t Ahmad Fatoum
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Ahmad Fatoum @ 2025-05-27 20:13 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Adding __printf to the panic definition in the follow up commit will
make it evident that we are using a long value for a %pS format
specifier, which is not correct, albeit they have the same size.

Fix this by adding the missing cast.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 lib/stackprot.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/stackprot.c b/lib/stackprot.c
index 7a8d0a4c1064..1bf4f7e7a5b4 100644
--- a/lib/stackprot.c
+++ b/lib/stackprot.c
@@ -24,7 +24,8 @@ volatile ulong __stack_chk_guard = (ulong)(0xfeedf00ddeadbeef & ~0UL);
  */
 noinstr void __stack_chk_fail(void)
 {
-	panic("stack-protector: " STAGE " stack is corrupted in: %pS\n", _RET_IP_);
+	panic("stack-protector: " STAGE " stack is corrupted in: %pS\n",
+	      (void *)_RET_IP_);
 }
 EXPORT_SYMBOL(__stack_chk_fail);
 
-- 
2.39.5




^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/9] fastboot: use correct format specifier for size_t
  2025-05-27 20:13 [PATCH 1/9] lib: stackprot: fix type for %pS Ahmad Fatoum
@ 2025-05-27 20:13 ` Ahmad Fatoum
  2025-05-27 20:13 ` [PATCH 3/9] Makefile: don't warn over zero-size format string Ahmad Fatoum
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Ahmad Fatoum @ 2025-05-27 20:13 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

When we start checking for format specifier to be correct in a follow-up
commit, we will get warnings that we are printing a size_t as if it were
an int. Fix this.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/fastboot.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/common/fastboot.c b/common/fastboot.c
index 56bc4e82c4fe..de50797f31d8 100644
--- a/common/fastboot.c
+++ b/common/fastboot.c
@@ -398,7 +398,7 @@ void fastboot_download_finished(struct fastboot *fb)
 
 	printf("\n");
 
-	fastboot_tx_print(fb, FASTBOOT_MSG_INFO, "Downloading %d bytes finished",
+	fastboot_tx_print(fb, FASTBOOT_MSG_INFO, "Downloading %zu bytes finished",
 			  fb->download_bytes);
 
 	fastboot_tx_print(fb, FASTBOOT_MSG_OKAY, "");
@@ -421,7 +421,7 @@ static void cb_download(struct fastboot *fb, const char *cmd)
 	fb->download_size = simple_strtoul(cmd, NULL, 16);
 	fb->download_bytes = 0;
 
-	fastboot_tx_print(fb, FASTBOOT_MSG_INFO, "Downloading %d bytes...",
+	fastboot_tx_print(fb, FASTBOOT_MSG_INFO, "Downloading %zu bytes...",
 			  fb->download_size);
 
 	init_progression_bar(fb->download_size);
@@ -446,7 +446,7 @@ static void cb_download(struct fastboot *fb, const char *cmd)
 
 void fastboot_start_download_generic(struct fastboot *fb)
 {
-	fastboot_tx_print(fb, FASTBOOT_MSG_DATA, "%08x", fb->download_size);
+	fastboot_tx_print(fb, FASTBOOT_MSG_DATA, "%08zx", fb->download_size);
 }
 
 static void __maybe_unused cb_boot(struct fastboot *fb, const char *opt)
-- 
2.39.5




^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 3/9] Makefile: don't warn over zero-size format string
  2025-05-27 20:13 [PATCH 1/9] lib: stackprot: fix type for %pS Ahmad Fatoum
  2025-05-27 20:13 ` [PATCH 2/9] fastboot: use correct format specifier for size_t Ahmad Fatoum
@ 2025-05-27 20:13 ` Ahmad Fatoum
  2025-05-27 20:13 ` [PATCH 4/9] scripts: define __printf attribute macro Ahmad Fatoum
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Ahmad Fatoum @ 2025-05-27 20:13 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

It's normal for functions like fastboot_tx_print to take an early string
to indicate that no particular message should be reported to the host.

This would be warned about once we use the printf attribute, so let's
disable the check for barebox.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index c733a76604e7..031d5bdd3e20 100644
--- a/Makefile
+++ b/Makefile
@@ -492,7 +492,7 @@ KBUILD_CPPFLAGS        := -D__KERNEL__ -D__BAREBOX__ $(LINUXINCLUDE) \
 KBUILD_CFLAGS   := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
 		   -fno-strict-aliasing -fno-common -fshort-wchar -funsigned-char \
 		   -Werror=implicit-function-declaration -Werror=implicit-int \
-		   -Werror=int-conversion \
+		   -Werror=int-conversion -Wno-format-zero-length \
 		   -Os -pipe -Wmissing-prototypes -std=gnu11
 KBUILD_AFLAGS          := -D__ASSEMBLY__
 KBUILD_AFLAGS_KERNEL :=
-- 
2.39.5




^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 4/9] scripts: define __printf attribute macro
  2025-05-27 20:13 [PATCH 1/9] lib: stackprot: fix type for %pS Ahmad Fatoum
  2025-05-27 20:13 ` [PATCH 2/9] fastboot: use correct format specifier for size_t Ahmad Fatoum
  2025-05-27 20:13 ` [PATCH 3/9] Makefile: don't warn over zero-size format string Ahmad Fatoum
@ 2025-05-27 20:13 ` Ahmad Fatoum
  2025-05-27 20:13 ` [PATCH 5/9] treewide: specify __printf attribute directly on static definition Ahmad Fatoum
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Ahmad Fatoum @ 2025-05-27 20:13 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

In preparation for wider use of __printf, define it also for scripts and
not only in include/.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 scripts/include/linux/compiler.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/scripts/include/linux/compiler.h b/scripts/include/linux/compiler.h
index 780ccec21a3c..9e95b510c825 100644
--- a/scripts/include/linux/compiler.h
+++ b/scripts/include/linux/compiler.h
@@ -23,6 +23,10 @@
 # define __packed		__attribute__((__packed__))
 #endif
 
+#ifndef __printf
+# define __printf(a, b)		__attribute__((format(__printf__, a, b)))
+#endif
+
 #ifndef __force
 # define __force
 #endif
-- 
2.39.5




^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 5/9] treewide: specify __printf attribute directly on static definition
  2025-05-27 20:13 [PATCH 1/9] lib: stackprot: fix type for %pS Ahmad Fatoum
                   ` (2 preceding siblings ...)
  2025-05-27 20:13 ` [PATCH 4/9] scripts: define __printf attribute macro Ahmad Fatoum
@ 2025-05-27 20:13 ` Ahmad Fatoum
  2025-05-27 20:13 ` [PATCH 6/9] treewide: replace attribute with shorter __printf macro Ahmad Fatoum
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Ahmad Fatoum @ 2025-05-27 20:13 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

On a declaration, __printf can come at the end, but for a definition, it
is not accepted after argument list and before the curly brace, so
instead of having a declaration with the attribute as well as a
definition, just have a single definition and move the __printf to the
start.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 efi/devicepath.c       |  6 ++----
 include/linux/printk.h | 11 ++++-------
 include/printf.h       |  3 +--
 3 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/efi/devicepath.c b/efi/devicepath.c
index ecb3e7b64cc1..342422ea1a11 100644
--- a/efi/devicepath.c
+++ b/efi/devicepath.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 
 #include <common.h>
+#include <linux/compiler.h>
 #include <efi.h>
 #include <efi/efi-util.h>
 #include <malloc.h>
@@ -15,10 +16,7 @@ struct string {
 	unsigned used;
 };
 
-char *cprintf(struct string *str, const char *fmt, ...)
-    __attribute__ ((format(__printf__, 2, 3)));
-
-char *cprintf(struct string *str, const char *fmt, ...)
+static __printf(2, 3) char *cprintf(struct string *str, const char *fmt, ...)
 {
 	void *buf = str->str;
 	unsigned bufsize = 0;
diff --git a/include/linux/printk.h b/include/linux/printk.h
index d4aafc84e2dd..f1f76fb71859 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -3,6 +3,7 @@
 #define __LINUX_PRINTK_H
 
 #include <linux/list.h>
+#include <linux/compiler.h>
 #include <linux/err.h>
 #include <printf.h>
 #include <stdarg.h>
@@ -40,9 +41,7 @@ int dev_printf(int level, const struct device *dev, const char *format, ...)
 int pr_print(int level, const char *format, ...)
 	__attribute__ ((format(__printf__, 2, 3)));
 #else
-static int pr_print(int level, const char *format, ...)
-	__attribute__ ((format(__printf__, 2, 3)));
-static inline int pr_print(int level, const char *format, ...)
+static inline __printf(2, 3) int pr_print(int level, const char *format, ...)
 {
 	return 0;
 }
@@ -104,10 +103,8 @@ static inline int pr_print(int level, const char *format, ...)
 int dev_err_probe(struct device *dev, int err, const char *fmt, ...)
 	__attribute__ ((format(__printf__, 3, 4)));
 #elif !defined(dev_err_probe)
-static int dev_err_probe(struct device *dev, int err, const char *fmt, ...)
-	__attribute__ ((format(__printf__, 3, 4)));
-static inline int dev_err_probe(struct device *dev, int err, const char *fmt,
-				...)
+static inline __printf(3, 4) int dev_err_probe(struct device *dev,
+			       int err, const char *fmt, ...)
 {
 	return err;
 }
diff --git a/include/printf.h b/include/printf.h
index 9a84850d02bf..eac78aec92c1 100644
--- a/include/printf.h
+++ b/include/printf.h
@@ -20,8 +20,7 @@ struct device;
 	(IN_PBL && defined(CONFIG_PBL_CONSOLE))
 int printf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2)));
 #else
-static int printf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2)));
-static inline int printf(const char *fmt, ...)
+static inline __printf(1, 2) int printf(const char *fmt, ...)
 {
 	return 0;
 }
-- 
2.39.5




^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 6/9] treewide: replace attribute with shorter __printf macro
  2025-05-27 20:13 [PATCH 1/9] lib: stackprot: fix type for %pS Ahmad Fatoum
                   ` (3 preceding siblings ...)
  2025-05-27 20:13 ` [PATCH 5/9] treewide: specify __printf attribute directly on static definition Ahmad Fatoum
@ 2025-05-27 20:13 ` Ahmad Fatoum
  2025-05-27 20:13 ` [PATCH 7/9] treewide: add missing __printf attributes Ahmad Fatoum
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Ahmad Fatoum @ 2025-05-27 20:13 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

This makes for more compact code, but doesn't introduce any functional
change.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/include/asm/psci.h |  5 +++--
 include/bbu.h               |  3 +--
 include/environment.h       |  5 ++---
 include/linux/printk.h      |  7 +++----
 include/of.h                |  2 +-
 include/printf.h            |  3 ++-
 include/stdio.h             | 12 ++++++------
 include/xfuncs.h            |  2 +-
 8 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
index b342eb85f5ec..8ffb85db0516 100644
--- a/arch/arm/include/asm/psci.h
+++ b/arch/arm/include/asm/psci.h
@@ -6,6 +6,8 @@
 #ifndef __ARM_PSCI_H__
 #define __ARM_PSCI_H__
 
+#include <linux/compiler.h>
+
 struct device_node;
 
 #define ARM_PSCI_VER(major, minor)	(((major) << 16) | (minor))
@@ -121,8 +123,7 @@ void psci_cpu_entry(void);
 void psci_set_putc(void (*putcf)(void *ctx, int c), void *ctx);
 void psci_putc(char c);
 int psci_puts(const char *str);
-int psci_printf(const char *fmt, ...)
-            __attribute__ ((format(__printf__, 1, 2)));
+int psci_printf(const char *fmt, ...) __printf(1, 2);
 #else
 
 static inline void psci_set_putc(void (*putcf)(void *ctx, int c), void *ctx)
diff --git a/include/bbu.h b/include/bbu.h
index 087d3ee8278f..bce138d95b37 100644
--- a/include/bbu.h
+++ b/include/bbu.h
@@ -37,8 +37,7 @@ struct bbu_handler {
 	const char *devicefile;
 };
 
-int bbu_force(struct bbu_data *, const char *fmt, ...)
-	__attribute__ ((format(__printf__, 2, 3)));
+int bbu_force(struct bbu_data *, const char *fmt, ...) __printf(2, 3);
 
 int bbu_confirm(struct bbu_data *);
 
diff --git a/include/environment.h b/include/environment.h
index c24796427675..585af53c0bfe 100644
--- a/include/environment.h
+++ b/include/environment.h
@@ -33,7 +33,7 @@ const char *var_name(struct variable_d *);
 const char *getenv(const char *);
 int envvar_for_each(int (*fn)(struct variable_d *v, void *data), void *data);
 int setenv(const char *, const char *);
-int pr_setenv(const char *, const char *fmt, ...)  __attribute__ ((format(__printf__, 2, 3)));
+int pr_setenv(const char *, const char *fmt, ...) __printf(2, 3);
 void export_env_ull(const char *name, unsigned long long val);
 int getenv_ull(const char *name, unsigned long long *val);
 int getenv_ullx(const char *name, unsigned long long *val);
@@ -58,8 +58,7 @@ static inline int setenv(const char *var, const char *val)
 	return 0;
 }
 
-static inline __attribute__ ((format(__printf__, 2, 3))) int pr_setenv(
-	const char *var, const char *fmt, ...)
+static inline __printf(2, 3) int pr_setenv(const char *var, const char *fmt, ...)
 {
 	return 0;
 }
diff --git a/include/linux/printk.h b/include/linux/printk.h
index f1f76fb71859..f39dcb69a9ec 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -31,15 +31,14 @@ struct device;
 
 #if !defined(CONFIG_CONSOLE_NONE) && IN_PROPER
 int dev_printf(int level, const struct device *dev, const char *format, ...)
-	__attribute__ ((format(__printf__, 3, 4)));
+	__printf(3, 4);
 #else
 #define dev_printf(level, dev, ...) pr_print(((void)dev, (level)), __VA_ARGS__)
 #endif
 
 #if (IN_PROPER && !defined(CONFIG_CONSOLE_NONE)) || \
 	(IN_PBL && defined(CONFIG_PBL_CONSOLE))
-int pr_print(int level, const char *format, ...)
-	__attribute__ ((format(__printf__, 2, 3)));
+int pr_print(int level, const char *format, ...) __printf(2, 3);
 #else
 static inline __printf(2, 3) int pr_print(int level, const char *format, ...)
 {
@@ -101,7 +100,7 @@ static inline __printf(2, 3) int pr_print(int level, const char *format, ...)
 
 #if LOGLEVEL >= MSG_ERR
 int dev_err_probe(struct device *dev, int err, const char *fmt, ...)
-	__attribute__ ((format(__printf__, 3, 4)));
+	__printf(3, 4);
 #elif !defined(dev_err_probe)
 static inline __printf(3, 4) int dev_err_probe(struct device *dev,
 			       int err, const char *fmt, ...)
diff --git a/include/of.h b/include/of.h
index fccb8ba7e9e1..e46d410d3651 100644
--- a/include/of.h
+++ b/include/of.h
@@ -293,7 +293,7 @@ extern int of_property_write_string(struct device_node *np, const char *propname
 extern int of_property_write_strings(struct device_node *np, const char *propname,
 				    ...) __attribute__((__sentinel__));
 int of_property_sprintf(struct device_node *np, const char *propname, const char *fmt, ...)
-	__attribute__ ((format(__printf__, 3, 4)));
+	__printf(3, 4);
 
 extern struct device_node *of_parse_phandle(const struct device_node *np,
 					    const char *phandle_name,
diff --git a/include/printf.h b/include/printf.h
index eac78aec92c1..0e5f79afb87e 100644
--- a/include/printf.h
+++ b/include/printf.h
@@ -3,6 +3,7 @@
 #define __PRINTF_H
 
 #include <linux/types.h>
+#include <linux/compiler.h>
 
 struct device;
 
@@ -18,7 +19,7 @@ struct device;
 
 #if (IN_PROPER && !defined(CONFIG_CONSOLE_NONE)) || \
 	(IN_PBL && defined(CONFIG_PBL_CONSOLE))
-int printf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2)));
+int printf(const char *fmt, ...) __printf(1, 2);
 #else
 static inline __printf(1, 2) int printf(const char *fmt, ...)
 {
diff --git a/include/stdio.h b/include/stdio.h
index 0e01a0e63a46..f6f181941b4a 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -12,17 +12,17 @@
  */
 
 /* serial stuff */
-void serial_printf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2)));
+void serial_printf(const char *fmt, ...) __printf(1, 2);
 
-int sprintf(char *buf, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3)));
-int snprintf(char *buf, size_t size, const char *fmt, ...) __attribute__ ((format(__printf__, 3, 4)));
-int scnprintf(char *buf, size_t size, const char *fmt, ...) __attribute__ ((format(__printf__, 3, 4)));
+int sprintf(char *buf, const char *fmt, ...) __printf(2, 3);
+int snprintf(char *buf, size_t size, const char *fmt, ...) __printf(3, 4);
+int scnprintf(char *buf, size_t size, const char *fmt, ...) __printf(3, 4);
 int vsprintf(char *buf, const char *fmt, va_list args);
 int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
 int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
 
 #if IN_PROPER || defined(CONFIG_PBL_CONSOLE)
-int asprintf(char **strp, const char *fmt, ...)  __attribute__ ((format(__printf__, 2, 3)));
+int asprintf(char **strp, const char *fmt, ...) __printf(2, 3);
 char *bvasprintf(const char *fmt, va_list ap);
 int vasprintf(char **strp, const char *fmt, va_list ap);
 #else
@@ -143,7 +143,7 @@ static inline void putchar(char c)
 #define MAX_FILES	128
 
 int vdprintf(int fd, const char *fmt, va_list args) ;
-int dprintf(int file, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3)));
+int dprintf(int file, const char *fmt, ...) __printf(2, 3);
 int dputs(int file, const char *s);
 int dputc(int file, const char c);
 
diff --git a/include/xfuncs.h b/include/xfuncs.h
index f0aca6de76b3..8dd88d6607d7 100644
--- a/include/xfuncs.h
+++ b/include/xfuncs.h
@@ -17,7 +17,7 @@ char *xstrdup(const char *s);
 char *xstrndup(const char *s, size_t size) __returns_nonnull;
 void* xmemalign(size_t alignment, size_t bytes) __xalloc_size(2);
 void* xmemdup(const void *orig, size_t size) __returns_nonnull;
-char *xasprintf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2))) __returns_nonnull;
+char *xasprintf(const char *fmt, ...) __printf(1, 2) __returns_nonnull;
 char *xvasprintf(const char *fmt, va_list ap) __returns_nonnull;
 
 wchar_t *xstrdup_wchar(const wchar_t *src);
-- 
2.39.5




^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 7/9] treewide: add missing __printf attributes
  2025-05-27 20:13 [PATCH 1/9] lib: stackprot: fix type for %pS Ahmad Fatoum
                   ` (4 preceding siblings ...)
  2025-05-27 20:13 ` [PATCH 6/9] treewide: replace attribute with shorter __printf macro Ahmad Fatoum
@ 2025-05-27 20:13 ` Ahmad Fatoum
  2025-05-27 20:13 ` [PATCH 8/9] vsprintf: add %ps format specifier for symbols without offset Ahmad Fatoum
  2025-05-27 20:13 ` [PATCH 9/9] lib: random: print get_crypto_bytes caller when no HWRNG is registered Ahmad Fatoum
  7 siblings, 0 replies; 9+ messages in thread
From: Ahmad Fatoum @ 2025-05-27 20:13 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

To get compiler warnings for mismatched format specifiers, add the
__printf attribute everywhere it's appropriate.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/include/asm/psci.h | 2 +-
 include/bthread.h           | 4 +++-
 include/driver.h            | 4 ++--
 include/fastboot.h          | 2 +-
 include/libfile.h           | 3 ++-
 include/linux/clkdev.h      | 7 +++++--
 include/linux/printk.h      | 3 ++-
 include/printf.h            | 4 ++--
 include/stdio.h             | 2 +-
 include/stringlist.h        | 3 ++-
 include/xfuncs.h            | 2 +-
 11 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
index 8ffb85db0516..1952b8ac7652 100644
--- a/arch/arm/include/asm/psci.h
+++ b/arch/arm/include/asm/psci.h
@@ -139,7 +139,7 @@ static inline int psci_puts(const char *str)
 	return 0;
 }
 
-static inline int psci_printf(const char *fmt, ...)
+static inline __printf(1, 2) int psci_printf(const char *fmt, ...)
 {
 	return 0;
 }
diff --git a/include/bthread.h b/include/bthread.h
index 4441b53696fb..751d810a9f2f 100644
--- a/include/bthread.h
+++ b/include/bthread.h
@@ -7,12 +7,14 @@
 #define __BTHREAD_H_
 
 #include <linux/stddef.h>
+#include <linux/compiler.h>
 
 struct bthread;
 
 extern struct bthread *current;
 
-struct bthread *bthread_create(void (*threadfn)(void *), void *data, const char *namefmt, ...);
+struct bthread *bthread_create(void (*threadfn)(void *), void *data, const char *namefmt, ...)
+	__printf(3, 4);
 void bthread_cancel(struct bthread *bthread);
 
 void bthread_schedule(struct bthread *);
diff --git a/include/driver.h b/include/driver.h
index b5f4de01e424..e9a919f9bbb5 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -153,8 +153,8 @@ static inline const char *dev_name(const struct device *dev)
 	return dev_id(dev) ?: dev->name;
 }
 
-int dev_set_name(struct device *dev, const char *fmt, ...);
-int dev_add_alias(struct device *dev, const char *fmt, ...);
+int dev_set_name(struct device *dev, const char *fmt, ...) __printf(2, 3);
+int dev_add_alias(struct device *dev, const char *fmt, ...) __printf(2, 3);
 
 /*
  * get resource 'num' for a device
diff --git a/include/fastboot.h b/include/fastboot.h
index 4b2fdf3190b2..88577dfa5215 100644
--- a/include/fastboot.h
+++ b/include/fastboot.h
@@ -84,7 +84,7 @@ void fastboot_generic_free(struct fastboot *fb);
 int fastboot_handle_download_data(struct fastboot *fb, const void *buffer,
 				  unsigned int len);
 int fastboot_tx_print(struct fastboot *fb, enum fastboot_msg_type type,
-		      const char *fmt, ...);
+		      const char *fmt, ...) __printf(3, 4);
 void fastboot_start_download_generic(struct fastboot *fb);
 void fastboot_download_finished(struct fastboot *fb);
 void fastboot_exec_cmd(struct fastboot *fb, const char *cmdbuf)
diff --git a/include/libfile.h b/include/libfile.h
index bf775b022dc4..b795a0253039 100644
--- a/include/libfile.h
+++ b/include/libfile.h
@@ -3,6 +3,7 @@
 #define __LIBFILE_H
 
 #include <linux/types.h>
+#include <linux/compiler.h>
 
 struct resource;
 
@@ -14,7 +15,7 @@ int copy_fd(int in, int out);
 
 ssize_t read_file_into_buf(const char *filename, void *buf, size_t size);
 
-char *read_file_line(const char *fmt, ...);
+char *read_file_line(const char *fmt, ...) __printf(1, 2);
 
 void *read_file(const char *filename, size_t *size);
 
diff --git a/include/linux/clkdev.h b/include/linux/clkdev.h
index 65edbd760b2d..107dacb51995 100644
--- a/include/linux/clkdev.h
+++ b/include/linux/clkdev.h
@@ -12,6 +12,8 @@
 #ifndef __CLKDEV_H
 #define __CLKDEV_H
 
+#include <linux/compiler.h>
+
 struct clk;
 struct device;
 
@@ -24,14 +26,15 @@ struct clk_lookup {
 };
 
 struct clk_lookup *clkdev_alloc(struct clk *clk, const char *con_id,
-	const char *dev_fmt, ...);
+	const char *dev_fmt, ...) __printf(3, 4);
 
 void clkdev_add(struct clk_lookup *cl);
 void clkdev_drop(struct clk_lookup *cl);
 
 void clkdev_add_table(struct clk_lookup *, size_t);
 int clk_add_alias(const char *, const char *, char *, struct device *);
-int clk_register_clkdev(struct clk *, const char *, const char *, ...);
+int clk_register_clkdev(struct clk *, const char *, const char *, ...)
+	__printf(3, 4);
 
 int clkdev_add_physbase(struct clk *clk, unsigned long base, const char *id);
 
diff --git a/include/linux/printk.h b/include/linux/printk.h
index f39dcb69a9ec..0d7180f0ebbc 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -167,7 +167,8 @@ static inline __printf(3, 4) int dev_err_probe(struct device *dev,
 int memory_display(const void *addr, loff_t offs, unsigned nbytes, int size,
 		   int swab);
 int __pr_memory_display(int level, const void *addr, loff_t offs, unsigned nbytes,
-			int size, int swab, const char *format, ...);
+			int size, int swab, const char *format, ...)
+	__printf(7, 8);
 
 #define pr_memory_display(level, addr, offs, nbytes, size, swab) \
 	({	\
diff --git a/include/printf.h b/include/printf.h
index 0e5f79afb87e..83da06201a3a 100644
--- a/include/printf.h
+++ b/include/printf.h
@@ -27,8 +27,8 @@ static inline __printf(1, 2) int printf(const char *fmt, ...)
 }
 #endif
 
-void __attribute__((noreturn)) panic(const char *fmt, ...);
-void __attribute__((noreturn)) panic_no_stacktrace(const char *fmt, ...);
+void __noreturn panic(const char *fmt, ...) __printf(1, 2);
+void __noreturn panic_no_stacktrace(const char *fmt, ...) __printf(1, 2);
 
 #define printk			printf
 
diff --git a/include/stdio.h b/include/stdio.h
index f6f181941b4a..50688feff4e6 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -26,7 +26,7 @@ int asprintf(char **strp, const char *fmt, ...) __printf(2, 3);
 char *bvasprintf(const char *fmt, va_list ap);
 int vasprintf(char **strp, const char *fmt, va_list ap);
 #else
-static inline int asprintf(char **strp, const char *fmt, ...)
+static inline __printf(2, 3) int asprintf(char **strp, const char *fmt, ...)
 {
 	return -1;
 }
diff --git a/include/stringlist.h b/include/stringlist.h
index b964fabd2320..03711ad9c7ff 100644
--- a/include/stringlist.h
+++ b/include/stringlist.h
@@ -12,7 +12,8 @@ struct string_list {
 };
 
 int string_list_add(struct string_list *sl, const char *str);
-int string_list_add_asprintf(struct string_list *sl, const char *fmt, ...);
+int string_list_add_asprintf(struct string_list *sl, const char *fmt, ...)
+	__printf(2, 3);
 int string_list_add_sorted(struct string_list *sl, const char *str);
 int string_list_add_sort_uniq(struct string_list *sl, const char *str);
 int string_list_contains(struct string_list *sl, const char *str);
diff --git a/include/xfuncs.h b/include/xfuncs.h
index 8dd88d6607d7..eb4050f489d9 100644
--- a/include/xfuncs.h
+++ b/include/xfuncs.h
@@ -33,7 +33,7 @@ static inline char *xstrdup(const char *s) { BUG(); }
 static inline char *xstrndup(const char *s, size_t size) { BUG(); }
 static inline void* xmemalign(size_t alignment, size_t bytes) { BUG(); }
 static inline void* xmemdup(const void *orig, size_t size) { BUG(); }
-static inline char *xasprintf(const char *fmt, ...) { BUG(); }
+static inline __printf(1, 2) char *xasprintf(const char *fmt, ...) { BUG(); }
 static inline char *xvasprintf(const char *fmt, va_list ap) { BUG(); }
 
 static inline wchar_t *xstrdup_wchar(const wchar_t *src) { BUG(); }
-- 
2.39.5




^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 8/9] vsprintf: add %ps format specifier for symbols without offset
  2025-05-27 20:13 [PATCH 1/9] lib: stackprot: fix type for %pS Ahmad Fatoum
                   ` (5 preceding siblings ...)
  2025-05-27 20:13 ` [PATCH 7/9] treewide: add missing __printf attributes Ahmad Fatoum
@ 2025-05-27 20:13 ` Ahmad Fatoum
  2025-05-27 20:13 ` [PATCH 9/9] lib: random: print get_crypto_bytes caller when no HWRNG is registered Ahmad Fatoum
  7 siblings, 0 replies; 9+ messages in thread
From: Ahmad Fatoum @ 2025-05-27 20:13 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

%pS always prints an offset, which can look confusing outside of debug
output. Add a %ps variant like Linux also has.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 commands/kallsyms.c |  2 +-
 common/kallsyms.c   |  6 +++++-
 include/kallsyms.h  |  4 +++-
 lib/vsprintf.c      | 14 ++++++++++----
 4 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/commands/kallsyms.c b/commands/kallsyms.c
index 163cd99c1079..121d245500f9 100644
--- a/commands/kallsyms.c
+++ b/commands/kallsyms.c
@@ -22,7 +22,7 @@ static int do_kallsyms(int argc, char *argv[])
 	if (kstrtoul(argv[1], 16, &addr) == 0) {
 		char sym[KSYM_SYMBOL_LEN];
 
-		sprint_symbol(sym, addr);
+		sprint_symbol(sym, addr, true);
 
 		printf("%s\n", sym);
 		return 0;
diff --git a/common/kallsyms.c b/common/kallsyms.c
index 3c5904f8a833..61eae2794537 100644
--- a/common/kallsyms.c
+++ b/common/kallsyms.c
@@ -189,7 +189,7 @@ const char *kallsyms_lookup(unsigned long addr,
 }
 
 /* Look up a kernel symbol and return it in a text buffer. */
-int sprint_symbol(char *buffer, unsigned long address)
+int sprint_symbol(char *buffer, unsigned long address, bool with_offset)
 {
 	char *modname;
 	const char *name;
@@ -205,12 +205,16 @@ int sprint_symbol(char *buffer, unsigned long address)
 	len = strlen(buffer);
 	buffer += len;
 
+	if (!with_offset)
+		goto out;
+
 	if (modname)
 		len += sprintf(buffer, "+%#lx/%#lx [%s]",
 						offset, size, modname);
 	else
 		len += sprintf(buffer, "+%#lx/%#lx", offset, size);
 
+out:
 	return len;
 }
 EXPORT_SYMBOL_GPL(sprint_symbol);
diff --git a/include/kallsyms.h b/include/kallsyms.h
index f61efc9e0c42..c93287302bde 100644
--- a/include/kallsyms.h
+++ b/include/kallsyms.h
@@ -2,6 +2,8 @@
 #ifndef __KALLSYMS_H
 #define __KALLSYMS_H
 
+#include <linux/types.h>
+
 #define KSYM_NAME_LEN 128
 #define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + (KSYM_NAME_LEN - 1) + \
 		2*(BITS_PER_LONG*3/10) + (MODULE_NAME_LEN - 1) + 1)
@@ -12,6 +14,6 @@ const char *kallsyms_lookup(unsigned long addr,
 			    char **modname, char *namebuf);
 
 /* Look up a kernel symbol and return it in a text buffer. */
-int sprint_symbol(char *buffer, unsigned long address);
+int sprint_symbol(char *buffer, unsigned long address, bool with_offset);
 
 #endif /* __KALLSYMS_H */
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 32429dd76c23..ba87f6c210d2 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -254,12 +254,12 @@ static char *raw_pointer(char *buf, const char *end, const void *ptr, int field_
 
 #if IN_PROPER
 static char *symbol_string(char *buf, const char *end, const void *ptr, int field_width,
-			   int precision, int flags)
+			   int precision, int flags, bool with_offset)
 {
 	unsigned long value = (unsigned long) ptr;
 #ifdef CONFIG_KALLSYMS
 	char sym[KSYM_SYMBOL_LEN];
-	sprint_symbol(sym, value);
+	sprint_symbol(sym, value, with_offset);
 	return string(buf, end, sym, field_width, precision, flags);
 #else
 	field_width = 2*sizeof(void *);
@@ -484,7 +484,8 @@ char *device_node_string(char *buf, const char *end, const struct device_node *n
  *
  * Right now we handle following Linux-compatible format specifiers:
  *
- * - 'S' For symbolic direct pointers
+ * - 'S' For symbolic direct pointers (or function descriptors) with offset
+ * - 's' For symbolic direct pointers (or function descriptors) without offset
  * - 'U' For a 16 byte UUID/GUID, it prints the UUID/GUID in the form
  *       "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
  *       Options for %pU are:
@@ -523,9 +524,14 @@ char *device_node_string(char *buf, const char *end, const struct device_node *n
 static char *pointer(const char *fmt, char *buf, const char *end, const void *ptr,
 		     int field_width, int precision, int flags)
 {
+	bool with_offset = false;
+
 	switch (*fmt) {
 	case 'S':
-		return symbol_string(buf, end, ptr, field_width, precision, flags);
+		with_offset = true;
+		fallthrough;
+	case 's':
+		return symbol_string(buf, end, ptr, field_width, precision, flags, with_offset);
 	case 'U':
 		if (IS_ENABLED(CONFIG_PRINTF_UUID))
 			return uuid_string(buf, end, ptr, field_width, precision, flags, fmt);
-- 
2.39.5




^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 9/9] lib: random: print get_crypto_bytes caller when no HWRNG is registered
  2025-05-27 20:13 [PATCH 1/9] lib: stackprot: fix type for %pS Ahmad Fatoum
                   ` (6 preceding siblings ...)
  2025-05-27 20:13 ` [PATCH 8/9] vsprintf: add %ps format specifier for symbols without offset Ahmad Fatoum
@ 2025-05-27 20:13 ` Ahmad Fatoum
  7 siblings, 0 replies; 9+ messages in thread
From: Ahmad Fatoum @ 2025-05-27 20:13 UTC (permalink / raw)
  To: barebox; +Cc: Roland Hieber, Ahmad Fatoum

When stack protector is enabled without a HWRNG, warning or error
messages are printed, but it's not directly evident why.

Improve this by printing the caller of the function leading to message
like this:

  ERROR: stackprot_randomize_guard: no HWRNG available!

Reported-by: Roland Hieber <r.hieber@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 lib/random.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/random.c b/lib/random.c
index 889d314e0fad..0fbcf87ac0d3 100644
--- a/lib/random.c
+++ b/lib/random.c
@@ -135,11 +135,11 @@ int get_crypto_bytes(void *buf, int len)
 	}
 
 	if (!IS_ENABLED(CONFIG_ALLOW_PRNG_FALLBACK)) {
-		pr_err("no HWRNG available!\n");
+		pr_err("%ps: no HWRNG available!\n", (void *)_RET_IP_);
 		return err;
 	}
 
-	pr_warn("falling back to Pseudo RNG source!\n");
+	pr_warn("%ps: falling back to Pseudo RNG source!\n", (void *)_RET_IP_);
 
 	get_noncrypto_bytes(buf, len);
 
-- 
2.39.5




^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-05-27 20:14 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-27 20:13 [PATCH 1/9] lib: stackprot: fix type for %pS Ahmad Fatoum
2025-05-27 20:13 ` [PATCH 2/9] fastboot: use correct format specifier for size_t Ahmad Fatoum
2025-05-27 20:13 ` [PATCH 3/9] Makefile: don't warn over zero-size format string Ahmad Fatoum
2025-05-27 20:13 ` [PATCH 4/9] scripts: define __printf attribute macro Ahmad Fatoum
2025-05-27 20:13 ` [PATCH 5/9] treewide: specify __printf attribute directly on static definition Ahmad Fatoum
2025-05-27 20:13 ` [PATCH 6/9] treewide: replace attribute with shorter __printf macro Ahmad Fatoum
2025-05-27 20:13 ` [PATCH 7/9] treewide: add missing __printf attributes Ahmad Fatoum
2025-05-27 20:13 ` [PATCH 8/9] vsprintf: add %ps format specifier for symbols without offset Ahmad Fatoum
2025-05-27 20:13 ` [PATCH 9/9] lib: random: print get_crypto_bytes caller when no HWRNG is registered Ahmad Fatoum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox