All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paulo Marques <pmarques@grupopie.com>
To: Stephen Hemminger <shemminger@osdl.org>
Cc: Jesper Juhl <juhl-lkml@dif.dk>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Nico Schottelius <nico-kernel@schottelius.org>
Subject: Re: [PATCH] add sysfs attribute 'carrier' for net devices
Date: Tue, 28 Sep 2004 13:10:21 +0100	[thread overview]
Message-ID: <415954AD.7010905@grupopie.com> (raw)
In-Reply-To: <1096306153.1729.2.camel@localhost.localdomain>

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

  parent reply	other threads:[~2004-09-28 12:10 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20041021112750.GN15294@schottelius.org>
     [not found] ` <Pine.LNX.4.61.0410221744500.15769@jjulnx.backbone.dif.dk>
2004-09-26 22:51   ` [PATCH] add sysfs attribute 'carrier' for net devices Jesper Juhl
2004-09-27 17:29     ` Stephen Hemminger
2004-09-28 11:18       ` Jesper Juhl
2004-09-28 19:23         ` [PATCH] add sysfs attribute 'carrier' for net devices - try 2 Jesper Juhl
2004-09-28 19:22           ` Stephen Hemminger
2004-09-28 20:54           ` Nico Schottelius
2004-09-28 22:24             ` Stephen Hemminger
2004-09-29  6:54               ` Nico Schottelius
2004-09-28 12:10       ` Paulo Marques [this message]
2004-09-28 16:09         ` [PATCH] add sysfs attribute 'carrier' for net devices Martin Waitz
2004-10-23 18:49           ` Nico Schottelius

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=415954AD.7010905@grupopie.com \
    --to=pmarques@grupopie.com \
    --cc=juhl-lkml@dif.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nico-kernel@schottelius.org \
    --cc=shemminger@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.