Skip to contentSkip to conversation

: Cleanup: Remove trivial gcc format string warnings when compiling with -Wformat-security (part 2: cleanups)

PATCH Floris Kraak 1 participant 1 message Feb 10, 2009

Subsystems (4)
lore
Share & tools
lore
#0 lore raw
Quoted 5 lines · Floris Kraak
Quoted 4 lines · Floris Kraak

Here's the patch that I get when I blindly patch every single location that emits this warning.

Quoted 8 lines
Quoted 4 lines

If needed I can attempt to split this monster into 135 patches but given my limited experience with the tools involved a little help on how to go about creating such a series would be appreciated ;-)

Here's the first part of a split series of patches dealing with this. I will reply to this message with further patches in the series.

This patch contains cleaned up code; As in, changes to code that has been restructured a bit to make the warning go away without introducing extra "%s" arguments.

---
[PATCH]: Cleanup: Remove trivial gcc format string warnings when compiling with -Wformat-security (part 2: cleanups)

When compiling the kernel with an allyesconfig and the gcc flags -Wformat and -Wformat-security the build process emits ~150 warnings along these lines:

init/main.c:557: warning: format not a string literal and no format arguments init/initramfs.c:582: warning: format not a string literal and no format arguments
arch/x86/kernel/dumpstack.c:115: warning: format not a string literal and no format arguments
...

Many of these warnings are harmless - the format string is statically set within the kernel itself and is known to not contain any format qualifiers.
This patch fixes a number of cases by restructuring code a little to avoid needing an extra "%s" argument.

---

sound/pci/hda/hda_codec.c +2 -4
index 0b70813..99db356 100644
@@ -591,14 +591,12 @@ find_codec_preset(struct hda_codec *codec)
 	mutex_unlock(&preset_mutex);
 
 	if (mod_requested < HDA_MODREQ_MAX_COUNT) {
-		char name[32];
 		if (!mod_requested)
-			snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
+			request_module("snd-hda-codec-id:%08x",
 				 codec->vendor_id);
 		else
-			snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
+			request_module("snd-hda-codec-id:%04x*",
 				 (codec->vendor_id >> 16) & 0xffff);
-		request_module(name);
 		mod_requested++;
 		goto again;
 	}
arch/x86/kernel/e820.c +3 -2
index e858268..c7ebb40 100644
@@ -1172,8 +1172,9 @@ u64 __init e820_hole_size(u64 start, u64 end)
 	return end - start - ((u64)ram << PAGE_SHIFT);
 }
 
-static void early_panic(char *msg)
+static inline void __init panic_memory_map_invalid(void)
 {
+	static const char msg[] = "Invalid user supplied memory map";
 	early_printk(msg);
 	panic(msg);
 }
@@ -1253,7 +1254,7 @@ void __init finish_e820_parsing(void)
 		int nr = e820.nr_map;
 
 		if (sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &nr) < 0)
-			early_panic("Invalid user supplied memory map");
+			panic_memory_map_invalid();
 		e820.nr_map = nr;
 
 		printk(KERN_INFO "user-defined physical RAM map:\n");
drivers/net/hamradio/mkiss.c +1 -1
index bbdb311..5ededee 100644
@@ -994,7 +994,7 @@ static int __init mkiss_init_driver(void)
 	printk(banner);
 
 	if ((status = tty_register_ldisc(N_AX25, &ax_ldisc)) != 0)
-		printk(msg_regfail);
+		printk(msg_regfail, status);
 
 	return status;
 }
drivers/net/wireless/b43/main.c +4 -4
index c788bad..7472526 100644
@@ -1999,11 +1999,11 @@ static void b43_release_firmware(struct b43_wldev *dev)
 
 static void b43_print_fw_helptext(struct b43_wl *wl, bool error)
 {
-	const char *text;
+	static const char text[] =
+		"You must go to "
+		"http://linuxwireless.org/en/users/Drivers/b43#devicefirmware "
+		"and download the latest firmware (version 4).\n";
 
-	text = "You must go to "
-	       "http://linuxwireless.org/en/users/Drivers/b43#devicefirmware "
-	       "and download the latest firmware (version 4).\n";
 	if (error)
 		b43err(wl, text);
 	else
sound/core/sound.c +6 -6
index 7872a02..8e4237c 100644
@@ -81,14 +81,14 @@ EXPORT_SYMBOL(snd_request_card);
 
 static void snd_request_other(int minor)
 {
-	char *str;
-
 	switch (minor) {
-	case SNDRV_MINOR_SEQUENCER:	str = "snd-seq";	break;
-	case SNDRV_MINOR_TIMER:		str = "snd-timer";	break;
-	default:			return;
+	case SNDRV_MINOR_SEQUENCER:
+		request_module("snd-seq");
+		break;
+	case SNDRV_MINOR_TIMER:
+		request_module("snd-timer");
+		break;
 	}
-	request_module(str);
 }
 
 #endif	/* modular kernel */
sound/drivers/opl3/opl3_seq.c +0 -0
index 2d33f53..7c0e0bc 100644
@@ -220,6 +220,7 @@ static int snd_opl3_seq_new_device(struct

snd_seq_device *dev)
struct snd_opl3 *opl3;
int client, err;
char name[32];
+ static const char nameformat [] = "OPL%i FM synth";
int opl_ver;

opl3 = *(struct snd_opl3 **)SNDRV_SEQ_DEVICE_ARGPTR(dev);
@@ -232,10 +233,9 @@ static int snd_opl3_seq_new_device(struct snd_seq_device *dev)

/* allocate new client */
opl_ver = (opl3->hardware & OPL3_HW_MASK) >> 8;
- sprintf(name, "OPL%i FM synth", opl_ver);
client = opl3->seq_client =
snd_seq_create_kernel_client(opl3->card, opl3->seq_dev_num,
- name);
+ nameformat, opl_ver);
if (client < 0)
return client;

@@ -253,6 +253,7 @@ static int snd_opl3_seq_new_device(struct snd_seq_device *dev)
opl3->sys_timer_status = 0;

#ifdef CONFIG_SND_SEQUENCER_OSS
+ sprintf(name, nameformat, opl_ver);
snd_opl3_init_seq_oss(opl3, name);
#endif
return 0;
---

Regards,
Floris
---
"They that give up essential liberty to obtain temporary safety, deserve neither liberty nor safety."
-- Ben Franklin

"The course of history shows that as a government grows, liberty decreases."
-- Thomas Jefferson