Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S267668AbUI1MKm (ORCPT ); Tue, 28 Sep 2004 08:10:42 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S267678AbUI1MKm (ORCPT ); Tue, 28 Sep 2004 08:10:42 -0400 Received: from [195.23.16.24] ([195.23.16.24]:35982 "EHLO bipbip.comserver-pie.com") by vger.kernel.org with ESMTP id S267668AbUI1MKf (ORCPT ); Tue, 28 Sep 2004 08:10:35 -0400 Message-ID: <415954AD.7010905@grupopie.com> Date: Tue, 28 Sep 2004 13:10:21 +0100 From: Paulo Marques Organization: Grupo PIE User-Agent: Mozilla Thunderbird 0.7.1 (X11/20040626) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Stephen Hemminger Cc: Jesper Juhl , linux-kernel , Nico Schottelius Subject: Re: [PATCH] add sysfs attribute 'carrier' for net devices References: <1096306153.1729.2.camel@localhost.localdomain> In-Reply-To: <1096306153.1729.2.camel@localhost.localdomain> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1174 Lines: 36 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)); 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 :) -- 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/