Skip to contentSkip to conversation

sisusb: Use static const, fix typo

PATCH Joe Perches 2 participants 4 messages Feb 22, 2014 – Feb 25, 2014

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

Reduce text a bit by using static const.

Fix a symmetric typo and neaten a dev_info call
to 80 columns.

$ size drivers/usb/misc/sisusbvga/sisusb.o*
   text	   data	    bss	    dec	    hex	filename
  30016	   4841	   9180	  44037	   ac05	drivers/usb/misc/sisusbvga/sisusb.o.new
  30087	   4841	   9180	  44108	   ac4c	drivers/usb/misc/sisusbvga/sisusb.o.old
---
 drivers/usb/misc/sisusbvga/sisusb.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/usb/misc/sisusbvga/sisusb.c +7 -5
index de98906..1f89633 100644
@@ -2123,8 +2123,9 @@ sisusb_get_ramconfig(struct sisusb_usb_data *sisusb)
 	u8 tmp8, tmp82, ramtype;
 	int bw = 0;
 	char *ramtypetext1 = NULL;
-	const char *ramtypetext2[] = {	"SDR SDRAM", "SDR SGRAM",
-					"DDR SDRAM", "DDR SGRAM" };
+	static const char *ramtypetext2[] = {
+		"SDR SDRAM", "SDR SGRAM", "DDR SDRAM", "DDR SGRAM"
+	};
 	static const int busSDR[4]  = {64, 64, 128, 128};
 	static const int busDDR[4]  = {32, 32,  64,  64};
 	static const int busDDRA[4] = {64+32, 64+32 , (64+32)*2, (64+32)*2};
@@ -2146,7 +2147,7 @@ sisusb_get_ramconfig(struct sisusb_usb_data *sisusb)
 		sisusb->vramsize <<= 1;
 		bw = busSDR[(tmp8 & 0x03)];
 		break;
-	case 2: ramtypetext1 = "asymmeric";
+	case 2: ramtypetext1 = "asymmetric";
 		sisusb->vramsize += sisusb->vramsize/2;
 		bw = busDDRA[(tmp8 & 0x03)];
 		break;
@@ -2156,8 +2157,9 @@ sisusb_get_ramconfig(struct sisusb_usb_data *sisusb)
 		break;
 	}
 
-	dev_info(&sisusb->sisusb_dev->dev, "%dMB %s %s, bus width %d\n", (sisusb->vramsize >> 20), ramtypetext1,
-			ramtypetext2[ramtype], bw);
+	dev_info(&sisusb->sisusb_dev->dev, "%dMB %s %s, bus width %d\n",
+		 sisusb->vramsize >> 20, ramtypetext1, ramtypetext2[ramtype],
+		 bw);
 }
 
 static int
#1 lore raw

From: Joe Perches

Quoted 1 line

Reduce text a bit by using static const.

If you want to save a few bytes remove the pointers. (and the fixed RAM text to get below 7 chars). eg:

drivers/usb/misc/sisusbvga/sisusb.c sisusb_get_ramconfig(struct sisusb_usb_data *sisusb) · line 2127

