public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Florian Fainelli <f.fainelli@gmail•com>
To: Ben Hutchings <ben@decadent•org.uk>, netdev@vger•kernel.org
Cc: davem@davemloft•net, zajec5@gmail•com, nbd@nbd•name,
	hauke@hauke-m•de, jon.mason@broadcom•com
Subject: Re: [PATCH net-next 2/2] bgmac: Add support for ethtool statistics
Date: Fri, 3 Jun 2016 11:10:10 -0700	[thread overview]
Message-ID: <5751C802.1050008@gmail.com> (raw)
In-Reply-To: <1464976668.2847.117.camel@decadent.org.uk>

On 06/03/2016 10:57 AM, Ben Hutchings wrote:
> On Fri, 2016-06-03 at 10:07 -0700, Florian Fainelli wrote:
> [...]
>> +static void bgmac_get_strings(struct net_device *dev, u32 stringset,
>> +			      u8 *data)
>> +{
>> +	int i;
>> +
>> +	if (stringset != ETH_SS_STATS)
>> +		return;
>> +
>> +	for (i = 0; i < BGMAC_STATS_LEN; i++)
>> +		memcpy(data + i * ETH_GSTRING_LEN,
>> +		       bgmac_get_strings_stats[i].name,
>> +		       ETH_GSTRING_LEN);
> 
> These strings are null-terminated, not padded to ETH_GSTRING_LEN.  So
> here you should be using strlcpy() instead of memcpy().
> 
>> +}
>> +
>> +static void bgmac_get_ethtool_stats(struct net_device *dev,
>> +				    struct ethtool_stats *ss, uint64_t *data)
>> +{
>> +	struct bgmac *bgmac = netdev_priv(dev);
>> +	const struct bgmac_stat *s;
>> +	unsigned int i;
>> +	u64 val;
>> +
>> +	if (!netif_running(dev))
>> +		return;
>> +
>> +	for (i = 0; i < BGMAC_STATS_LEN; i++) {
>> +		s = &bgmac_get_strings_stats[i];
>> +		val = 0;
>> +		if (s->size == 8)
>> +			val = (u64)bgmac_read(bgmac, s->offset + 4);
> 
> Isn't this missing a << 32?

It is, guess I should have made sure there was 4GB+ worth of traffic to
make sure this seemed reasonable.
> 
> Does reading the high 32 bits latch the value of the low 32 bits?  If
> not, you need to read the high bits again after the low bits and retry
> if they changed.

Yes these registers are latched.

> 
>> +		val |= bgmac_read(bgmac, s->offset);
>> +		data[i] = (u64)val;
> 
> Redundant cast.

Indeed, thanks.
-- 
Florian

      reply	other threads:[~2016-06-03 18:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-03 17:06 [PATCH net-next 0/2] net: bgmac: Misc improvements Florian Fainelli
2016-06-03 17:07 ` [PATCH net-next 1/2] bgmac: Bind net_device with backing device structure Florian Fainelli
2016-06-03 17:07 ` [PATCH net-next 2/2] bgmac: Add support for ethtool statistics Florian Fainelli
2016-06-03 17:57   ` Ben Hutchings
2016-06-03 18:10     ` Florian Fainelli [this message]

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=5751C802.1050008@gmail.com \
    --to=f.fainelli@gmail$(echo .)com \
    --cc=ben@decadent$(echo .)org.uk \
    --cc=davem@davemloft$(echo .)net \
    --cc=hauke@hauke-m$(echo .)de \
    --cc=jon.mason@broadcom$(echo .)com \
    --cc=nbd@nbd$(echo .)name \
    --cc=netdev@vger$(echo .)kernel.org \
    --cc=zajec5@gmail$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox