Skip to contentSkip to conversation

quiet ide-cd warning

PATCH In review Matt Mackall 2 participants 3 messages Apr 1, 2005 – Apr 2, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 quiet ide-cd warning

This shuts up a potential uninitialized variable warning.

drivers/ide/ide-cd.c +1 -3
Index: af/drivers/ide/ide-cd.c
===================================================================
@@ -430,7 +430,7 @@ void cdrom_analyze_sense_data(ide_drive_
 #if VERBOSE_IDE_CD_ERRORS
 	{
 		int i;
-		const char *s;
+		const char *s = "bad sense key!";
 		char buf[80];
 
 		printk ("ATAPI device %s:\n", drive->name);
@@ -445,8 +445,6 @@ void cdrom_analyze_sense_data(ide_drive_
 
 		if (sense->sense_key < ARY_LEN(sense_key_texts))
 			s = sense_key_texts[sense->sense_key];
-		else
-			s = "bad sense key!";
 
 		printk("%s -- (Sense key=0x%02x)\n", s, sense->sense_key);
 
Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#1 lore raw
Quoted 1 line · Matt Mackall

This shuts up a potential uninitialized variable warning.

Potential warning or potential uninitialized use? The code was right before the change, and if the compiler generates such a warning on it, it's the compiler who should be fixed, not the code: it's obvious the variable can't be used uninitialized here, and moving the things around like that makes the code misleading and hard to understand...

/mjt

Quoted 25 lines

Index: af/drivers/ide/ide-cd.c
===================================================================

drivers/ide/ide-cd.c +1 -3
@@ -430,7 +430,7 @@ void cdrom_analyze_sense_data(ide_drive_
 #if VERBOSE_IDE_CD_ERRORS
 	{
 		int i;
-		const char *s;
+		const char *s = "bad sense key!";
 		char buf[80];
 
 		printk ("ATAPI device %s:\n", drive->name);
@@ -445,8 +445,6 @@ void cdrom_analyze_sense_data(ide_drive_
 
 		if (sense->sense_key < ARY_LEN(sense_key_texts))
 			s = sense_key_texts[sense->sense_key];
-		else
-			s = "bad sense key!";
 
 		printk("%s -- (Sense key=0x%02x)\n", s, sense->sense_key);
 
#2 lore raw
Quoted 10 lines · Michael Tokarev
Quoted 1 line · Matt Mackall

This shuts up a potential uninitialized variable warning.

Potential warning or potential uninitialized use? The code was right before the change, and if the compiler generates such a warning on it, it's the compiler who should be fixed, not the code: it's obvious the variable can't be used uninitialized here, and moving the things around like that makes the code misleading and hard to understand...

It's a compiler problem.

With gcc 3.3.5:

drivers/ide/ide-cd.c: In function `cdrom_analyze_sense_data':
drivers/ide/ide-cd.c:433: warning: `s' might be used uninitialized in this function

Looks like the compiler's being stupid about my earlier patch which makes printk an inline (and it's the only thing in the tree to do so). gcc-snapshot doesn't complain.

Quoted 27 lines

/mjt

Quoted 25 lines

Index: af/drivers/ide/ide-cd.c
===================================================================

drivers/ide/ide-cd.c +1 -3
@@ -430,7 +430,7 @@ void cdrom_analyze_sense_data(ide_drive_
 #if VERBOSE_IDE_CD_ERRORS
 	{
 		int i;
-		const char *s;
+		const char *s = "bad sense key!";
 		char buf[80];
 
 		printk ("ATAPI device %s:\n", drive->name);
@@ -445,8 +445,6 @@ void cdrom_analyze_sense_data(ide_drive_
 
 		if (sense->sense_key < ARY_LEN(sense_key_texts))
 			s = sense_key_texts[sense->sense_key];
-		else
-			s = "bad sense key!";
 
 		printk("%s -- (Sense key=0x%02x)\n", s, sense->sense_key);
 
Signature · 1 line
Mathematics is the supreme nostalgia of our time.