Re: [PATCH 2.6.19] e1000: replace kmalloc with kzalloc

2006-12-17 Thread Ingo Oeser
On Tuesday, 12. December 2006 18:34, Pekka Enberg wrote:
> On 12/12/06, Yan Burman <[EMAIL PROTECTED]> wrote:
> > size = txdr->count * sizeof(struct e1000_buffer);
> > -   if (!(txdr->buffer_info = kmalloc(size, GFP_KERNEL))) {
> > +   if (!(txdr->buffer_info = kzalloc(size, GFP_KERNEL))) {
> > ret_val = 1;
> > goto err_nomem;
> > }
> > -   memset(txdr->buffer_info, 0, size);
> 
> No one seems to be using size elsewhere so why not convert to
> kcalloc() and get rid of it? (Seems to apply to other places as well.)

Because if done properly that often exceeds the 80 column limit.
The intermediate variable should be optimized away from the compiler.

But kcalloc() is better for another reason: Overflow checking.

Regards

Ingo Oeser
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2.6.19] e1000: replace kmalloc with kzalloc

2006-12-17 Thread Ingo Oeser
On Tuesday, 12. December 2006 18:34, Pekka Enberg wrote:
 On 12/12/06, Yan Burman [EMAIL PROTECTED] wrote:
  size = txdr-count * sizeof(struct e1000_buffer);
  -   if (!(txdr-buffer_info = kmalloc(size, GFP_KERNEL))) {
  +   if (!(txdr-buffer_info = kzalloc(size, GFP_KERNEL))) {
  ret_val = 1;
  goto err_nomem;
  }
  -   memset(txdr-buffer_info, 0, size);
 
 No one seems to be using size elsewhere so why not convert to
 kcalloc() and get rid of it? (Seems to apply to other places as well.)

Because if done properly that often exceeds the 80 column limit.
The intermediate variable should be optimized away from the compiler.

But kcalloc() is better for another reason: Overflow checking.

Regards

Ingo Oeser
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2.6.19] e1000: replace kmalloc with kzalloc

2006-12-12 Thread Auke Kok

Pekka Enberg wrote:

On 12/12/06, Yan Burman <[EMAIL PROTECTED]> wrote:

size = txdr->count * sizeof(struct e1000_buffer);
-   if (!(txdr->buffer_info = kmalloc(size, GFP_KERNEL))) {
+   if (!(txdr->buffer_info = kzalloc(size, GFP_KERNEL))) {
ret_val = 1;
goto err_nomem;
}
-   memset(txdr->buffer_info, 0, size);


No one seems to be using size elsewhere so why not convert to
kcalloc() and get rid of it? (Seems to apply to other places as well.)


I'll put it on my todo list.

Auke
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2.6.19] e1000: replace kmalloc with kzalloc

2006-12-12 Thread Pekka Enberg

On 12/12/06, Yan Burman <[EMAIL PROTECTED]> wrote:

size = txdr->count * sizeof(struct e1000_buffer);
-   if (!(txdr->buffer_info = kmalloc(size, GFP_KERNEL))) {
+   if (!(txdr->buffer_info = kzalloc(size, GFP_KERNEL))) {
ret_val = 1;
goto err_nomem;
}
-   memset(txdr->buffer_info, 0, size);


No one seems to be using size elsewhere so why not convert to
kcalloc() and get rid of it? (Seems to apply to other places as well.)
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2.6.19] e1000: replace kmalloc with kzalloc

2006-12-12 Thread Yan Burman
Replace kmalloc+memset with kzalloc

Signed-off-by: Yan Burman <[EMAIL PROTECTED]>

