lkml.org 
[lkml]   [2008]   [Dec]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 02/27] drivers/net: fix sparse warnings: make do-while a compound statement
2008/12/22 Krzysztof Halasa <khc@pm.waw.pl>:
>> --- a/drivers/net/starfire.c
>> +++ b/drivers/net/starfire.c
>> @@ -882,9 +882,9 @@ static int mdio_read(struct net_device *dev, int phy_id, int location)
>> void __iomem *mdio_addr = np->base + MIICtrl + (phy_id<<7) + (location<<2);
>> int result, boguscnt=1000;
>> /* ??? Should we add a busy-wait here? */
>> - do
>> + do {
>> result = readl(mdio_addr);
>> - while ((result & 0xC0000000) != 0x80000000 && --boguscnt > 0);
>> + } while ((result & 0xC0000000) != 0x80000000 && --boguscnt > 0);
>> if (boguscnt == 0)
>> return 0;
>> if ((result & 0xffff) == 0xffff)
>
>
> I don't know how one could think the above is an improvement.

For this specific issue the important aspect is to improve readability
(and not just eventually satisfy some warning from a tool), which I
assume there is no disagrement on. Now what constitutes improved
readbility on the other hand is another issue, and I guess there are
next to as many oppinions as developers... :)
I would most certainly prefer to have code look consistently and always
have brackets, even in the case of just one body line.

Of secondary importance is the benefit that always using brackets
makes them much more merge friendly. Consider the following scenario:

Common base:
do
result = readl(mdio_addr);
while ((result & 0xC0000000) != 0x80000000 && --boguscnt > 0);

Branch 1
do {
result = readl(mdio_addr);
do_something();
} while ((result & 0xC0000000) != 0x80000000 && --boguscnt > 0);

Branch 2
do
result = readl(mdio_addr);
while (NOT_OK(result) && --boguscnt > 0);

In this case if both branch 1 and 2 are merged, there will be a merge conflict
that has to be resolved manually. If the brackets had been in place from the
start tools should be able to resolv this automatically.

BR Håkon Løvdal
\
 
 \ /
  Last update: 2008-12-23 00:47    [W:1.413 / U:1.692 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site