Skip to contentSkip to conversation

mtd: mtdpart: Do not supply NULL to printf()

PATCH Applied Andy Shevchenko 3 participants 4 messages Mar 13, 2025 – Mar 18, 2025 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mtd: mtdpart: Do not supply NULL to printf()

GCC compiler is not happy about NULL being supplied as printf() parameter:

drivers/mtd/mtdpart.c:693:34: error: ‘%s’ directive argument is null [-Werror=format-overflow=]

Move the code after the parser test for NULL, and drop the ternary completely. The user can deduct this since when it's not NULL two messages will be printed.

---

v2: changed approach to remove that ternary completely, seems less hackish

 drivers/mtd/mtdpart.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/mtd/mtdpart.c +1 -2
index 6811a714349d..994e8c51e674 100644
@@ -690,10 +690,9 @@ int parse_mtd_partitions(struct mtd_info *master, const char *const *types,
 			parser = mtd_part_parser_get(*types);
 			if (!parser && !request_module("%s", *types))
 				parser = mtd_part_parser_get(*types);
-			pr_debug("%s: got parser %s\n", master->name,
-				parser ? parser->name : NULL);
 			if (!parser)
 				continue;
+			pr_debug("%s: got parser %s\n", master->name, parser->name);
 			ret = mtd_part_do_parse(parser, master, &pparts, data);
 			if (ret <= 0)
 				mtd_part_parser_put(parser);
Signature · 1 line
2.47.2
Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Andy Shevchenko

GCC compiler is not happy about NULL being supplied as printf() parameter:

drivers/mtd/mtdpart.c:693:34: error: ‘%s’ directive argument is null [-Werror=format-overflow=]

Move the code after the parser test for NULL, and drop the ternary completely. The user can deduct this since when it's not NULL two messages will be printed.

Quoted 7 lines

---

v2: changed approach to remove that ternary completely, seems less hackish

  drivers/mtd/mtdpart.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
Quoted 18 lines
drivers/mtd/mtdpart.c +1 -2
index 6811a714349d..994e8c51e674 100644
@@ -690,10 +690,9 @@ int parse_mtd_partitions(struct mtd_info *master, const char *const *types,
  			parser = mtd_part_parser_get(*types);
  			if (!parser && !request_module("%s", *types))
  				parser = mtd_part_parser_get(*types);
-			pr_debug("%s: got parser %s\n", master->name,
-				parser ? parser->name : NULL);
  			if (!parser)
  				continue;
+			pr_debug("%s: got parser %s\n", master->name, parser->name);
  			ret = mtd_part_do_parse(parser, master, &pparts, data);
  			if (ret <= 0)
  				mtd_part_parser_put(parser);
#2 lore raw
Quoted 9 lines · Zhihao Cheng
Quoted 6 lines · Andy Shevchenko

GCC compiler is not happy about NULL being supplied as printf() parameter:

drivers/mtd/mtdpart.c:693:34: error: ‘%s’ directive argument is null [-Werror=format-overflow=]

Move the code after the parser test for NULL, and drop the ternary completely. The user can deduct this since when it's not NULL two messages will be printed.

Thank you!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer Applied
#3 lore raw
In reply to Andy Shevchenko
Quoted 8 lines · Andy Shevchenko

GCC compiler is not happy about NULL being supplied as printf() parameter:

drivers/mtd/mtdpart.c:693:34: error: ‘%s’ directive argument is null [-Werror=format-overflow=]

Move the code after the parser test for NULL, and drop the ternary completely. The user can deduct this since when it's not NULL two messages will be printed.

[...]

Applied to mtd/next, thanks!

[1/1] mtd: mtdpart: Do not supply NULL to printf()

      commit: 6bc9f42739889eaaaa47b90f48e4ef8323efa3ea

Patche(s) should be available on mtd/linux.git and will be part of the next PR (provided that no robot complains by then).

Kind regards,
Miquèl