All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] net: a few kzalloc/memset cleanups
@ 2015-09-09  8:38 Rasmus Villemoes
  2015-09-09  8:38 ` [PATCH 1/4] net: cavium: liquidio: use kzalloc in setup_glist() Rasmus Villemoes
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Rasmus Villemoes @ 2015-09-09  8:38 UTC (permalink / raw)
  To: netdev; +Cc: Rasmus Villemoes, linux-kernel

These are just a few k[czm]alloc/memset related cleanups.

Rasmus Villemoes (4):
  net: cavium: liquidio: use kzalloc in setup_glist()
  net: jme: use kzalloc() instead of kmalloc+memset
  net: mv643xx_eth: use kzalloc
  net: qlcnic: delete redundant memsets

 drivers/net/ethernet/cavium/liquidio/lio_main.c          | 3 +--
 drivers/net/ethernet/jme.c                               | 8 ++------
 drivers/net/ethernet/marvell/mv643xx_eth.c               | 5 +----
 drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c      | 2 --
 drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c          | 2 --
 drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c | 2 --
 6 files changed, 4 insertions(+), 18 deletions(-)

-- 
2.1.3


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/4] net: cavium: liquidio: use kzalloc in setup_glist()
  2015-09-09  8:38 [PATCH 0/4] net: a few kzalloc/memset cleanups Rasmus Villemoes
@ 2015-09-09  8:38 ` Rasmus Villemoes
  2015-09-09  8:38 ` [PATCH 2/4] net: jme: use kzalloc() instead of kmalloc+memset Rasmus Villemoes
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: Rasmus Villemoes @ 2015-09-09  8:38 UTC (permalink / raw)
  To: Derek Chickles, Satanand Burla, Felix Manlunas, Raghu Vatsavayi
  Cc: Rasmus Villemoes, netdev, linux-kernel

We save a little .text and get rid of the sizeof(...) style
inconsistency.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 drivers/net/ethernet/cavium/liquidio/lio_main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/cavium/liquidio/lio_main.c b/drivers/net/ethernet/cavium/liquidio/lio_main.c
index 0660deecc2c9..f683d97d7614 100644
--- a/drivers/net/ethernet/cavium/liquidio/lio_main.c
+++ b/drivers/net/ethernet/cavium/liquidio/lio_main.c
@@ -818,10 +818,9 @@ static int setup_glist(struct lio *lio)
 	INIT_LIST_HEAD(&lio->glist);
 
 	for (i = 0; i < lio->tx_qsize; i++) {
-		g = kmalloc(sizeof(*g), GFP_KERNEL);
+		g = kzalloc(sizeof(*g), GFP_KERNEL);
 		if (!g)
 			break;
-		memset(g, 0, sizeof(struct octnic_gather));
 
 		g->sg_size =
 			((ROUNDUP4(OCTNIC_MAX_SG) >> 2) * OCT_SG_ENTRY_SIZE);
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/4] net: jme: use kzalloc() instead of kmalloc+memset
  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 ` Rasmus Villemoes
  2015-09-09  8:38 ` [PATCH 3/4] net: mv643xx_eth: use kzalloc Rasmus Villemoes
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: Rasmus Villemoes @ 2015-09-09  8:38 UTC (permalink / raw)
  To: Guo-Fu Tseng; +Cc: Rasmus Villemoes, netdev, linux-kernel

Using kzalloc saves a tiny bit on .text.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 drivers/net/ethernet/jme.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/jme.c b/drivers/net/ethernet/jme.c
index 6e9a792097d3..060dd3922974 100644
--- a/drivers/net/ethernet/jme.c
+++ b/drivers/net/ethernet/jme.c
@@ -583,7 +583,7 @@ jme_setup_tx_resources(struct jme_adapter *jme)
 	atomic_set(&txring->next_to_clean, 0);
 	atomic_set(&txring->nr_free, jme->tx_ring_size);
 
-	txring->bufinf		= kmalloc(sizeof(struct jme_buffer_info) *
+	txring->bufinf		= kzalloc(sizeof(struct jme_buffer_info) *
 					jme->tx_ring_size, GFP_ATOMIC);
 	if (unlikely(!(txring->bufinf)))
 		goto err_free_txring;
@@ -592,8 +592,6 @@ jme_setup_tx_resources(struct jme_adapter *jme)
 	 * Initialize Transmit Descriptors
 	 */
 	memset(txring->alloc, 0, TX_RING_ALLOC_SIZE(jme->tx_ring_size));
-	memset(txring->bufinf, 0,
-		sizeof(struct jme_buffer_info) * jme->tx_ring_size);
 
 	return 0;
 
@@ -845,7 +843,7 @@ jme_setup_rx_resources(struct jme_adapter *jme)
 	rxring->next_to_use	= 0;
 	atomic_set(&rxring->next_to_clean, 0);
 
-	rxring->bufinf		= kmalloc(sizeof(struct jme_buffer_info) *
+	rxring->bufinf		= kzalloc(sizeof(struct jme_buffer_info) *
 					jme->rx_ring_size, GFP_ATOMIC);
 	if (unlikely(!(rxring->bufinf)))
 		goto err_free_rxring;
@@ -853,8 +851,6 @@ jme_setup_rx_resources(struct jme_adapter *jme)
 	/*
 	 * Initiallize Receive Descriptors
 	 */
-	memset(rxring->bufinf, 0,
-		sizeof(struct jme_buffer_info) * jme->rx_ring_size);
 	for (i = 0 ; i < jme->rx_ring_size ; ++i) {
 		if (unlikely(jme_make_new_rx_buf(jme, i))) {
 			jme_free_rx_resources(jme);
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/4] net: mv643xx_eth: use kzalloc
  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 ` Rasmus Villemoes
  2015-09-09 16:00   ` 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
  4 siblings, 1 reply; 12+ messages in thread
From: Rasmus Villemoes @ 2015-09-09  8:38 UTC (permalink / raw)
  To: Sebastian Hesselbarth; +Cc: Rasmus Villemoes, netdev, linux-kernel

The double memset is a little ugly; using kzalloc avoids it altogether.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 drivers/net/ethernet/marvell/mv643xx_eth.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mv643xx_eth.c b/drivers/net/ethernet/marvell/mv643xx_eth.c
index d52639bc491f..960169efe636 100644
--- 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);
 
-	memset(mc_spec, 0, 0x100);
-	memset(mc_other, 0, 0x100);
-
 	netdev_for_each_mc_addr(ha, dev) {
 		u8 *a = ha->addr;
 		u32 *table;
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 4/4] net: qlcnic: delete redundant memsets
  2015-09-09  8:38 [PATCH 0/4] net: a few kzalloc/memset cleanups Rasmus Villemoes
                   ` (2 preceding siblings ...)
  2015-09-09  8:38 ` [PATCH 3/4] net: mv643xx_eth: use kzalloc Rasmus Villemoes
@ 2015-09-09  8:38 ` Rasmus Villemoes
  2015-09-10  0:06 ` [PATCH 0/4] net: a few kzalloc/memset cleanups David Miller
  4 siblings, 0 replies; 12+ messages in thread
From: Rasmus Villemoes @ 2015-09-09  8:38 UTC (permalink / raw)
  To: Shahed Shaikh, Dept-GELinuxNICDev; +Cc: Rasmus Villemoes, netdev, linux-kernel

In all cases, mbx->req.arg and mbx->rsp.arg have just been allocated
using kcalloc(), so these six memsets are redundant.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
I cranked $context_lines to 11 to make the kcallocs visible.

 drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c      | 2 --
 drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c          | 2 --
 drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c | 2 --
 3 files changed, 6 deletions(-)

diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c
index 5ab3adf88166..9f0bdd993955 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c
@@ -910,24 +910,22 @@ int qlcnic_83xx_alloc_mbx_args(struct qlcnic_cmd_args *mbx,
 			mbx->req.arg = kcalloc(mbx->req.num, sizeof(u32),
 					       GFP_ATOMIC);
 			if (!mbx->req.arg)
 				return -ENOMEM;
 			mbx->rsp.arg = kcalloc(mbx->rsp.num, sizeof(u32),
 					       GFP_ATOMIC);
 			if (!mbx->rsp.arg) {
 				kfree(mbx->req.arg);
 				mbx->req.arg = NULL;
 				return -ENOMEM;
 			}
-			memset(mbx->req.arg, 0, sizeof(u32) * mbx->req.num);
-			memset(mbx->rsp.arg, 0, sizeof(u32) * mbx->rsp.num);
 			temp = adapter->ahw->fw_hal_version << 29;
 			mbx->req.arg[0] = (type | (mbx->req.num << 16) | temp);
 			mbx->cmd_op = type;
 			return 0;
 		}
 	}
 
 	dev_err(&adapter->pdev->dev, "%s: Invalid mailbox command opcode 0x%x\n",
 		__func__, type);
 	return -EINVAL;
 }
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
index 6e6f18fc5d76..a5f422f26cb4 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
@@ -65,24 +65,22 @@ int qlcnic_82xx_alloc_mbx_args(struct qlcnic_cmd_args *mbx,
 			mbx->req.arg = kcalloc(mbx->req.num,
 					       sizeof(u32), GFP_ATOMIC);
 			if (!mbx->req.arg)
 				return -ENOMEM;
 			mbx->rsp.arg = kcalloc(mbx->rsp.num,
 					       sizeof(u32), GFP_ATOMIC);
 			if (!mbx->rsp.arg) {
 				kfree(mbx->req.arg);
 				mbx->req.arg = NULL;
 				return -ENOMEM;
 			}
-			memset(mbx->req.arg, 0, sizeof(u32) * mbx->req.num);
-			memset(mbx->rsp.arg, 0, sizeof(u32) * mbx->rsp.num);
 			mbx->req.arg[0] = type;
 			break;
 		}
 	}
 	return 0;
 }
 
 /* Free up mailbox registers */
 void qlcnic_free_mbx_args(struct qlcnic_cmd_args *cmd)
 {
 	kfree(cmd->req.arg);
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c
index 546cd5f1c85a..7327b729ba2e 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c
@@ -721,24 +721,22 @@ static int qlcnic_sriov_alloc_bc_mbx_args(struct qlcnic_cmd_args *mbx, u32 type)
 			mbx->req.arg = kcalloc(mbx->req.num, sizeof(u32),
 					       GFP_ATOMIC);
 			if (!mbx->req.arg)
 				return -ENOMEM;
 			mbx->rsp.arg = kcalloc(mbx->rsp.num, sizeof(u32),
 					       GFP_ATOMIC);
 			if (!mbx->rsp.arg) {
 				kfree(mbx->req.arg);
 				mbx->req.arg = NULL;
 				return -ENOMEM;
 			}
-			memset(mbx->req.arg, 0, sizeof(u32) * mbx->req.num);
-			memset(mbx->rsp.arg, 0, sizeof(u32) * mbx->rsp.num);
 			mbx->req.arg[0] = (type | (mbx->req.num << 16) |
 					   (3 << 29));
 			mbx->rsp.arg[0] = (type & 0xffff) | mbx->rsp.num << 16;
 			return 0;
 		}
 	}
 	return -EINVAL;
 }
 
 static int qlcnic_sriov_prepare_bc_hdr(struct qlcnic_bc_trans *trans,
 				       struct qlcnic_cmd_args *cmd,
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 3/4] net: mv643xx_eth: use kzalloc
  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
  0 siblings, 1 reply; 12+ messages in thread
From: Joe Perches @ 2015-09-09 16:00 UTC (permalink / raw)
  To: Rasmus Villemoes; +Cc: Sebastian Hesselbarth, netdev, linux-kernel

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.

	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]);
	}



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 3/4] net: mv643xx_eth: use kzalloc
  2015-09-09 16:00   ` Joe Perches
