Skip to content

Commit caa97be

Browse files
Colin Ian Kinggregkh
authored andcommitted
char/mwave: make some arrays static const to make object code smaller
Don't populate arrays on the stack but make them static. Makes the object code smaller. Also remove temporary variables that have hard coded array sizes and just use ARRAY_SIZE instead and wrap some lines that are wider than 80 chars to clean up some checkpatch warnings. Before: text data bss dec hex filename 11141 2008 64 13213 339d drivers/char/mwave/smapi.o After: text data bss dec hex filename 10697 2352 64 13113 3339 drivers/char/mwave/smapi.o Signed-off-by: Colin Ian King <colin.king@canonical.com> Acked-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2dee584 commit caa97be

1 file changed

Lines changed: 25 additions & 23 deletions

File tree

‎drivers/char/mwave/smapi.c‎

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,11 @@ int smapi_query_DSP_cfg(SMAPI_DSP_SETTINGS * pSettings)
128128
{
129129
int bRC = -EIO;
130130
unsigned short usAX, usBX, usCX, usDX, usDI, usSI;
131-
unsigned short ausDspBases[] = { 0x0030, 0x4E30, 0x8E30, 0xCE30, 0x0130, 0x0350, 0x0070, 0x0DB0 };
132-
unsigned short ausUartBases[] = { 0x03F8, 0x02F8, 0x03E8, 0x02E8 };
133-
unsigned short numDspBases = 8;
134-
unsigned short numUartBases = 4;
131+
static const unsigned short ausDspBases[] = {
132+
0x0030, 0x4E30, 0x8E30, 0xCE30,
133+
0x0130, 0x0350, 0x0070, 0x0DB0 };
134+
static const unsigned short ausUartBases[] = {
135+
0x03F8, 0x02F8, 0x03E8, 0x02E8 };
135136

136137
PRINTK_1(TRACE_SMAPI, "smapi::smapi_query_DSP_cfg entry\n");
137138

@@ -148,7 +149,7 @@ int smapi_query_DSP_cfg(SMAPI_DSP_SETTINGS * pSettings)
148149
pSettings->bDSPEnabled = ((usCX & 0x0001) != 0);
149150
pSettings->usDspIRQ = usSI & 0x00FF;
150151
pSettings->usDspDMA = (usSI & 0xFF00) >> 8;
151-
if ((usDI & 0x00FF) < numDspBases) {
152+
if ((usDI & 0x00FF) < ARRAY_SIZE(ausDspBases)) {
152153
pSettings->usDspBaseIO = ausDspBases[usDI & 0x00FF];
153154
} else {
154155
pSettings->usDspBaseIO = 0;
@@ -176,7 +177,7 @@ int smapi_query_DSP_cfg(SMAPI_DSP_SETTINGS * pSettings)
176177

177178
pSettings->bModemEnabled = ((usCX & 0x0001) != 0);
178179
pSettings->usUartIRQ = usSI & 0x000F;
179-
if (((usSI & 0xFF00) >> 8) < numUartBases) {
180+
if (((usSI & 0xFF00) >> 8) < ARRAY_SIZE(ausUartBases)) {
180181
pSettings->usUartBaseIO = ausUartBases[(usSI & 0xFF00) >> 8];
181182
} else {
182183
pSettings->usUartBaseIO = 0;
@@ -205,50 +206,51 @@ int smapi_set_DSP_cfg(void)
205206
int bRC = -EIO;
206207
int i;
207208
unsigned short usAX, usBX, usCX, usDX, usDI, usSI;
208-
unsigned short ausDspBases[] = { 0x0030, 0x4E30, 0x8E30, 0xCE30, 0x0130, 0x0350, 0x0070, 0x0DB0 };
209-
unsigned short ausUartBases[] = { 0x03F8, 0x02F8, 0x03E8, 0x02E8 };
210-
unsigned short ausDspIrqs[] = { 5, 7, 10, 11, 15 };
211-
unsigned short ausUartIrqs[] = { 3, 4 };
212-
213-
unsigned short numDspBases = 8;
214-
unsigned short numUartBases = 4;
215-
unsigned short numDspIrqs = 5;
216-
unsigned short numUartIrqs = 2;
209+
static const unsigned short ausDspBases[] = {
210+
0x0030, 0x4E30, 0x8E30, 0xCE30,
211+
0x0130, 0x0350, 0x0070, 0x0DB0 };
212+
static const unsigned short ausUartBases[] = {
213+
0x03F8, 0x02F8, 0x03E8, 0x02E8 };
214+
static const unsigned short ausDspIrqs[] = {
215+
5, 7, 10, 11, 15 };
216+
static const unsigned short ausUartIrqs[] = {
217+
3, 4 };
218+
217219
unsigned short dspio_index = 0, uartio_index = 0;
218220

219221
PRINTK_5(TRACE_SMAPI,
220222
"smapi::smapi_set_DSP_cfg entry mwave_3780i_irq %x mwave_3780i_io %x mwave_uart_irq %x mwave_uart_io %x\n",
221223
mwave_3780i_irq, mwave_3780i_io, mwave_uart_irq, mwave_uart_io);
222224

223225
if (mwave_3780i_io) {
224-
for (i = 0; i < numDspBases; i++) {
226+
for (i = 0; i < ARRAY_SIZE(ausDspBases); i++) {
225227
if (mwave_3780i_io == ausDspBases[i])
226228
break;
227229
}
228-
if (i == numDspBases) {
230+
if (i == ARRAY_SIZE(ausDspBases)) {
229231
PRINTK_ERROR(KERN_ERR_MWAVE "smapi::smapi_set_DSP_cfg: Error: Invalid mwave_3780i_io address %x. Aborting.\n", mwave_3780i_io);
230232
return bRC;
231233
}
232234
dspio_index = i;
233235
}
234236

235237
if (mwave_3780i_irq) {
236-
for (i = 0; i < numDspIrqs; i++) {
238+
for (i = 0; i < ARRAY_SIZE(ausDspIrqs); i++) {
237239
if (mwave_3780i_irq == ausDspIrqs[i])
238240
break;
239241
}
240-
if (i == numDspIrqs) {
242+
if (i == ARRAY_SIZE(ausDspIrqs)) {
241243
PRINTK_ERROR(KERN_ERR_MWAVE "smapi::smapi_set_DSP_cfg: Error: Invalid mwave_3780i_irq %x. Aborting.\n", mwave_3780i_irq);
242244
return bRC;
243245
}
244246
}
245247

246248
if (mwave_uart_io) {
247-
for (i = 0; i < numUartBases; i++) {
249+
for (i = 0; i < ARRAY_SIZE(ausUartBases); i++) {
248250
if (mwave_uart_io == ausUartBases[i])
249251
break;
250252
}
251-
if (i == numUartBases) {
253+
if (i == ARRAY_SIZE(ausUartBases)) {
252254
PRINTK_ERROR(KERN_ERR_MWAVE "smapi::smapi_set_DSP_cfg: Error: Invalid mwave_uart_io address %x. Aborting.\n", mwave_uart_io);
253255
return bRC;
254256
}
@@ -257,11 +259,11 @@ int smapi_set_DSP_cfg(void)
257259

258260

259261
if (mwave_uart_irq) {
260-
for (i = 0; i < numUartIrqs; i++) {
262+
for (i = 0; i < ARRAY_SIZE(ausUartIrqs); i++) {
261263
if (mwave_uart_irq == ausUartIrqs[i])
262264
break;
263265
}
264-
if (i == numUartIrqs) {
266+
if (i == ARRAY_SIZE(ausUartIrqs)) {
265267
PRINTK_ERROR(KERN_ERR_MWAVE "smapi::smapi_set_DSP_cfg: Error: Invalid mwave_uart_irq %x. Aborting.\n", mwave_uart_irq);
266268
return bRC;
267269
}

0 commit comments

Comments
 (0)