Skip to contentSkip to conversation

media: qcom: camss: avoid format string warning

PATCH In review Arnd Bergmann 2 participants 2 messages Mar 20

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: qcom: camss: avoid format string warning

From: Arnd Bergmann <[email protected]>

clang-22 warns about csiphy_match_clock_name() taking a variable format string that is not checked against the 'int index' argument:

drivers/media/platform/qcom/camss/camss-csiphy.c:566:44: error: diagnostic behavior may be improved by
adding the 'format(printf, 2, 3)' attribute to the declaration of 'csiphy_match_clock_name' [-Werror,-Wmissing-format-attribute]

  561 | static bool csiphy_match_clock_name(const char *clock_name, const char *format,
      | __attribute__((format(printf, 2, 3)))
  562 |                                     int index)
  563 | {
  564 |         char name[16]; /* csiphyXXX_timer\0 */
  565 |
  566 |         snprintf(name, sizeof(name), format, index);
      |                                                   ^

drivers/media/platform/qcom/camss/camss-csiphy.c:561:13: note: 'csiphy_match_clock_name' declared here
561 | static bool csiphy_match_clock_name(const char *clock_name, const char *format,
| ^

Change the function to use a snprintf() style format string that allows this to be checked at the call site.

Fixes 0727615fb975 ("media: qcom: camss: Functionally decompose CSIPHY clock lookups")
---
 drivers/media/platform/qcom/camss/camss-csiphy.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/media/platform/qcom/camss/camss-csiphy.c +7 -3
index 62623393f414..78a1b568dbae 100644
@@ -558,12 +558,16 @@ static int csiphy_init_formats(struct v4l2_subdev *sd,
 	return csiphy_set_format(sd, fh ? fh->state : NULL, &format);
 }
 
-static bool csiphy_match_clock_name(const char *clock_name, const char *format,
-				    int index)
+static bool __printf(2, 3)
+csiphy_match_clock_name(const char *clock_name, const char *format, ...)
 {
 	char name[16]; /* csiphyXXX_timer\0 */
+	va_list args;
+
+	va_start(args, format);
+	vsnprintf(name, sizeof(name), format, args);
+	va_end(args);
 
-	snprintf(name, sizeof(name), format, index);
 	return !strcmp(clock_name, name);
 }
 
Signature · 1 line
2.39.5
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 43 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

clang-22 warns about csiphy_match_clock_name() taking a variable format string that is not checked against the 'int index' argument:

drivers/media/platform/qcom/camss/camss-csiphy.c:566:44: error: diagnostic behavior may be improved by
adding the 'format(printf, 2, 3)' attribute to the declaration of 'csiphy_match_clock_name' [-Werror,-Wmissing-format-attribute]

   561 | static bool csiphy_match_clock_name(const char *clock_name, const char *format,
       | __attribute__((format(printf, 2, 3)))
   562 |                                     int index)
   563 | {
   564 |         char name[16]; /* csiphyXXX_timer\0 */
   565 |
   566 |         snprintf(name, sizeof(name), format, index);
       |                                                   ^

drivers/media/platform/qcom/camss/camss-csiphy.c:561:13: note: 'csiphy_match_clock_name' declared here
561 | static bool csiphy_match_clock_name(const char *clock_name, const char *format,
| ^

Change the function to use a snprintf() style format string that allows this to be checked at the call site.

Fixes 0727615fb975 ("media: qcom: camss: Functionally decompose CSIPHY clock lookups")
---
  drivers/media/platform/qcom/camss/camss-csiphy.c | 10 +++++++---
  1 file changed, 7 insertions(+), 3 deletions(-)
drivers/media/platform/qcom/camss/camss-csiphy.c +2 -2
index 62623393f414..78a1b568dbae 100644
@@ -558,12 +558,16 @@ static int csiphy_init_formats(struct v4l2_subdev *sd,
  	return csiphy_set_format(sd, fh ? fh->state : NULL, &format);
  }
 
-static bool csiphy_match_clock_name(const char *clock_name, const char *format,
-				    int index)
+static bool __printf(2, 3)
+csiphy_match_clock_name(const char *clock_name, const char *format, ...)
  {
  	char name[16]; /* csiphyXXX_timer\0 */

drivers/media/platform/qcom/camss/camss-csiphy.c static int csiphy_init_formats(struct v4l2_subdev *sd, · line 573

Quoted 10 lines
drivers/media/platform/qcom/camss/camss-csiphy.c +5 -1
+	va_list args;
+
+	va_start(args, format);
+	vsnprintf(name, sizeof(name), format, args);
+	va_end(args);
 
-	snprintf(name, sizeof(name), format, index);
  	return !strcmp(clock_name, name);
  }