@ 2015-09-09 18:34     ` Rasmus Villemoes
  2015-09-09 18:45       ` Joe Perches
  0 siblings, 1 reply; 12+ messages in thread
From: Rasmus Villemoes @ 2015-09-09 18:34 UTC (permalink / raw)
  To: Joe Perches; +Cc: Sebastian Hesselbarth, netdev, linux-kernel

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 3/4] net: mv643xx_eth: use kzalloc
  2015-09-09 18:34     ` Rasmus Villemoes
@ 2015-09-09 18:45       ` Joe Perches
  2015-09-09 23:25         ` Joe Perches
  0 siblings, 1 reply; 12+ messages in thread
From: Joe Perches @ 2015-09-09 18:45 UTC (permalink / raw)
  To: Rasmus Villemoes; +Cc: Sebastian Hesselbarth, netdev, linux-kernel

On Wed, 2015-09-09 at 20:34 +0200, Rasmus Villemoes wrote:
> 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. 

Right, misread.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 3/4] net: mv643xx_eth: use kzalloc
  2015-09-09 18:45       ` Joe Perches
@ 2015-09-09 23:25         ` Joe Perches
  0 siblings, 0 replies; 12+ messages in thread
From: Joe Perches @ 2015-09-09 23:25 UTC (permalink / raw)
  To: Rasmus Villemoes; +Cc: Sebastian Hesselbarth, netdev, linux-kernel

On Wed, 2015-09-09 at 11:45 -0700, Joe Perches wrote:
> On Wed, 2015-09-09 at 20:34 +0200, Rasmus Villemoes wrote:
> > 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. 

Perhaps this would make the code a bit clearer:

Use kcalloc, decimal sizes, decimal indexing,
and a promiscuous exit block using the same
style as the non-promiscuous multicast block.
---
  drivers/net/ethernet/marvell/mv643xx_eth.c | 46 ++++++++++++++----------------
 1 file changed, 22 insertions(+), 24 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mv643xx_eth.c b/drivers/net/ethernet/marvell/mv643xx_eth.c
index d52639b..9230ed5 100644
--- a/drivers/net/ethernet/marvell/mv643xx_eth.c
+++ b/drivers/net/ethernet/marvell/mv643xx_eth.c
@@ -1845,32 +1845,19 @@ static void mv643xx_eth_program_multicast_filter(struct net_device *dev)
 	struct netdev_hw_addr *ha;
 	int i;
 
-	if (dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) {
-		int port_num;
-		u32 accept;
+	if (dev->flags & (IFF_PROMISC | IFF_ALLMULTI))
+		goto promiscuous;
 
-oom:
-		port_num = mp->port_num;
-		accept = 0x01010101;
-		for (i = 0; i < 0x100; i += 4) {
-			wrl(mp, SPECIAL_MCAST_TABLE(port_num) + i, accept);
-			wrl(mp, OTHER_MCAST_TABLE(port_num) + i, accept);
-		}
-		return;
-	}
-
-	mc_spec = kmalloc(0x200, GFP_ATOMIC);
-	if (mc_spec == NULL)
-		goto oom;
-	mc_other = mc_spec + (0x100 >> 2);
-
-	memset(mc_spec, 0, 0x100);
-	memset(mc_other, 0, 0x100);
+	/* Allocate both mc_spec and mc_other tables */
+	mc_spec = kcalloc(128, sizeof(u32), GFP_ATOMIC);
+	if (!mc_spec)
+		goto promiscuous;
+	mc_other = &mc_spec[64];
 
 	netdev_for_each_mc_addr(ha, dev) {
 		u8 *a = ha->addr;
 		u32 *table;
-		int entry;
+		u8 entry;
 
 		if (memcmp(a, "\x01\x00\x5e\x00\x00", 5) == 0) {
 			table = mc_spec;
@@ -1883,12 +1870,23 @@ oom:
 		table[entry >> 2] |= 1 << (8 * (entry & 3));
 	}
 
-	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]);
+	for (i = 0; i < 64; i++) {
+		wrl(mp, SPECIAL_MCAST_TABLE(mp->port_num) + i * sizeof(u32),
+		    mc_spec[i]);
+		wrl(mp, OTHER_MCAST_TABLE(mp->port_num) + i * sizeof(u32),
+		    mc_other[i]);
 	}
 
 	kfree(mc_spec);
+	return;
+
+promiscuous:
+	for (i = 0; i < 64; i++) {
+		wrl(mp, SPECIAL_MCAST_TABLE(mp->port_num) + i * sizeof(u32),
+		    0x01010101u);
+		wrl(mp, OTHER_MCAST_TABLE(mp->port_num) + i * sizeof(u32),
+		    0x01010101u);
+	}
 }
 
 static void mv643xx_eth_set_rx_mode(struct net_device *dev)



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 0/4] net: a few kzalloc/memset cleanups
  2015-09-09  8:38 [PATCH 0/4] net: a few kzalloc/memset cleanups Rasmus Villemoes
                   ` (3 preceding siblings ...)
  2015-09-09  8:38 ` [PATCH 4/4] net: qlcnic: delete redundant memsets Rasmus Villemoes
@ 2015-09-10  0:06 ` David Miller
  2015-09-10  0:40   ` [PATCH] mv643xx_eth: Neaten mv643xx_eth_program_multicast_filter Joe Perches
  4 siblings, 1 reply; 12+ messages in thread
From: David Miller @ 2015-09-10  0:06 UTC (permalink / raw)
  To: linux; +Cc: netdev, linux-kernel

From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Date: Wed,  9 Sep 2015 10:38:01 +0200

> These are just a few k[czm]alloc/memset related cleanups.

Series applied, thanks.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH] mv643xx_eth: Neaten mv643xx_eth_program_multicast_filter
  2015-09-10  0:06 ` [PATCH 0/4] net: a few kzalloc/memset cleanups David Miller
