Re: [PATCH] add sysfs attribute 'carrier' for net devices

From: Paulo Marques
Date: Tue Sep 28 2004 - 07:12:56 EST


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@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/