lkml.org 
[lkml]   [2004]   [Sep]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] add sysfs attribute 'carrier' for net devices
Stephen Hemminger wrote:
> ....
>>+{
>>+ struct net_device *net = to_net_dev(dev);
>>+ if (netif_running(net)) {
>>+ if (netif_carrier_ok(net))
>>+ return snprintf(buf, 3, "%d\n", 1);
>>+ else
>>+ return snprintf(buf, 3, "%d\n", 0);
>
>
> Using snprintf in this way is kind of silly. since buffer is PAGESIZE.
> The most concise format of this would be:
> return sprintf(buf, dec_fmt, !!netif_carrier_ok(dev));

<nitpick>
Since netif_carrier_ok already has a "!" in it, it is guaranteed to
return a 0 / 1 result. so this could be:

return sprintf(buf, dec_fmt, netif_carrier_ok(dev));

Of course your way is more robust to future 'netif_carrier_ok' changes
and the compiler should optimize it way anyway since it is an inline
function, so I actually prefer the !! version :)
</nitpick>

--
Paulo Marques - www.grupopie.com

To err is human, but to really foul things up requires a computer.
Farmers' Almanac, 1978
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:06    [W:0.151 / U:0.172 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site