@ 2015-09-10  0:40   ` Joe Perches
  2015-09-15 19:49     ` David Miller
  0 siblings, 1 reply; 12+ messages in thread
From: Joe Perches @ 2015-09-10  0:40 UTC (permalink / raw)
  To: David Miller; +Cc: linux, netdev, linux-kernel, Sebastian Hesselbarth

The code around the allocation and loops are a bit obfuscated.

Neaten it by using:

o kcalloc with decimal count and sizeof(u32)
o Decimal loop indexing and i++ not i += 4
o A promiscuous block using a similar style
  to the multicast block
o Remove unnecessary variables

Signed-off-by: Joe Perches <joe@perches.com>
---
Here's a neatening patch respun against Rasmus' patch
Might be useful.

 drivers/net/ethernet/marvell/mv643xx_eth.c | 43 +++++++++++++++---------------
 1 file changed, 22 insertions(+), 21 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mv643xx_eth.c b/drivers/net/ethernet/marvell/mv643xx_eth.c
index 960169e..c78ae18 100644
--- a/drivers/net/ethernet/marvell/mv643xx_eth.c
+++ b/drivers/net/ethernet/marvell/mv643xx_eth.c
@@ -1845,29 +1845,19 @@ static void mv643xx_eth_program_multicast_filter(struct net_device *dev)
 	struct netdev_hw_addr *ha;
 	int i;
 
