mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 7/9] treewide: add missing __printf attributes
Date: Tue, 27 May 2025 22:13:57 +0200	[thread overview]
Message-ID: <20250527201359.889550-7-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20250527201359.889550-1-a.fatoum@pengutronix.de>

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




  parent reply	other threads:[~2025-05-27 20:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Ahmad Fatoum [this message]
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

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=20250527201359.889550-7-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox