mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Joe Perches <joe@perches.com>
Cc: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/4] net: mv643xx_eth: use kzalloc
Date: Wed, 09 Sep 2015 20:34:27 +0200	[thread overview]
Message-ID: <87r3m74f2k.fsf@rasmusvillemoes.dk> (raw)
In-Reply-To: <1441814431.17219.46.camel@perches.com> (Joe Perches's message of "Wed, 09 Sep 2015 09:00:31 -0700")

On Wed, Sep 09 2015, Joe Perches <joe@perches.com> wrote:

> On Wed, 2015-09-09 at 10:38 +0200, Rasmus Villemoes wrote:
>> The double memset is a little ugly; using kzalloc avoids it altogether.
> []
>> diff --git a/drivers/net/ethernet/marvell/mv643xx_eth.c b/drivers/net/ethernet/marvell/mv643xx_eth.c
> []
>> @@ -1859,14 +1859,11 @@ oom:
>>  		return;
>>  	}
>>  
>> -	mc_spec = kmalloc(0x200, GFP_ATOMIC);
>> +	mc_spec = kzalloc(0x200, GFP_ATOMIC);
>>  	if (mc_spec == NULL)
>>  		goto oom;
>>  	mc_other = mc_spec + (0x100 >> 2);
>
> This sure looks wrong as it sets a pointer
> to unallocated memory.
>
>> -	memset(mc_spec, 0, 0x100);
>> -	memset(mc_other, 0, 0x100);
>
> So this does a memset of random memory.
>

Huh? mc_spec and mc_other are u32*, we allocate 0x200 = 512 bytes = 128
u32s, and pointer arithmetic makes mc_other point to the latter 64. Then
the memory is cleared 256 bytes at a time.

It's unusual and slightly obfuscated code, but I don't think it's
wrong. 

>
> 	for (i = 0; i < 0x100; i += 4) {
> 		wrl(mp, SPECIAL_MCAST_TABLE(mp->port_num) + i, mc_spec[i >> 2]);
> 		wrl(mp, OTHER_MCAST_TABLE(mp->port_num) + i, mc_other[i >> 2]);
> 	}

I'd probably have written that as

for (i = 0; i < 64; ++i) {
	wrl(mp, SPECIAL_MCAST_TABLE(mp->port_num) + 4*i, mc_spec[i]);
	wrl(mp, OTHER_MCAST_TABLE(mp->port_num) + 4*i, mc_other[i]);
}

but again, I don't think it's wrong [haven't checked what
SPECIAL_MCAST_TABLE/OTHER_MCAST_TABLE do, though].

Rasmus

  reply	other threads:[~2015-09-09 18:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-09  8:38 [PATCH 0/4] net: a few kzalloc/memset cleanups Rasmus Villemoes
2015-09-09  8:38 ` [PATCH 1/4] net: cavium: liquidio: use kzalloc in setup_glist() Rasmus Villemoes
2015-09-09  8:38 ` [PATCH 2/4] net: jme: use kzalloc() instead of kmalloc+memset Rasmus Villemoes
2015-09-09  8:38 ` [PATCH 3/4] net: mv643xx_eth: use kzalloc Rasmus Villemoes
2015-09-09 16:00   ` Joe Perches
2015-09-09 18:34     ` Rasmus Villemoes [this message]
2015-09-09 18:45       ` Joe Perches
2015-09-09 23:25         ` Joe Perches
2015-09-09  8:38 ` [PATCH 4/4] net: qlcnic: delete redundant memsets Rasmus Villemoes
2015-09-10  0:06 ` [PATCH 0/4] net: a few kzalloc/memset cleanups David Miller
2015-09-10  0:40   ` [PATCH] mv643xx_eth: Neaten mv643xx_eth_program_multicast_filter Joe Perches
2015-09-15 19:49     ` David Miller

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=87r3m74f2k.fsf@rasmusvillemoes.dk \
    --to=linux@rasmusvillemoes.dk \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=sebastian.hesselbarth@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome