Skip to content

Commit 181bf1e

Browse files
Alan Coxtorvalds
authored andcommitted
parport_pc: clean up the modified while loops using for
And tidy up a few bits coding style detectors missed Signed-off-by: Alan Cox <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 3aeda9b commit 181bf1e

File tree

1 file changed

+57
-41
lines changed

1 file changed

+57
-41
lines changed

drivers/parport/parport_pc.c

Lines changed: 57 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ static size_t parport_pc_fifo_write_block_dma(struct parport *port,
626626
unsigned long start = (unsigned long) buf;
627627
unsigned long end = (unsigned long) buf + length - 1;
628628

629-
dump_parport_state("enter fifo_write_block_dma", port);
629+
dump_parport_state("enter fifo_write_block_dma", port);
630630
if (end < MAX_DMA_ADDRESS) {
631631
/* If it would cross a 64k boundary, cap it at the end. */
632632
if ((start ^ end) & ~0xffffUL)
@@ -737,7 +737,7 @@ dump_parport_state("enter fifo_write_block_dma", port);
737737
if (dma_handle)
738738
dma_unmap_single(dev, dma_handle, length, DMA_TO_DEVICE);
739739

740-
dump_parport_state("leave fifo_write_block_dma", port);
740+
dump_parport_state("leave fifo_write_block_dma", port);
741741
return length - left;
742742
}
743743
#endif
@@ -955,8 +955,8 @@ static size_t parport_pc_ecp_read_block_pio(struct parport *port,
955955
char *bufp = buf;
956956

957957
port = port->physport;
958-
DPRINTK(KERN_DEBUG "parport_pc: parport_pc_ecp_read_block_pio\n");
959-
dump_parport_state("enter fcn", port);
958+
DPRINTK(KERN_DEBUG "parport_pc: parport_pc_ecp_read_block_pio\n");
959+
dump_parport_state("enter fcn", port);
960960

961961
/* Special case: a timeout of zero means we cannot call schedule().
962962
* Also if O_NONBLOCK is set then use the default implementation. */
@@ -1112,14 +1112,15 @@ dump_parport_state("enter fcn", port);
11121112

11131113
if (ecrval & 0x02) {
11141114
/* FIFO is full. */
1115-
dump_parport_state("FIFO full", port);
1115+
dump_parport_state("FIFO full", port);
11161116
insb(fifo, bufp, fifo_depth);
11171117
bufp += fifo_depth;
11181118
left -= fifo_depth;
11191119
continue;
11201120
}
11211121

1122-
DPRINTK(KERN_DEBUG "*** ecp_read_block_pio: reading one byte from the FIFO\n");
1122+
DPRINTK(KERN_DEBUG
1123+
"*** ecp_read_block_pio: reading one byte from the FIFO\n");
11231124

11241125
/* FIFO not filled. We will cycle this loop for a while
11251126
* and either the peripheral will fill it faster,
@@ -1135,7 +1136,7 @@ DPRINTK(KERN_DEBUG "*** ecp_read_block_pio: reading one byte from the FIFO\n");
11351136
}
11361137

11371138
port->ieee1284.phase = IEEE1284_PH_REV_IDLE;
1138-
dump_parport_state("rev idle2", port);
1139+
dump_parport_state("rev idle2", port);
11391140

11401141
out_no_data:
11411142

@@ -1163,7 +1164,7 @@ dump_parport_state("rev idle2", port);
11631164
port->name, lost);
11641165
}
11651166

1166-
dump_parport_state("fwd idle", port);
1167+
dump_parport_state("fwd idle", port);
11671168
return length - left;
11681169
}
11691170
#endif /* 0 */
@@ -1216,10 +1217,23 @@ static const struct parport_operations parport_pc_ops = {
12161217
};
12171218

12181219
#ifdef CONFIG_PARPORT_PC_SUPERIO
1220+
1221+
static struct superio_struct *find_free_superio(void)
1222+
{
1223+
int i;
1224+
for (i = 0; i < NR_SUPERIOS; i++)
1225+
if (superios[i].io == 0)
1226+
return &superios[i];
1227+
return NULL;
1228+
}
1229+
1230+
12191231
/* Super-IO chipset detection, Winbond, SMSC */
12201232
static void __devinit show_parconfig_smsc37c669(int io, int key)
12211233
{
1222-
int cr1, cr4, cra, cr23, cr26, cr27, i = 0;
1234+
int cr1, cr4, cra, cr23, cr26, cr27;
1235+
struct superio_struct *s;
1236+
12231237
static const char *const modes[] = {
12241238
"SPP and Bidirectional (PS/2)",
12251239
"EPP and SPP",
@@ -1272,38 +1286,38 @@ static void __devinit show_parconfig_smsc37c669(int io, int key)
12721286
are related, however DMA can be 1 or 3, assume DMA_A=DMA1,
12731287
DMA_C=DMA3 (this is true e.g. for TYAN 1564D Tomcat IV) */
12741288
if (cr23 * 4 >= 0x100) { /* if active */
1275-
while ((i < NR_SUPERIOS) && (superios[i].io != 0))
1276-
i++;
1277-
if (i == NR_SUPERIOS) {
1289+
s = find_free_superio();
1290+
if (s == NULL)
12781291
printk(KERN_INFO "Super-IO: too many chips!\n");
1279-
} else {
1292+
else {
12801293
int d;
12811294
switch (cr23 * 4) {
12821295
case 0x3bc:
1283-
superios[i].io = 0x3bc;
1284-
superios[i].irq = 7;
1296+
s->io = 0x3bc;
1297+
s->irq = 7;
12851298
break;
12861299
case 0x378:
1287-
superios[i].io = 0x378;
1288-
superios[i].irq = 7;
1300+
s->io = 0x378;
1301+
s->irq = 7;
12891302
break;
12901303
case 0x278:
1291-
superios[i].io = 0x278;
1292-
superios[i].irq = 5;
1304+
s->io = 0x278;
1305+
s->irq = 5;
12931306
}
12941307
d = (cr26 & 0x0f);
12951308
if (d == 1 || d == 3)
1296-
superios[i].dma = d;
1309+
s->dma = d;
12971310
else
1298-
superios[i].dma = PARPORT_DMA_NONE;
1311+
s->dma = PARPORT_DMA_NONE;
12991312
}
13001313
}
13011314
}
13021315

13031316

13041317
static void __devinit show_parconfig_winbond(int io, int key)
13051318
{
1306-
int cr30, cr60, cr61, cr70, cr74, crf0, i = 0;
1319+
int cr30, cr60, cr61, cr70, cr74, crf0;
1320+
struct superio_struct *s;
13071321
static const char *const modes[] = {
13081322
"Standard (SPP) and Bidirectional(PS/2)", /* 0 */
13091323
"EPP-1.9 and SPP",
@@ -1356,14 +1370,13 @@ static void __devinit show_parconfig_winbond(int io, int key)
13561370
}
13571371

13581372
if (cr30 & 0x01) { /* the settings can be interrogated later ... */
1359-
while ((i < NR_SUPERIOS) && (superios[i].io != 0))
1360-
i++;
1361-
if (i == NR_SUPERIOS) {
1373+
s = find_free_superio();
1374+
if (s == NULL)
13621375
printk(KERN_INFO "Super-IO: too many chips!\n");
1363-
} else {
1364-
superios[i].io = (cr60<<8)|cr61;
1365-
superios[i].irq = cr70&0x0f;
1366-
superios[i].dma = (((cr74 & 0x07) > 3) ?
1376+
else {
1377+
s->io = (cr60 << 8) | cr61;
1378+
s->irq = cr70 & 0x0f;
1379+
s->dma = (((cr74 & 0x07) > 3) ?
13671380
PARPORT_DMA_NONE : (cr74 & 0x07));
13681381
}
13691382
}
@@ -1618,25 +1631,28 @@ static void __devinit detect_and_report_it87(void)
16181631
}
16191632
#endif /* CONFIG_PARPORT_PC_SUPERIO */
16201633

1621-
static int get_superio_dma(struct parport *p)
1634+
static struct superio_struct *find_superio(struct parport *p)
16221635
{
1623-
int i = 0;
1636+
int i;
1637+
for (i = 0; i < NR_SUPERIOS; i++)
1638+
if (superios[i].io != p->base)
1639+
return &superios[i];
1640+
return NULL;
1641+
}
16241642

1625-
while ((i < NR_SUPERIOS) && (superios[i].io != p->base))
1626-
i++;
1627-
if (i != NR_SUPERIOS)
1628-
return superios[i].dma;
1643+
static int get_superio_dma(struct parport *p)
1644+
{
1645+
struct superio_struct *s = find_superio(p);
1646+
if (s)
1647+
return s->dma;
16291648
return PARPORT_DMA_NONE;
16301649
}
16311650

16321651
static int get_superio_irq(struct parport *p)
16331652
{
1634-
int i = 0;
1635-
1636-
while ((i < NR_SUPERIOS) && (superios[i].io != p->base))
1637-
i++;
1638-
if (i != NR_SUPERIOS)
1639-
return superios[i].irq;
1653+
struct superio_struct *s = find_superio(p);
1654+
if (s)
1655+
return s->irq;
16401656
return PARPORT_IRQ_NONE;
16411657
}
16421658

0 commit comments

Comments
 (0)