-	if (dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) {
-		int port_num;
-		u32 accept;
+	if (dev->flags & (IFF_PROMISC | IFF_ALLMULTI))
+		goto promiscuous;
 
-oom:
-		port_num = mp->port_num;
-		accept = 0x01010101;
-		for (i = 0; i < 0x100; i += 4) {
-			wrl(mp, SPECIAL_MCAST_TABLE(port_num) + i, accept);
-			wrl(mp, OTHER_MCAST_TABLE(port_num) + i, accept);
-		}
-		return;
-	}
-
-	mc_spec = kzalloc(0x200, GFP_ATOMIC);
-	if (mc_spec == NULL)
-		goto oom;
-	mc_other = mc_spec + (0x100 >> 2);
+	/* Allocate both mc_spec and mc_other tables */
+	mc_spec = kcalloc(128, sizeof(u32), GFP_ATOMIC);
+	if (!mc_spec)
+		goto promiscuous;
+	mc_other = &mc_spec[64];
 
 	netdev_for_each_mc_addr(ha, dev) {
 		u8 *a = ha->addr;
 		u32 *table;
-		int entry;
+		u8 entry;
 
 		if (memcmp(a, "\x01\x00\x5e\x00\x00", 5) == 0) {
 			table = mc_spec;
@@ -1880,12 +1870,23 @@ oom:
 		table[entry >> 2] |= 1 << (8 * (entry & 3));
 	}
 
-	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]);
+	for (i = 0; i < 64; i++) {
+		wrl(mp, SPECIAL_MCAST_TABLE(mp->port_num) + i * sizeof(u32),
+		    mc_spec[i]);
+		wrl(mp, OTHER_MCAST_TABLE(mp->port_num) + i * sizeof(u32),
+		    mc_other[i]);
 	}
 
 	kfree(mc_spec);
