[PATCH] scsi: esas2r: fix __printf annotation on esas2r_log_master()

Arnd Bergmann posted 1 patch 1 week, 4 days ago
drivers/scsi/esas2r/esas2r_log.c | 14 +++-----------
1 file changed, 3 insertions(+), 11 deletions(-)
[PATCH] scsi: esas2r: fix __printf annotation on esas2r_log_master()
Posted by Arnd Bergmann 1 week, 4 days ago
From: Arnd Bergmann <arnd@arndb.de>

clang-22 started warning about functions that take printf format strings:

drivers/scsi/esas2r/esas2r_log.c:160:50: error: diagnostic behavior may be improved by adding the 'format(printf, 3, 0)' attribute to the declaration of 'esas2r_log_master' [-Werror,-Wmissing-format-attribute]
  121 |                 retval = vsnprintf(buffer, buflen, format, args);
      |                                                                ^
drivers/scsi/esas2r/esas2r_log.c:121:12: note: 'esas2r_log_master' declared here
  121 | static int esas2r_log_master(const long level,
      |            ^

The warning already got silenced for gcc but not clang in the past.
Rather than modify that hack to turn it off for both, just add the
attribute as suggested and remove the pragma again.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/scsi/esas2r/esas2r_log.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/drivers/scsi/esas2r/esas2r_log.c b/drivers/scsi/esas2r/esas2r_log.c
index d6c87a0bae09..46f489b2263c 100644
--- a/drivers/scsi/esas2r/esas2r_log.c
+++ b/drivers/scsi/esas2r/esas2r_log.c
@@ -101,11 +101,6 @@ static const char *translate_esas2r_event_level_to_kernel(const long level)
 	}
 }
 
-#pragma GCC diagnostic push
-#ifndef __clang__
-#pragma GCC diagnostic ignored "-Wsuggest-attribute=format"
-#endif
-
 /*
  * the master logging function.  this function will format the message as
  * outlined by the formatting string, the input device information and the
@@ -118,10 +113,9 @@ static const char *translate_esas2r_event_level_to_kernel(const long level)
  *
  * @return 0 on success, or -1 if an error occurred.
  */
-static int esas2r_log_master(const long level,
-			     const struct device *dev,
-			     const char *format,
-			     va_list args)
+static __printf(3, 0)
+int esas2r_log_master(const long level, const struct device *dev,
+		      const char *format, va_list args)
 {
 	if (level <= event_log_level) {
 		unsigned long flags = 0;
@@ -175,8 +169,6 @@ static int esas2r_log_master(const long level,
 	return 0;
 }
 
-#pragma GCC diagnostic pop
-
 /*
  * formats and logs a message to the system log.
  *
-- 
2.39.5
Re: [PATCH] scsi: esas2r: fix __printf annotation on esas2r_log_master()
Posted by Martin K. Petersen 17 hours ago
On Mon, 23 Mar 2026 10:57:39 +0100, Arnd Bergmann wrote:

> clang-22 started warning about functions that take printf format strings:
> 
> drivers/scsi/esas2r/esas2r_log.c:160:50: error: diagnostic behavior may be improved by adding the 'format(printf, 3, 0)' attribute to the declaration of 'esas2r_log_master' [-Werror,-Wmissing-format-attribute]
>   121 |                 retval = vsnprintf(buffer, buflen, format, args);
>       |                                                                ^
> drivers/scsi/esas2r/esas2r_log.c:121:12: note: 'esas2r_log_master' declared here
>   121 | static int esas2r_log_master(const long level,
>       |            ^
> 
> [...]

Applied to 7.1/scsi-queue, thanks!

[1/1] scsi: esas2r: fix __printf annotation on esas2r_log_master()
      https://git.kernel.org/mkp/scsi/c/67557418905b

-- 
Martin K. Petersen
Re: [PATCH] scsi: esas2r: fix __printf annotation on esas2r_log_master()
Posted by Martin K. Petersen 6 days, 22 hours ago
Arnd,

> clang-22 started warning about functions that take printf format
> strings:

Applied to 7.1/scsi-staging, thanks!

-- 
Martin K. Petersen
Re: [PATCH] scsi: esas2r: fix __printf annotation on esas2r_log_master()
Posted by Bart Van Assche 1 week, 4 days ago
On 3/23/26 2:57 AM, Arnd Bergmann wrote:
> The warning already got silenced for gcc but not clang in the past.
> Rather than modify that hack to turn it off for both, just add the
> attribute as suggested and remove the pragma again.

Reviewed-by: Bart Van Assche <bvanassche@acm.org>