From: Edward Cree <ecree@solarflare.com>
To: David Laight <David.Laight@ACULAB.COM>
Cc: 'Shradha Shah' <sshah@solarflare.com>,
David Miller <davem@davemloft.net>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"linux-net-drivers@solarflare.com"
<linux-net-drivers@solarflare.com>
Subject: Re: [PATCH net-next 02/14] sfc: Add sysfs entry for flags (link control and primary)
Date: Fri, 29 May 2015 14:09:01 +0100 [thread overview]
Message-ID: <556864ED.1080408@solarflare.com> (raw)
In-Reply-To: <063D6719AE5E284EB5DD2968C1650D6D1CB42986@AcuExch.aculab.com>
On 29/05/15 11:48, David Laight wrote:
> From: Shradha Shah
>> Sent: 29 May 2015 11:01
>> On every adapter there will be one primary PF per adaptor and
>> one link control PF per port.
> ...
>> + return sprintf(buf, "%d\n",
>> + ((efx->mcdi->fn_flags) &
>> + (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
>> + ? 1 : 0);
> Horrid expression.
> Why not:
> (efx->mcdi->fn_flags >> MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL) & 1
I think the idea is that this is more explicit about what it's doing.
It's a toss-up which is more readable / idiomatic; I prefer the OP version.
(They probably compile to the same thing, though I haven't checked.)
> using sprintf() is also excessive. Maybe:
> *buf = '0' + (expression);
> return 1;
That loses the '\n'; it's annoying when you cat a file and it doesn't end in a '\n', because it gloms onto your shell prompt.
sprintf isn't really that expensive, this isn't likely to be called very frequently.
> You may also need to check for buffer overrun.
In fact Documentation/filesystems/sysfs.txt says that "show() should always use scnprintf()" and that "The buffer will always be PAGE_SIZE bytes in length."
So if we want to be consistent, it should be
return scnprintf(buf, PAGE_SIZE, "%d\n", expression);
although it'd be rather surprising if either 0\n or 1\n were ever too big for PAGE_SIZE :grin:.
next prev parent reply other threads:[~2015-05-29 13:09 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-29 9:59 [PATCH net-next 00/14] sfc: ndo_get_phys_port_id, vadaptor stats and PF unload when Vf's assigned to guest Shradha Shah
2015-05-29 10:01 ` [PATCH net-next 01/14] sfc: Add sysfs entry for physical port Shradha Shah
2015-06-01 0:32 ` David Miller
2015-05-29 10:01 ` [PATCH net-next 02/14] sfc: Add sysfs entry for flags (link control and primary) Shradha Shah
2015-05-29 10:48 ` David Laight
2015-05-29 13:09 ` Edward Cree [this message]
2015-05-29 10:01 ` [PATCH net-next 03/14] sfc: Implement ndo_gets_phys_port_id() for EF10 VFs Shradha Shah
2015-05-29 10:01 ` [PATCH net-next 04/14] sfc: add "port_" prefix to MAC stats Shradha Shah
2015-05-29 10:01 ` [PATCH net-next 05/14] sfc: set the port-id when calling MC_CMD_MAC_STATS Shradha Shah
2015-05-29 10:02 ` [PATCH net-next 06/14] sfc: display vadaptor statistics for all interfaces Shradha Shah
2015-05-29 10:02 ` [PATCH net-next 07/14] sfc: DMA the VF stats only when requested Shradha Shah
2015-05-29 10:02 ` [PATCH net-next 08/14] sfc: update netdevice statistics to use vadaptor stats Shradha Shah
2015-05-29 10:02 ` [PATCH net-next 09/14] sfc: suppress ENOENT error messages from MC_CMD_MAC_STATS Shradha Shah
2015-05-29 10:03 ` [PATCH net-next 11/14] sfc: don't update stats on VF when called in atomic context Shradha Shah
2015-05-29 10:03 ` [PATCH net-next 12/14] sfc: do not allow VFs to be destroyed if assigned to guests Shradha Shah
2015-05-29 10:03 ` [PATCH net-next 13/14] sfc: force removal of VF and vport on driver removal Shradha Shah
2015-05-29 10:03 ` [PATCH net-next 14/14] sfc: leak vports if a VF is assigned during PF unload Shradha Shah
2015-05-29 10:08 ` [PATCH net-next 10/14] sfc: suppress vadaptor stats when EVB is not present Shradha Shah
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=556864ED.1080408@solarflare.com \
--to=ecree@solarflare.com \
--cc=David.Laight@ACULAB.COM \
--cc=davem@davemloft.net \
--cc=linux-net-drivers@solarflare.com \
--cc=netdev@vger.kernel.org \
--cc=sshah@solarflare.com \
/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.