Quoted 2 lines
drivers/usb/misc/sisusbvga/sisusb.c +0 -2
-	const char *ramtypetext2[] = {	"SDR SDRAM", "SDR SGRAM",
-					"DDR SDRAM", "DDR SGRAM" };
	static const char ramtypetext2[8][] = {
		"SDR SD", "SDR SG", "DDR SD", "DDR SG"

...

drivers/usb/misc/sisusbvga/sisusb.c sisusb_get_ramconfig(struct sisusb_usb_data *sisusb) · line 2160

Quoted 3 lines
(quoted diff) +0 -1
-	dev_info(&sisusb->sisusb_dev->dev, "%dMB %s %s, bus width %d\n", (sisusb->vramsize >> 20),

ramtypetext1,

drivers/usb/misc/sisusbvga/sisusb.c +0 -1
-			ramtypetext2[ramtype], bw);
	dev_info(&sisusb->sisusb_dev->dev, "%dMB %s %sRAM, bus width %d\n",
		 sisusb->vramsize >> 20, ramtypetext1, ramtypetext2[ramtype],
		 bw);

	David
#2 lore raw
Quoted 5 lines · David Laight

From: Joe Perches

Quoted 1 line

Reduce text a bit by using static const.

If you want to save a few bytes remove the pointers. (and the fixed RAM text to get below 7 chars).

Hi David.

Quoted 4 lines

eg:

Review

Quoted 2 lines
(quoted diff) +0 -2
-	const char *ramtypetext2[] = {	"SDR SDRAM", "SDR SGRAM",
-					"DDR SDRAM", "DDR SGRAM" };

The idea was use static to avoid the array reload
on each function entry.

Quoted 2 lines
	static const char ramtypetext2[8][] = {
		"SDR SD", "SDR SG", "DDR SD", "DDR SG"

8 is an odd number here.

That could be done with char like:

	static const char ram_datarate[4] = {'S', 'S', 'D', 'D'};
	static const char ram_dynamictype[4] = {'D', 'G', 'D', 'G'};
Quoted 8 lines

...

Review

Quoted 3 lines
(quoted diff) +0 -1
-	dev_info(&sisusb->sisusb_dev->dev, "%dMB %s %s, bus width %d\n", (sisusb->vramsize >> 20),

ramtypetext1,

(quoted diff) +0 -1
-			ramtypetext2[ramtype], bw);
	dev_info(&sisusb->sisusb_dev->dev, "%dMB %s %sRAM, bus width %d\n",
		 sisusb->vramsize >> 20, ramtypetext1, ramtypetext2[ramtype],
		 bw);
	dev_info(&sisusb->sisusb_dev->dev, "%dMB %s %c%cRAM, bus width %d\n",
		 sisusb->vramsize >> 20, ramtypetext1,
		 ram_datarate[ramtype], ram_dynamictype[ramtype], bw);

So something like:

Convert 1 char * array to 2 char arrays to reduce size. Use static const to avoid array reloads on function entry. Fix asymmetric typo.

$ size drivers/usb/misc/sisusbvga/sisusb.o*
   text	   data	    bss	    dec	    hex	filename
  29971	   4841	   9180	  43992	   abd8	drivers/usb/misc/sisusbvga/sisusb.o.new
  30083	   4841	   9180	  44104	   ac48	drivers/usb/misc/sisusbvga/sisusb.o.old
---
 drivers/usb/misc/sisusbvga/sisusb.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/usb/misc/sisusbvga/sisusb.c +6 -4
index de98906..06b5d77 100644
@@ -2123,8 +2123,8 @@ sisusb_get_ramconfig(struct sisusb_usb_data *sisusb)
 	u8 tmp8, tmp82, ramtype;
 	int bw = 0;
 	char *ramtypetext1 = NULL;
-	const char *ramtypetext2[] = {	"SDR SDRAM", "SDR SGRAM",
-					"DDR SDRAM", "DDR SGRAM" };
+	static const char ram_datarate[4] = {'S', 'S', 'D', 'D'};
+	static const char ram_dynamictype[4] = {'D', 'G', 'D', 'G'};
 	static const int busSDR[4]  = {64, 64, 128, 128};
 	static const int busDDR[4]  = {32, 32,  64,  64};
 	static const int busDDRA[4] = {64+32, 64+32 , (64+32)*2, (64+32)*2};
@@ -2156,8 +2156,10 @@ sisusb_get_ramconfig(struct sisusb_usb_data *sisusb)
 		break;
 	}
 
-	dev_info(&sisusb->sisusb_dev->dev, "%dMB %s %s, bus width %d\n", (sisusb->vramsize >> 20), ramtypetext1,
-			ramtypetext2[ramtype], bw);
+
+	dev_info(&sisusb->sisusb_dev->dev, "%dMB %s %cDR S%cRAM, bus width %d\n",
+		 sisusb->vramsize >> 20, ramtypetext1,
+		 ram_datarate[ramtype], ram_dynamictype[ramtype], bw);
 }
 
 static int
#3 lore raw

From: Joe Perches [

Quoted 17 lines · David Laight
Quoted 5 lines

From: Joe Perches

Quoted 1 line

Reduce text a bit by using static const.

If you want to save a few bytes remove the pointers. (and the fixed RAM text to get below 7 chars).

Hi David.

Quoted 4 lines

eg:

drivers/usb/misc/sisusbvga/sisusb.c sisusb_get_ramconfig(struct sisusb_usb_data *sisusb) · line 2127

Quoted 2 lines
drivers/usb/misc/sisusbvga/sisusb.c +0 -2
-	const char *ramtypetext2[] = {	"SDR SDRAM", "SDR SGRAM",
-					"DDR SDRAM", "DDR SGRAM" };

The idea was use static to avoid the array reload
on each function entry.

Quoted 4 lines
Quoted 2 lines
	static const char ramtypetext2[8][] = {
		"SDR SD", "SDR SG", "DDR SD", "DDR SG"

8 is an odd number here.

Brain fade - not enough coffee.
I meant 'char ramtypetext2[][8]' so that you avoid the pointers as well.

David