Skip to contentSkip to conversation

printk: add __printf attributes to internal functions

PATCH Superseded Nicolas Iooss 3 participants 6 messages May 20, 2017 – May 25, 2017 Printk

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 printk: add __printf attributes to internal functions

When compiling with -Wsuggest-attribute=format, gcc complains that some functions in kernel/printk/printk_safe.c transmit their argument to printf-like functions without having a printf attribute. Silence these warnings by adding relevant __printf attributes.

---
 kernel/printk/printk_safe.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/printk/printk_safe.c +4 -4
index 033e50a7d706..2e27a31941f4 100644
@@ -80,8 +80,8 @@ static void queue_flush_work(struct printk_safe_seq_buf *s)
  * happen, printk_safe_log_store() will notice the buffer->len mismatch
  * and repeat the write.
  */
-static int printk_safe_log_store(struct printk_safe_seq_buf *s,
-				 const char *fmt, va_list args)
+static __printf(2, 0) int printk_safe_log_store(struct printk_safe_seq_buf *s,
+						const char *fmt, va_list args)
 {
 	int add;
 	size_t len;
@@ -299,7 +299,7 @@ void printk_safe_flush_on_panic(void)
  * one writer running. But the buffer might get flushed from another
  * CPU, so we need to be careful.
  */
-static int vprintk_nmi(const char *fmt, va_list args)
+static __printf(1, 0) int vprintk_nmi(const char *fmt, va_list args)
 {
 	struct printk_safe_seq_buf *s = this_cpu_ptr(&nmi_print_seq);
 
@@ -330,7 +330,7 @@ static int vprintk_nmi(const char *fmt, va_list args)
  * into itself. It uses a per-CPU buffer to store the message, just like
  * NMI.
  */
-static int vprintk_safe(const char *fmt, va_list args)
+static __printf(1, 0) int vprintk_safe(const char *fmt, va_list args)
 {
 	struct printk_safe_seq_buf *s = this_cpu_ptr(&safe_print_seq);
 
Signature · 1 line
2.12.2
maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Nicolas Iooss
Quoted 26 lines · Nicolas Iooss

When compiling with -Wsuggest-attribute=format, gcc complains that some functions in kernel/printk/printk_safe.c transmit their argument to printf-like functions without having a printf attribute. Silence these warnings by adding relevant __printf attributes.

---
 kernel/printk/printk_safe.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/printk/printk_safe.c +2 -2
index 033e50a7d706..2e27a31941f4 100644
@@ -80,8 +80,8 @@ static void queue_flush_work(struct printk_safe_seq_buf *s)
  * happen, printk_safe_log_store() will notice the buffer->len mismatch
  * and repeat the write.
  */
-static int printk_safe_log_store(struct printk_safe_seq_buf *s,
-				 const char *fmt, va_list args)
+static __printf(2, 0) int printk_safe_log_store(struct printk_safe_seq_buf *s,
+						const char *fmt, va_list args)
 {
 	int add;
 	size_t len;

kernel/printk/printk_safe.c void printk_safe_flush_on_panic(void) · line 302

Quoted 5 lines
kernel/printk/printk_safe.c +1 -1
@@ -299,7 +299,7 @@ void printk_safe_flush_on_panic(void)
  * one writer running. But the buffer might get flushed from another
  * CPU, so we need to be careful.
  */
-static int vprintk_nmi(const char *fmt, va_list args)
+static __printf(1, 0) int vprintk_nmi(const char *fmt, va_list args)

There is one more variant of this function used when CONFIG_PRINTK_NMI is not defined. Feel free to send updated patch as a reply. Or I could add this trivial change when pushing this patch to printk.git if nobody complains.

Otherwise, the patch looks fine to me. Therefore with patching the other vprintk_nmi() variant:

Best Regards,
Petr

#3 lore raw

PATCH v2 1/1 printk: add __printf attributes to internal functions

When compiling with -Wsuggest-attribute=format, gcc complains that some functions in kernel/printk/printk_safe.c transmit their argument to printf-like functions without having a printf attribute. Silence these warnings by adding relevant __printf attributes.

---
v2: add __printf attribute to the definition of vprintk_nmi() which is used when CONFIG_PRINTK_NMI is not defined.

 kernel/printk/printk_safe.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
kernel/printk/printk_safe.c +5 -5
index 033e50a7d706..f96d1ecd85ac 100644
@@ -80,8 +80,8 @@ static void queue_flush_work(struct printk_safe_seq_buf *s)
  * happen, printk_safe_log_store() will notice the buffer->len mismatch
  * and repeat the write.
  */
-static int printk_safe_log_store(struct printk_safe_seq_buf *s,
-				 const char *fmt, va_list args)
+static __printf(2, 0) int printk_safe_log_store(struct printk_safe_seq_buf *s,
+						const char *fmt, va_list args)
 {
 	int add;
 	size_t len;
@@ -299,7 +299,7 @@ void printk_safe_flush_on_panic(void)
  * one writer running. But the buffer might get flushed from another
  * CPU, so we need to be careful.
  */
-static int vprintk_nmi(const char *fmt, va_list args)
+static __printf(1, 0) int vprintk_nmi(const char *fmt, va_list args)
 {
 	struct printk_safe_seq_buf *s = this_cpu_ptr(&nmi_print_seq);
 
@@ -318,7 +318,7 @@ void printk_nmi_exit(void)
 
 #else
 
-static int vprintk_nmi(const char *fmt, va_list args)
+static __printf(1, 0) int vprintk_nmi(const char *fmt, va_list args)
 {
 	return 0;
 }
@@ -330,7 +330,7 @@ static int vprintk_nmi(const char *fmt, va_list args)
  * into itself. It uses a per-CPU buffer to store the message, just like
  * NMI.
  */
-static int vprintk_safe(const char *fmt, va_list args)
+static __printf(1, 0) int vprintk_safe(const char *fmt, va_list args)
 {
 	struct printk_safe_seq_buf *s = this_cpu_ptr(&safe_print_seq);
 
Signature · 1 line
2.13.0
maintainer
#4 lore raw
Quoted 10 lines · Nicolas Iooss

When compiling with -Wsuggest-attribute=format, gcc complains that some functions in kernel/printk/printk_safe.c transmit their argument to printf-like functions without having a printf attribute. Silence these warnings by adding relevant __printf attributes.

---
v2: add __printf attribute to the definition of vprintk_nmi() which is used when CONFIG_PRINTK_NMI is not defined.

Sergey, I believe that that your Reviewed-by is still valid even after this small update. Is that true, please?

Best Regards,
Petr

Reviewed-by
#5 lore raw
Quoted 6 lines · Petr Mladek
Quoted 5 lines · Nicolas Iooss

When compiling with -Wsuggest-attribute=format, gcc complains that some functions in kernel/printk/printk_safe.c transmit their argument to printf-like functions without having a printf attribute. Silence these warnings by adding relevant __printf attributes.

Quoted 8 lines
Quoted 5 lines

---
v2: add __printf attribute to the definition of vprintk_nmi() which is used when CONFIG_PRINTK_NMI is not defined.

Sergey, I believe that that your Reviewed-by is still valid even after this small update. Is that true, please?

sure. sorry about that!

	-ss