diff -rubp linux-2.6.19-rc5_orig/drivers/net/e1000/e1000_ethtool.c 
linux-2.6.19-rc5_kzalloc/drivers/net/e1000/e1000_ethtool.c
--- linux-2.6.19-rc5_orig/drivers/net/e1000/e1000_ethtool.c 2006-11-09 
12:16:21.0 +0200
+++ linux-2.6.19-rc5_kzalloc/drivers/net/e1000/e1000_ethtool.c  2006-11-11 
22:44:04.0 +0200
@@ -1053,11 +1053,10 @@ e1000_setup_desc_rings(struct e1000_adap
txdr->count = E1000_DEFAULT_TXD;
 
size = txdr->count * sizeof(struct e1000_buffer);
-   if (!(txdr->buffer_info = kmalloc(size, GFP_KERNEL))) {
+   if (!(txdr->buffer_info = kzalloc(size, GFP_KERNEL))) {
ret_val = 1;
goto err_nomem;
}
-   memset(txdr->buffer_info, 0, size);
 
txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
E1000_ROUNDUP(txdr->size, 4096);
@@ -1109,11 +1108,10 @@ e1000_setup_desc_rings(struct e1000_adap
rxdr->count = E1000_DEFAULT_RXD;
 
size = rxdr->count * sizeof(struct e1000_buffer);
-   if (!(rxdr->buffer_info = kmalloc(size, GFP_KERNEL))) {
+   if (!(rxdr->buffer_info = kzalloc(size, GFP_KERNEL))) {
ret_val = 4;
goto err_nomem;
}
-   memset(rxdr->buffer_info, 0, size);
 
rxdr->size = rxdr->count * sizeof(struct e1000_rx_desc);
if (!(rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, >dma))) 
{
diff -rubp linux-2.6.19-rc5_orig/drivers/net/e1000/e1000_main.c 
linux-2.6.19-rc5_kzalloc/drivers/net/e1000/e1000_main.c
--- linux-2.6.19-rc5_orig/drivers/net/e1000/e1000_main.c2006-11-09 
12:16:21.0 +0200
+++ linux-2.6.19-rc5_kzalloc/drivers/net/e1000/e1000_main.c 2006-11-11 
22:44:26.0 +0200
@@ -1228,28 +1228,25 @@ e1000_alloc_queues(struct e1000_adapter 
int size;
 
size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
-   adapter->tx_ring = kmalloc(size, GFP_KERNEL);
+   adapter->tx_ring = kzalloc(size, GFP_KERNEL);
if (!adapter->tx_ring)
return -ENOMEM;
-   memset(adapter->tx_ring, 0, size);
 
size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
-   adapter->rx_ring = kmalloc(size, GFP_KERNEL);
+   adapter->rx_ring = kzalloc(size, GFP_KERNEL);
if (!adapter->rx_ring) {
kfree(adapter->tx_ring);
return -ENOMEM;
}
-   memset(adapter->rx_ring, 0, size);
 
 #ifdef CONFIG_E1000_NAPI
size = sizeof(struct net_device) * adapter->num_rx_queues;
-   adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
+   adapter->polling_netdev = kzalloc(size, GFP_KERNEL);
if (!adapter->polling_netdev) {
kfree(adapter->tx_ring);
kfree(adapter->rx_ring);
return -ENOMEM;
}
-   memset(adapter->polling_netdev, 0, size);
 #endif
 
return E1000_SUCCESS;
@@ -1626,17 +1623,16 @@ e1000_setup_rx_resources(struct e1000_ad
memset(rxdr->buffer_info, 0, size);
 
size = sizeof(struct e1000_ps_page) * rxdr->count;
-   rxdr->ps_page = kmalloc(size, GFP_KERNEL);
+   rxdr->ps_page = kzalloc(size, GFP_KERNEL);
if (!rxdr->ps_page) {
vfree(rxdr->buffer_info);
DPRINTK(PROBE, ERR,
"Unable to allocate memory for the receive descriptor ring\n");
return -ENOMEM;
}
-   memset(rxdr->ps_page, 0, size);
 
size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
-   rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
+   rxdr->ps_page_dma = kzalloc(size, GFP_KERNEL);
if (!rxdr->ps_page_dma) {
vfree(rxdr->buffer_info);
kfree(rxdr->ps_page);
@@ -1644,7 +1640,6 @@ e1000_setup_rx_resources(struct e1000_ad
"Unable to allocate memory for the receive descriptor ring\n");
return -ENOMEM;
}
-   memset(rxdr->ps_page_dma, 0, size);
 
if (adapter->hw.mac_type <= e1000_82547_rev_2)
desc_len = sizeof(struct e1000_rx_desc);



-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2.6.19] e1000: replace kmalloc with kzalloc

2006-12-12 Thread Yan Burman
Replace kmalloc+memset with kzalloc

Signed-off-by: Yan Burman [EMAIL PROTECTED]

diff -rubp linux-2.6.19-rc5_orig/drivers/net/e1000/e1000_ethtool.c 
linux-2.6.19-rc5_kzalloc/drivers/net/e1000/e1000_ethtool.c
--- linux-2.6.19-rc5_orig/drivers/net/e1000/e1000_ethtool.c 2006-11-09 
12:16:21.0 +0200
+++ linux-2.6.19-rc5_kzalloc/drivers/net/e1000/e1000_ethtool.c  2006-11-11 
22:44:04.0 +0200
@@ -1053,11 +1053,10 @@ e1000_setup_desc_rings(struct e1000_adap
txdr-count = E1000_DEFAULT_TXD;
 
size = txdr-count * sizeof(struct e1000_buffer);
-   if (!(txdr-buffer_info = kmalloc(size, GFP_KERNEL))) {
+   if (!(txdr-buffer_info = kzalloc(size, GFP_KERNEL))) {
ret_val = 1;
goto err_nomem;
}
-   memset(txdr-buffer_info, 0, size);
 
txdr-size = txdr-count * sizeof(struct e1000_tx_desc);
E1000_ROUNDUP(txdr-size, 4096);
@@ -1109,11 +1108,10 @@ e1000_setup_desc_rings(struct e1000_adap
rxdr-count = E1000_DEFAULT_RXD;
 
size = rxdr-count * sizeof(struct e1000_buffer);
-   if (!(rxdr-buffer_info = kmalloc(size, GFP_KERNEL))) {
+   if (!(rxdr-buffer_info = kzalloc(size, GFP_KERNEL))) {
ret_val = 4;
goto err_nomem;
}
-   memset(rxdr-buffer_info, 0, size);
 
rxdr-size = rxdr-count * sizeof(struct e1000_rx_desc);
if (!(rxdr-desc = pci_alloc_consistent(pdev, rxdr-size, rxdr-dma))) 
{
diff -rubp linux-2.6.19-rc5_orig/drivers/net/e1000/e1000_main.c 
linux-2.6.19-rc5_kzalloc/drivers/net/e1000/e1000_main.c
--- linux-2.6.19-rc5_orig/drivers/net/e1000/e1000_main.c2006-11-09 
12:16:21.0 +0200
+++ linux-2.6.19-rc5_kzalloc/drivers/net/e1000/e1000_main.c 2006-11-11 
22:44:26.0 +0200
@@ -1228,28 +1228,25 @@ e1000_alloc_queues(struct e1000_adapter 
int size;
 
size = sizeof(struct e1000_tx_ring) * adapter-num_tx_queues;
-   adapter-tx_ring = kmalloc(size, GFP_KERNEL);
+   adapter-tx_ring = kzalloc(size, GFP_KERNEL);
if (!adapter-tx_ring)
return -ENOMEM;
-   memset(adapter-tx_ring, 0, size);
 
size = sizeof(struct e1000_rx_ring) * adapter-num_rx_queues;
-   adapter-rx_ring = kmalloc(size, GFP_KERNEL);
+   adapter-rx_ring = kzalloc(size, GFP_KERNEL);
if (!adapter-rx_ring) {
kfree(adapter-tx_ring);
return -ENOMEM;
}
-   memset(adapter-rx_ring, 0, size);
 
 #ifdef CONFIG_E1000_NAPI
size = sizeof(struct net_device) * adapter-num_rx_queues;
-   adapter-polling_netdev = kmalloc(size, GFP_KERNEL);
+   adapter-polling_netdev = kzalloc(size, GFP_KERNEL);
if (!adapter-polling_netdev) {
kfree(adapter-tx_ring);
kfree(adapter-rx_ring);
return -ENOMEM;
}
-   memset(adapter-polling_netdev, 0, size);
 #endif
 
return E1000_SUCCESS;
@@ -1626,17 +1623,16 @@ e1000_setup_rx_resources(struct e1000_ad
memset(rxdr-buffer_info, 0, size);
 
size = sizeof(struct e1000_ps_page) * rxdr-count;
-   rxdr-ps_page = kmalloc(size, GFP_KERNEL);
+   rxdr-ps_page = kzalloc(size, GFP_KERNEL);
if (!rxdr-ps_page) {
vfree(rxdr-buffer_info);
DPRINTK(PROBE, ERR,
Unable to allocate memory for the receive descriptor ring\n);
return -ENOMEM;
}
-   memset(rxdr-ps_page, 0, size);
 
size = sizeof(struct e1000_ps_page_dma) * rxdr-count;
-   rxdr-ps_page_dma = kmalloc(size, GFP_KERNEL);
+   rxdr-ps_page_dma = kzalloc(size, GFP_KERNEL);
if (!rxdr-ps_page_dma) {
vfree(rxdr-buffer_info);
kfree(rxdr-ps_page);
@@ -1644,7 +1640,6 @@ e1000_setup_rx_resources(struct e1000_ad
Unable to allocate memory for the receive descriptor ring\n);
return -ENOMEM;
}
-   memset(rxdr-ps_page_dma, 0, size);
 
if (adapter-hw.mac_type = e1000_82547_rev_2)
desc_len = sizeof(struct e1000_rx_desc);



-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2.6.19] e1000: replace kmalloc with kzalloc

2006-12-12 Thread Pekka Enberg

On 12/12/06, Yan Burman [EMAIL PROTECTED] wrote:

size = txdr-count * sizeof(struct e1000_buffer);
-   if (!(txdr-buffer_info = kmalloc(size, GFP_KERNEL))) {
+   if (!(txdr-buffer_info = kzalloc(size, GFP_KERNEL))) {
ret_val = 1;
goto err_nomem;
}
-   memset(txdr-buffer_info, 0, size);


No one seems to be using size elsewhere so why not convert to
kcalloc() and get rid of it? (Seems to apply to other places as well.)
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2.6.19] e1000: replace kmalloc with kzalloc

2006-12-12 Thread Auke Kok

Pekka Enberg wrote:

On 12/12/06, Yan Burman [EMAIL PROTECTED] wrote:

size = txdr-count * sizeof(struct e1000_buffer);
-   if (!(txdr-buffer_info = kmalloc(size, GFP_KERNEL))) {
+   if (!(txdr-buffer_info = kzalloc(size, GFP_KERNEL))) {
ret_val = 1;
goto err_nomem;
}
-   memset(txdr-buffer_info, 0, size);


No one seems to be using size elsewhere so why not convert to
kcalloc() and get rid of it? (Seems to apply to other places as well.)


I'll put it on my todo list.

Auke
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/