+	return;
+
+promiscuous:
+	for (i = 0; i < 64; i++) {
+		wrl(mp, SPECIAL_MCAST_TABLE(mp->port_num) + i * sizeof(u32),
+		    0x01010101u);
+		wrl(mp, OTHER_MCAST_TABLE(mp->port_num) + i * sizeof(u32),
+		    0x01010101u);
+	}
 }
 
 static void mv643xx_eth_set_rx_mode(struct net_device *dev)



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] mv643xx_eth: Neaten mv643xx_eth_program_multicast_filter
  2015-09-10  0:40   ` [PATCH] mv643xx_eth: Neaten mv643xx_eth_program_multicast_filter Joe Perches
@ 2015-09-15 19:49     ` David Miller
  0 siblings, 0 replies; 12+ messages in thread
From: David Miller @ 2015-09-15 19:49 UTC (permalink / raw)
  To: joe; +Cc: linux, netdev, linux-kernel, sebastian.hesselbarth

From: Joe Perches <joe@perches.com>
Date: Wed, 09 Sep 2015 17:40:56 -0700

> The code around the allocation and loops are a bit obfuscated.
> 
> Neaten it by using:
> 
> o kcalloc with decimal count and sizeof(u32)
> o Decimal loop indexing and i++ not i += 4
> o A promiscuous block using a similar style
>   to the multicast block
> o Remove unnecessary variables
> 
> Signed-off-by: Joe Perches <joe@perches.com>

Applied.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2015-09-15 19:49 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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.