netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/22] Add and use pci_zalloc_consistent
@ 2014-06-23 13:41 Joe Perches
  2014-06-23 13:41 ` [PATCH 02/22] atm: Use pci_zalloc_consistent Joe Perches
                   ` (14 more replies)
  0 siblings, 15 replies; 33+ messages in thread
From: Joe Perches @ 2014-06-23 13:41 UTC (permalink / raw)
  To: linux-kernel
  Cc: devel, linux-arch, linux-scsi, iss_storagedev, linux-rdma, netdev,
	linux-atm-general, linux-wireless, dri-devel, linux-crypto,
	linux-eata, linux-media

Adding the helper reduces object code size as well as overall
source size line count.

It's also consistent with all the various zalloc mechanisms
in the kernel.

Done with a simple cocci script and some typing.

Joe Perches (22):
  pci-dma-compat: Add pci_zalloc_consistent helper
  atm: Use pci_zalloc_consistent
  block: Use pci_zalloc_consistent
  crypto: Use pci_zalloc_consistent
  infiniband: Use pci_zalloc_consistent
  i810: Use pci_zalloc_consistent
  media: Use pci_zalloc_consistent
  amd: Use pci_zalloc_consistent
  atl1e: Use pci_zalloc_consistent
  enic: Use pci_zalloc_consistent
  sky2: Use pci_zalloc_consistent
  micrel: Use pci_zalloc_consistent
  qlogic: Use pci_zalloc_consistent
  irda: Use pci_zalloc_consistent
  ipw2100: Use pci_zalloc_consistent
  mwl8k: Use pci_zalloc_consistent
  rtl818x: Use pci_zalloc_consistent
  rtlwifi: Use pci_zalloc_consistent
  scsi: Use pci_zalloc_consistent
  staging: Use pci_zalloc_consistent
  synclink_gt: Use pci_zalloc_consistent
  vme: bridges: Use pci_zalloc_consistent

 drivers/atm/he.c                                   | 31 ++++++++---------
 drivers/atm/idt77252.c                             | 15 ++++----
 drivers/block/DAC960.c                             | 18 +++++-----
 drivers/block/cciss.c                              | 11 +++---
 drivers/block/skd_main.c                           | 25 +++++---------
 drivers/crypto/hifn_795x.c                         |  5 ++-
 drivers/gpu/drm/i810/i810_dma.c                    |  5 ++-
 drivers/infiniband/hw/amso1100/c2.c                |  6 ++--
 drivers/infiniband/hw/nes/nes_hw.c                 | 12 +++----
 drivers/infiniband/hw/nes/nes_verbs.c              |  5 ++-
 drivers/media/common/saa7146/saa7146_core.c        | 15 ++++----
 drivers/media/common/saa7146/saa7146_fops.c        |  5 +--
 drivers/media/pci/bt8xx/bt878.c                    | 16 +++------
 drivers/media/pci/ngene/ngene-core.c               |  7 ++--
 drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c  | 11 ++----
 drivers/media/usb/ttusb-dec/ttusb_dec.c            | 11 ++----
 drivers/net/ethernet/amd/pcnet32.c                 | 16 ++++-----
 drivers/net/ethernet/atheros/atl1e/atl1e_main.c    |  7 ++--
 drivers/net/ethernet/cisco/enic/vnic_dev.c         |  8 ++---
 drivers/net/ethernet/marvell/sky2.c                |  5 ++-
 drivers/net/ethernet/micrel/ksz884x.c              |  7 ++--
 .../net/ethernet/qlogic/netxen/netxen_nic_ctx.c    |  4 +--
 drivers/net/ethernet/qlogic/qlge/qlge_main.c       | 11 +++---
 drivers/net/irda/vlsi_ir.c                         |  4 +--
 drivers/net/wireless/ipw2x00/ipw2100.c             | 16 +++------
 drivers/net/wireless/mwl8k.c                       |  6 ++--
 drivers/net/wireless/rtl818x/rtl8180/dev.c         | 11 +++---
 drivers/net/wireless/rtlwifi/pci.c                 | 17 +++------
 drivers/scsi/3w-sas.c                              |  5 ++-
 drivers/scsi/a100u2w.c                             |  8 ++---
 drivers/scsi/be2iscsi/be_main.c                    | 10 +++---
 drivers/scsi/be2iscsi/be_mgmt.c                    |  3 +-
 drivers/scsi/csiostor/csio_wr.c                    |  8 +----
 drivers/scsi/eata.c                                |  5 ++-
 drivers/scsi/hpsa.c                                |  8 ++---
 drivers/scsi/megaraid/megaraid_mbox.c              | 16 ++++-----
 drivers/scsi/megaraid/megaraid_sas_base.c          |  8 ++---
 drivers/scsi/mesh.c                                |  6 ++--
 drivers/scsi/mvumi.c                               |  9 ++---
 drivers/scsi/pm8001/pm8001_sas.c                   |  5 ++-
 drivers/staging/rtl8192e/rtl8192e/rtl_core.c       | 15 +++-----
 drivers/staging/rtl8192ee/pci.c                    | 37 +++++++-------------
 drivers/staging/rtl8821ae/pci.c                    | 36 +++++++------------
 drivers/staging/slicoss/slicoss.c                  |  9 ++---
 drivers/staging/vt6655/device_main.c               | 40 +++++++---------------
 drivers/tty/synclink_gt.c                          |  5 ++-
 drivers/vme/bridges/vme_ca91cx42.c                 |  6 ++--
 drivers/vme/bridges/vme_tsi148.c                   |  6 ++--
 include/asm-generic/pci-dma-compat.h               |  8 +++++
 49 files changed, 209 insertions(+), 354 deletions(-)

-- 
1.8.1.2.459.gbcd45b4.dirty

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

* [PATCH 02/22] atm: Use pci_zalloc_consistent
  2014-06-23 13:41 [PATCH 00/22] Add and use pci_zalloc_consistent Joe Perches
@ 2014-06-23 13:41 ` Joe Perches
  2014-06-23 13:41 ` [PATCH 08/22] amd: " Joe Perches
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 33+ messages in thread
From: Joe Perches @ 2014-06-23 13:41 UTC (permalink / raw)
  To: linux-kernel; +Cc: Chas Williams, linux-atm-general, netdev

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <joe@perches.com>
---
 drivers/atm/he.c       | 31 +++++++++++++++----------------
 drivers/atm/idt77252.c | 15 ++++++---------
 2 files changed, 21 insertions(+), 25 deletions(-)

diff --git a/drivers/atm/he.c b/drivers/atm/he.c
index aa6be26..c39702b 100644
--- a/drivers/atm/he.c
+++ b/drivers/atm/he.c
@@ -533,14 +533,13 @@ static void he_init_tx_lbfp(struct he_dev *he_dev)
 
 static int he_init_tpdrq(struct he_dev *he_dev)
 {
-	he_dev->tpdrq_base = pci_alloc_consistent(he_dev->pci_dev,
-		CONFIG_TPDRQ_SIZE * sizeof(struct he_tpdrq), &he_dev->tpdrq_phys);
+	he_dev->tpdrq_base = pci_zalloc_consistent(he_dev->pci_dev,
+						   CONFIG_TPDRQ_SIZE * sizeof(struct he_tpdrq),
+						   &he_dev->tpdrq_phys);
 	if (he_dev->tpdrq_base == NULL) {
 		hprintk("failed to alloc tpdrq\n");
 		return -ENOMEM;
 	}
-	memset(he_dev->tpdrq_base, 0,
-				CONFIG_TPDRQ_SIZE * sizeof(struct he_tpdrq));
 
 	he_dev->tpdrq_tail = he_dev->tpdrq_base;
 	he_dev->tpdrq_head = he_dev->tpdrq_base;
@@ -804,13 +803,13 @@ static int he_init_group(struct he_dev *he_dev, int group)
 		goto out_free_rbpl_virt;
 	}
 
-	he_dev->rbpl_base = pci_alloc_consistent(he_dev->pci_dev,
-		CONFIG_RBPL_SIZE * sizeof(struct he_rbp), &he_dev->rbpl_phys);
+	he_dev->rbpl_base = pci_zalloc_consistent(he_dev->pci_dev,
+						  CONFIG_RBPL_SIZE * sizeof(struct he_rbp),
+						  &he_dev->rbpl_phys);
 	if (he_dev->rbpl_base == NULL) {
 		hprintk("failed to alloc rbpl_base\n");
 		goto out_destroy_rbpl_pool;
 	}
-	memset(he_dev->rbpl_base, 0, CONFIG_RBPL_SIZE * sizeof(struct he_rbp));
 
 	INIT_LIST_HEAD(&he_dev->rbpl_outstanding);
 
@@ -843,13 +842,13 @@ static int he_init_group(struct he_dev *he_dev, int group)
 
 	/* rx buffer ready queue */
 
-	he_dev->rbrq_base = pci_alloc_consistent(he_dev->pci_dev,
-		CONFIG_RBRQ_SIZE * sizeof(struct he_rbrq), &he_dev->rbrq_phys);
+	he_dev->rbrq_base = pci_zalloc_consistent(he_dev->pci_dev,
+						  CONFIG_RBRQ_SIZE * sizeof(struct he_rbrq),
+						  &he_dev->rbrq_phys);
 	if (he_dev->rbrq_base == NULL) {
 		hprintk("failed to allocate rbrq\n");
 		goto out_free_rbpl;
 	}
-	memset(he_dev->rbrq_base, 0, CONFIG_RBRQ_SIZE * sizeof(struct he_rbrq));
 
 	he_dev->rbrq_head = he_dev->rbrq_base;
 	he_writel(he_dev, he_dev->rbrq_phys, G0_RBRQ_ST + (group * 16));
@@ -867,13 +866,13 @@ static int he_init_group(struct he_dev *he_dev, int group)
 
 	/* tx buffer ready queue */
 
-	he_dev->tbrq_base = pci_alloc_consistent(he_dev->pci_dev,
-		CONFIG_TBRQ_SIZE * sizeof(struct he_tbrq), &he_dev->tbrq_phys);
+	he_dev->tbrq_base = pci_zalloc_consistent(he_dev->pci_dev,
+						  CONFIG_TBRQ_SIZE * sizeof(struct he_tbrq),
+						  &he_dev->tbrq_phys);
 	if (he_dev->tbrq_base == NULL) {
 		hprintk("failed to allocate tbrq\n");
 		goto out_free_rbpq_base;
 	}
-	memset(he_dev->tbrq_base, 0, CONFIG_TBRQ_SIZE * sizeof(struct he_tbrq));
 
 	he_dev->tbrq_head = he_dev->tbrq_base;
 
@@ -1460,13 +1459,13 @@ static int he_start(struct atm_dev *dev)
 
 	/* host status page */
 
-	he_dev->hsp = pci_alloc_consistent(he_dev->pci_dev,
-				sizeof(struct he_hsp), &he_dev->hsp_phys);
+	he_dev->hsp = pci_zalloc_consistent(he_dev->pci_dev,
+					    sizeof(struct he_hsp),
+					    &he_dev->hsp_phys);
 	if (he_dev->hsp == NULL) {
 		hprintk("failed to allocate host status page\n");
 		return -ENOMEM;
 	}
-	memset(he_dev->hsp, 0, sizeof(struct he_hsp));
 	he_writel(he_dev, he_dev->hsp_phys, HSP_BA);
 
 	/* initialize framer */
diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
index b621f56..2b24ed0 100644
--- a/drivers/atm/idt77252.c
+++ b/drivers/atm/idt77252.c
@@ -641,13 +641,11 @@ alloc_scq(struct idt77252_dev *card, int class)
 	scq = kzalloc(sizeof(struct scq_info), GFP_KERNEL);
 	if (!scq)
 		return NULL;
-	scq->base = pci_alloc_consistent(card->pcidev, SCQ_SIZE,
-					 &scq->paddr);
+	scq->base = pci_zalloc_consistent(card->pcidev, SCQ_SIZE, &scq->paddr);
 	if (scq->base == NULL) {
 		kfree(scq);
 		return NULL;
 	}
-	memset(scq->base, 0, SCQ_SIZE);
 
 	scq->next = scq->base;
 	scq->last = scq->base + (SCQ_ENTRIES - 1);
@@ -972,13 +970,12 @@ init_rsq(struct idt77252_dev *card)
 {
 	struct rsq_entry *rsqe;
 
-	card->rsq.base = pci_alloc_consistent(card->pcidev, RSQSIZE,
-					      &card->rsq.paddr);
+	card->rsq.base = pci_zalloc_consistent(card->pcidev, RSQSIZE,
+					       &card->rsq.paddr);
 	if (card->rsq.base == NULL) {
 		printk("%s: can't allocate RSQ.\n", card->name);
 		return -1;
 	}
-	memset(card->rsq.base, 0, RSQSIZE);
 
 	card->rsq.last = card->rsq.base + RSQ_NUM_ENTRIES - 1;
 	card->rsq.next = card->rsq.last;
@@ -3400,14 +3397,14 @@ static int init_card(struct atm_dev *dev)
 	writel(0, SAR_REG_GP);
 
 	/* Initialize RAW Cell Handle Register  */
-	card->raw_cell_hnd = pci_alloc_consistent(card->pcidev, 2 * sizeof(u32),
-						  &card->raw_cell_paddr);
+	card->raw_cell_hnd = pci_zalloc_consistent(card->pcidev,
+						   2 * sizeof(u32),
+						   &card->raw_cell_paddr);
 	if (!card->raw_cell_hnd) {
 		printk("%s: memory allocation failure.\n", card->name);
 		deinit_card(card);
 		return -1;
 	}
-	memset(card->raw_cell_hnd, 0, 2 * sizeof(u32));
 	writel(card->raw_cell_paddr, SAR_REG_RAWHND);
 	IPRINTK("%s: raw cell handle is at 0x%p.\n", card->name,
 		card->raw_cell_hnd);
-- 
1.8.1.2.459.gbcd45b4.dirty

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

* [PATCH 08/22] amd: Use pci_zalloc_consistent
  2014-06-23 13:41 [PATCH 00/22] Add and use pci_zalloc_consistent Joe Perches
  2014-06-23 13:41 ` [PATCH 02/22] atm: Use pci_zalloc_consistent Joe Perches
@ 2014-06-23 13:41 ` Joe Perches
  2014-06-23 18:02   ` Don Fry
  2014-06-23 13:41 ` [PATCH 09/22] atl1e: " Joe Perches
                   ` (12 subsequent siblings)
  14 siblings, 1 reply; 33+ messages in thread
From: Joe Perches @ 2014-06-23 13:41 UTC (permalink / raw)
  To: linux-kernel; +Cc: Don Fry, netdev

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <joe@perches.com>
---
 drivers/net/ethernet/amd/pcnet32.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/amd/pcnet32.c b/drivers/net/ethernet/amd/pcnet32.c
index e7cc917..e5e2725 100644
--- a/drivers/net/ethernet/amd/pcnet32.c
+++ b/drivers/net/ethernet/amd/pcnet32.c
@@ -484,15 +484,13 @@ static void pcnet32_realloc_tx_ring(struct net_device *dev,
 
 	pcnet32_purge_tx_ring(dev);
 
-	new_tx_ring = pci_alloc_consistent(lp->pci_dev,
-					   sizeof(struct pcnet32_tx_head) *
-					   (1 << size),
-					   &new_ring_dma_addr);
+	new_tx_ring = pci_zalloc_consistent(lp->pci_dev,
+					    sizeof(struct pcnet32_tx_head) * (1 << size),
+					    &new_ring_dma_addr);
 	if (new_tx_ring == NULL) {
 		netif_err(lp, drv, dev, "Consistent memory allocation failed\n");
 		return;
 	}
-	memset(new_tx_ring, 0, sizeof(struct pcnet32_tx_head) * (1 << size));
 
 	new_dma_addr_list = kcalloc(1 << size, sizeof(dma_addr_t),
 				    GFP_ATOMIC);
@@ -551,15 +549,13 @@ static void pcnet32_realloc_rx_ring(struct net_device *dev,
 	int new, overlap;
 	unsigned int entries = 1 << size;
 
-	new_rx_ring = pci_alloc_consistent(lp->pci_dev,
-					   sizeof(struct pcnet32_rx_head) *
-					   entries,
-					   &new_ring_dma_addr);
+	new_rx_ring = pci_zalloc_consistent(lp->pci_dev,
+					    sizeof(struct pcnet32_rx_head) * entries,
+					    &new_ring_dma_addr);
 	if (new_rx_ring == NULL) {
 		netif_err(lp, drv, dev, "Consistent memory allocation failed\n");
 		return;
 	}
-	memset(new_rx_ring, 0, sizeof(struct pcnet32_rx_head) * entries);
 
 	new_dma_addr_list = kcalloc(entries, sizeof(dma_addr_t), GFP_ATOMIC);
 	if (!new_dma_addr_list)
-- 
1.8.1.2.459.gbcd45b4.dirty

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

* [PATCH 09/22] atl1e: Use pci_zalloc_consistent
  2014-06-23 13:41 [PATCH 00/22] Add and use pci_zalloc_consistent Joe Perches
  2014-06-23 13:41 ` [PATCH 02/22] atm: Use pci_zalloc_consistent Joe Perches
  2014-06-23 13:41 ` [PATCH 08/22] amd: " Joe Perches
@ 2014-06-23 13:41 ` Joe Perches
  2014-06-23 13:41 ` [PATCH 10/22] enic: " Joe Perches
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 33+ messages in thread
From: Joe Perches @ 2014-06-23 13:41 UTC (permalink / raw)
  To: linux-kernel; +Cc: Jay Cliburn, Chris Snook, netdev

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <joe@perches.com>
---
 drivers/net/ethernet/atheros/atl1e/atl1e_main.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/atheros/atl1e/atl1e_main.c b/drivers/net/ethernet/atheros/atl1e/atl1e_main.c
index 4345332..316e0c3 100644
--- a/drivers/net/ethernet/atheros/atl1e/atl1e_main.c
+++ b/drivers/net/ethernet/atheros/atl1e/atl1e_main.c
@@ -831,17 +831,14 @@ static int atl1e_setup_ring_resources(struct atl1e_adapter *adapter)
 	/* real ring DMA buffer */
 
 	size = adapter->ring_size;
-	adapter->ring_vir_addr = pci_alloc_consistent(pdev,
-			adapter->ring_size, &adapter->ring_dma);
-
+	adapter->ring_vir_addr = pci_zalloc_consistent(pdev, adapter->ring_size,
+						       &adapter->ring_dma);
 	if (adapter->ring_vir_addr == NULL) {
 		netdev_err(adapter->netdev,
 			   "pci_alloc_consistent failed, size = D%d\n", size);
 		return -ENOMEM;
 	}
 
-	memset(adapter->ring_vir_addr, 0, adapter->ring_size);
-
 	rx_page_desc = rx_ring->rx_page_desc;
 
 	/* Init TPD Ring */
-- 
1.8.1.2.459.gbcd45b4.dirty

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

* [PATCH 10/22] enic: Use pci_zalloc_consistent
  2014-06-23 13:41 [PATCH 00/22] Add and use pci_zalloc_consistent Joe Perches
                   ` (2 preceding siblings ...)
  2014-06-23 13:41 ` [PATCH 09/22] atl1e: " Joe Perches
@ 2014-06-23 13:41 ` Joe Perches
  2014-06-26  6:27   ` Govindarajulu Varadarajan
  2014-06-23 13:41 ` [PATCH 11/22] sky2: " Joe Perches
                   ` (10 subsequent siblings)
  14 siblings, 1 reply; 33+ messages in thread
From: Joe Perches @ 2014-06-23 13:41 UTC (permalink / raw)
  To: linux-kernel
  Cc: Christian Benvenuti, Sujith Sankar, Govindarajulu Varadarajan,
	Neel Patel, netdev

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <joe@perches.com>
---
 drivers/net/ethernet/cisco/enic/vnic_dev.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/cisco/enic/vnic_dev.c b/drivers/net/ethernet/cisco/enic/vnic_dev.c
index e86a45c..8a4799c 100644
--- a/drivers/net/ethernet/cisco/enic/vnic_dev.c
+++ b/drivers/net/ethernet/cisco/enic/vnic_dev.c
@@ -432,14 +432,12 @@ int vnic_dev_fw_info(struct vnic_dev *vdev,
 	int err = 0;
 
 	if (!vdev->fw_info) {
-		vdev->fw_info = pci_alloc_consistent(vdev->pdev,
-			sizeof(struct vnic_devcmd_fw_info),
-			&vdev->fw_info_pa);
+		vdev->fw_info = pci_zalloc_consistent(vdev->pdev,
+						      sizeof(struct vnic_devcmd_fw_info),
+						      &vdev->fw_info_pa);
 		if (!vdev->fw_info)
 			return -ENOMEM;
 
-		memset(vdev->fw_info, 0, sizeof(struct vnic_devcmd_fw_info));
-
 		a0 = vdev->fw_info_pa;
 		a1 = sizeof(struct vnic_devcmd_fw_info);
 
-- 
1.8.1.2.459.gbcd45b4.dirty

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

* [PATCH 11/22] sky2: Use pci_zalloc_consistent
  2014-06-23 13:41 [PATCH 00/22] Add and use pci_zalloc_consistent Joe Perches
                   ` (3 preceding siblings ...)
  2014-06-23 13:41 ` [PATCH 10/22] enic: " Joe Perches
@ 2014-06-23 13:41 ` Joe Perches
  2014-06-23 13:41 ` [PATCH 12/22] micrel: " Joe Perches
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 33+ messages in thread
From: Joe Perches @ 2014-06-23 13:41 UTC (permalink / raw)
  To: linux-kernel; +Cc: Mirko Lindner, Stephen Hemminger, netdev

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <joe@perches.com>
---
 drivers/net/ethernet/marvell/sky2.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/marvell/sky2.c b/drivers/net/ethernet/marvell/sky2.c
index 6969338..5991514 100644
--- a/drivers/net/ethernet/marvell/sky2.c
+++ b/drivers/net/ethernet/marvell/sky2.c
@@ -1622,11 +1622,10 @@ static int sky2_alloc_buffers(struct sky2_port *sky2)
 	if (!sky2->tx_ring)
 		goto nomem;
 
-	sky2->rx_le = pci_alloc_consistent(hw->pdev, RX_LE_BYTES,
-					   &sky2->rx_le_map);
+	sky2->rx_le = pci_zalloc_consistent(hw->pdev, RX_LE_BYTES,
+					    &sky2->rx_le_map);
 	if (!sky2->rx_le)
 		goto nomem;
-	memset(sky2->rx_le, 0, RX_LE_BYTES);
 
 	sky2->rx_ring = kcalloc(sky2->rx_pending, sizeof(struct rx_ring_info),
 				GFP_KERNEL);
-- 
1.8.1.2.459.gbcd45b4.dirty

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

* [PATCH 12/22] micrel: Use pci_zalloc_consistent
  2014-06-23 13:41 [PATCH 00/22] Add and use pci_zalloc_consistent Joe Perches
                   ` (4 preceding siblings ...)
  2014-06-23 13:41 ` [PATCH 11/22] sky2: " Joe Perches
@ 2014-06-23 13:41 ` Joe Perches
  2014-06-23 13:41 ` [PATCH 13/22] qlogic: " Joe Perches
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 33+ messages in thread
From: Joe Perches @ 2014-06-23 13:41 UTC (permalink / raw)
  To: linux-kernel; +Cc: netdev

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <joe@perches.com>
---
 drivers/net/ethernet/micrel/ksz884x.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/micrel/ksz884x.c b/drivers/net/ethernet/micrel/ksz884x.c
index 064a48d..cd5f106 100644
--- a/drivers/net/ethernet/micrel/ksz884x.c
+++ b/drivers/net/ethernet/micrel/ksz884x.c
@@ -4409,14 +4409,13 @@ static int ksz_alloc_desc(struct dev_info *adapter)
 		DESC_ALIGNMENT;
 
 	adapter->desc_pool.alloc_virt =
-		pci_alloc_consistent(
-			adapter->pdev, adapter->desc_pool.alloc_size,
-			&adapter->desc_pool.dma_addr);
+		pci_zalloc_consistent(adapter->pdev,
+				      adapter->desc_pool.alloc_size,
+				      &adapter->desc_pool.dma_addr);
 	if (adapter->desc_pool.alloc_virt == NULL) {
 		adapter->desc_pool.alloc_size = 0;
 		return 1;
 	}
-	memset(adapter->desc_pool.alloc_virt, 0, adapter->desc_pool.alloc_size);
 
 	/* Align to the next cache line boundary. */
 	offset = (((ulong) adapter->desc_pool.alloc_virt % DESC_ALIGNMENT) ?
-- 
1.8.1.2.459.gbcd45b4.dirty

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

* [PATCH 13/22] qlogic: Use pci_zalloc_consistent
  2014-06-23 13:41 [PATCH 00/22] Add and use pci_zalloc_consistent Joe Perches
                   ` (5 preceding siblings ...)
  2014-06-23 13:41 ` [PATCH 12/22] micrel: " Joe Perches
@ 2014-06-23 13:41 ` Joe Perches
  2014-06-23 13:41 ` [PATCH 14/22] irda: " Joe Perches
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 33+ messages in thread
From: Joe Perches @ 2014-06-23 13:41 UTC (permalink / raw)
  To: linux-kernel
  Cc: Manish Chopra, Sony Chacko, Rajesh Borundia, Shahed Shaikh,
	Jitendra Kalsaria, Ron Mercer, linux-driver, netdev

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <joe@perches.com>
---
 drivers/net/ethernet/qlogic/netxen/netxen_nic_ctx.c |  4 +---
 drivers/net/ethernet/qlogic/qlge/qlge_main.c        | 11 +++++------
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/qlogic/netxen/netxen_nic_ctx.c b/drivers/net/ethernet/qlogic/netxen/netxen_nic_ctx.c
index 6f6be57..b8d5270 100644
--- a/drivers/net/ethernet/qlogic/netxen/netxen_nic_ctx.c
+++ b/drivers/net/ethernet/qlogic/netxen/netxen_nic_ctx.c
@@ -129,14 +129,12 @@ netxen_get_minidump_template(struct netxen_adapter *adapter)
 		return NX_RCODE_INVALID_ARGS;
 	}
 
-	addr = pci_alloc_consistent(adapter->pdev, size, &md_template_addr);
-
+	addr = pci_zalloc_consistent(adapter->pdev, size, &md_template_addr);
 	if (!addr) {
 		dev_err(&adapter->pdev->dev, "Unable to allocate dmable memory for template.\n");
 		return -ENOMEM;
 	}
 
-	memset(addr, 0, size);
 	memset(&cmd, 0, sizeof(cmd));
 	memset(&cmd.rsp, 1, sizeof(struct _cdrp_cmd));
 	cmd.req.cmd = NX_CDRP_CMD_GET_TEMP_HDR;
diff --git a/drivers/net/ethernet/qlogic/qlge/qlge_main.c b/drivers/net/ethernet/qlogic/qlge/qlge_main.c
index b40050e..d836ace 100644
--- a/drivers/net/ethernet/qlogic/qlge/qlge_main.c
+++ b/drivers/net/ethernet/qlogic/qlge/qlge_main.c
@@ -2727,23 +2727,22 @@ static void ql_free_shadow_space(struct ql_adapter *qdev)
 static int ql_alloc_shadow_space(struct ql_adapter *qdev)
 {
 	qdev->rx_ring_shadow_reg_area =
-	    pci_alloc_consistent(qdev->pdev,
-				 PAGE_SIZE, &qdev->rx_ring_shadow_reg_dma);
+		pci_zalloc_consistent(qdev->pdev, PAGE_SIZE,
+				      &qdev->rx_ring_shadow_reg_dma);
 	if (qdev->rx_ring_shadow_reg_area == NULL) {
 		netif_err(qdev, ifup, qdev->ndev,
 			  "Allocation of RX shadow space failed.\n");
 		return -ENOMEM;
 	}
-	memset(qdev->rx_ring_shadow_reg_area, 0, PAGE_SIZE);
+
 	qdev->tx_ring_shadow_reg_area =
-	    pci_alloc_consistent(qdev->pdev, PAGE_SIZE,
-				 &qdev->tx_ring_shadow_reg_dma);
+		pci_zalloc_consistent(qdev->pdev, PAGE_SIZE,
+				      &qdev->tx_ring_shadow_reg_dma);
 	if (qdev->tx_ring_shadow_reg_area == NULL) {
 		netif_err(qdev, ifup, qdev->ndev,
 			  "Allocation of TX shadow space failed.\n");
 		goto err_wqp_sh_area;
 	}
-	memset(qdev->tx_ring_shadow_reg_area, 0, PAGE_SIZE);
 	return 0;
 
 err_wqp_sh_area:
-- 
1.8.1.2.459.gbcd45b4.dirty

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

* [PATCH 14/22] irda: Use pci_zalloc_consistent
  2014-06-23 13:41 [PATCH 00/22] Add and use pci_zalloc_consistent Joe Perches
                   ` (6 preceding siblings ...)
  2014-06-23 13:41 ` [PATCH 13/22] qlogic: " Joe Perches
@ 2014-06-23 13:41 ` Joe Perches
  2014-06-23 13:41 ` [PATCH 15/22] ipw2100: " Joe Perches
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 33+ messages in thread
From: Joe Perches @ 2014-06-23 13:41 UTC (permalink / raw)
  To: linux-kernel; +Cc: Samuel Ortiz, netdev

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <joe@perches.com>
---
 drivers/net/irda/vlsi_ir.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/irda/vlsi_ir.c b/drivers/net/irda/vlsi_ir.c
index 4850066..58ef594 100644
--- a/drivers/net/irda/vlsi_ir.c
+++ b/drivers/net/irda/vlsi_ir.c
@@ -485,13 +485,13 @@ static int vlsi_create_hwif(vlsi_irda_dev_t *idev)
 	idev->virtaddr = NULL;
 	idev->busaddr = 0;
 
-	ringarea = pci_alloc_consistent(idev->pdev, HW_RING_AREA_SIZE, &idev->busaddr);
+	ringarea = pci_zalloc_consistent(idev->pdev, HW_RING_AREA_SIZE,
+					 &idev->busaddr);
 	if (!ringarea) {
 		IRDA_ERROR("%s: insufficient memory for descriptor rings\n",
 			   __func__);
 		goto out;
 	}
-	memset(ringarea, 0, HW_RING_AREA_SIZE);
 
 	hwmap = (struct ring_descr_hw *)ringarea;
 	idev->rx_ring = vlsi_alloc_ring(idev->pdev, hwmap, ringsize[1],
-- 
1.8.1.2.459.gbcd45b4.dirty

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

* [PATCH 15/22] ipw2100: Use pci_zalloc_consistent
  2014-06-23 13:41 [PATCH 00/22] Add and use pci_zalloc_consistent Joe Perches
                   ` (7 preceding siblings ...)
  2014-06-23 13:41 ` [PATCH 14/22] irda: " Joe Perches
@ 2014-06-23 13:41 ` Joe Perches
  2014-06-23 13:41 ` [PATCH 16/22] mwl8k: " Joe Perches
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 33+ messages in thread
From: Joe Perches @ 2014-06-23 13:41 UTC (permalink / raw)
  To: linux-kernel; +Cc: Stanislav Yakovlev, John W. Linville, linux-wireless, netdev

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <joe@perches.com>
---
 drivers/net/wireless/ipw2x00/ipw2100.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/drivers/net/wireless/ipw2x00/ipw2100.c b/drivers/net/wireless/ipw2x00/ipw2100.c
index dfc6dfc..1ab8e50 100644
--- a/drivers/net/wireless/ipw2x00/ipw2100.c
+++ b/drivers/net/wireless/ipw2x00/ipw2100.c
@@ -3449,8 +3449,9 @@ static int ipw2100_msg_allocate(struct ipw2100_priv *priv)
 		return -ENOMEM;
 
 	for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
-		v = pci_alloc_consistent(priv->pci_dev,
-					 sizeof(struct ipw2100_cmd_header), &p);
+		v = pci_zalloc_consistent(priv->pci_dev,
+					  sizeof(struct ipw2100_cmd_header),
+					  &p);
 		if (!v) {
 			printk(KERN_ERR DRV_NAME ": "
 			       "%s: PCI alloc failed for msg "
@@ -3459,8 +3460,6 @@ static int ipw2100_msg_allocate(struct ipw2100_priv *priv)
 			break;
 		}
 
-		memset(v, 0, sizeof(struct ipw2100_cmd_header));
-
 		priv->msg_buffers[i].type = COMMAND;
 		priv->msg_buffers[i].info.c_struct.cmd =
 		    (struct ipw2100_cmd_header *)v;
@@ -4336,16 +4335,12 @@ static int status_queue_allocate(struct ipw2100_priv *priv, int entries)
 	IPW_DEBUG_INFO("enter\n");
 
 	q->size = entries * sizeof(struct ipw2100_status);
-	q->drv =
-	    (struct ipw2100_status *)pci_alloc_consistent(priv->pci_dev,
-							  q->size, &q->nic);
+	q->drv = pci_zalloc_consistent(priv->pci_dev, q->size, &q->nic);
 	if (!q->drv) {
 		IPW_DEBUG_WARNING("Can not allocate status queue.\n");
 		return -ENOMEM;
 	}
 
-	memset(q->drv, 0, q->size);
-
 	IPW_DEBUG_INFO("exit\n");
 
 	return 0;
@@ -4374,13 +4369,12 @@ static int bd_queue_allocate(struct ipw2100_priv *priv,
 
 	q->entries = entries;
 	q->size = entries * sizeof(struct ipw2100_bd);
-	q->drv = pci_alloc_consistent(priv->pci_dev, q->size, &q->nic);
+	q->drv = pci_zalloc_consistent(priv->pci_dev, q->size, &q->nic);
 	if (!q->drv) {
 		IPW_DEBUG_INFO
 		    ("can't allocate shared memory for buffer descriptors\n");
 		return -ENOMEM;
 	}
-	memset(q->drv, 0, q->size);
 
 	IPW_DEBUG_INFO("exit\n");
 
-- 
1.8.1.2.459.gbcd45b4.dirty

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

* [PATCH 16/22] mwl8k: Use pci_zalloc_consistent
  2014-06-23 13:41 [PATCH 00/22] Add and use pci_zalloc_consistent Joe Perches
                   ` (8 preceding siblings ...)
  2014-06-23 13:41 ` [PATCH 15/22] ipw2100: " Joe Perches
@ 2014-06-23 13:41 ` Joe Perches
  2014-06-23 13:41 ` [PATCH 17/22] rtl818x: " Joe Perches
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 33+ messages in thread
From: Joe Perches @ 2014-06-23 13:41 UTC (permalink / raw)
  To: linux-kernel; +Cc: Lennert Buytenhek, John W. Linville, linux-wireless, netdev

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <joe@perches.com>
---
 drivers/net/wireless/mwl8k.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/wireless/mwl8k.c b/drivers/net/wireless/mwl8k.c
index 3c0a0a8..7e6b981 100644
--- a/drivers/net/wireless/mwl8k.c
+++ b/drivers/net/wireless/mwl8k.c
@@ -1159,12 +1159,11 @@ static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
 
 	size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
 
-	rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
+	rxq->rxd = pci_zalloc_consistent(priv->pdev, size, &rxq->rxd_dma);
 	if (rxq->rxd == NULL) {
 		wiphy_err(hw->wiphy, "failed to alloc RX descriptors\n");
 		return -ENOMEM;
 	}
-	memset(rxq->rxd, 0, size);
 
 	rxq->buf = kcalloc(MWL8K_RX_DESCS, sizeof(*rxq->buf), GFP_KERNEL);
 	if (rxq->buf == NULL) {
@@ -1451,12 +1450,11 @@ static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
 
 	size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
 
-	txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
+	txq->txd = pci_zalloc_consistent(priv->pdev, size, &txq->txd_dma);
 	if (txq->txd == NULL) {
 		wiphy_err(hw->wiphy, "failed to alloc TX descriptors\n");
 		return -ENOMEM;
 	}
-	memset(txq->txd, 0, size);
 
 	txq->skb = kcalloc(MWL8K_TX_DESCS, sizeof(*txq->skb), GFP_KERNEL);
 	if (txq->skb == NULL) {
-- 
1.8.1.2.459.gbcd45b4.dirty

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

* [PATCH 17/22] rtl818x: Use pci_zalloc_consistent
  2014-06-23 13:41 [PATCH 00/22] Add and use pci_zalloc_consistent Joe Perches
                   ` (9 preceding siblings ...)
  2014-06-23 13:41 ` [PATCH 16/22] mwl8k: " Joe Perches
@ 2014-06-23 13:41 ` Joe Perches
  2014-06-23 13:41 ` [PATCH 18/22] rtlwifi: " Joe Perches
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 33+ messages in thread
From: Joe Perches @ 2014-06-23 13:41 UTC (permalink / raw)
  To: linux-kernel; +Cc: John W. Linville, linux-wireless, netdev

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <joe@perches.com>
---
 drivers/net/wireless/rtl818x/rtl8180/dev.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/net/wireless/rtl818x/rtl8180/dev.c b/drivers/net/wireless/rtl818x/rtl8180/dev.c
index 1e25929..7577e01 100644
--- a/drivers/net/wireless/rtl818x/rtl8180/dev.c
+++ b/drivers/net/wireless/rtl818x/rtl8180/dev.c
@@ -964,16 +964,13 @@ static int rtl8180_init_rx_ring(struct ieee80211_hw *dev)
 	else
 		priv->rx_ring_sz = sizeof(struct rtl8180_rx_desc);
 
-	priv->rx_ring = pci_alloc_consistent(priv->pdev,
-					     priv->rx_ring_sz * 32,
-					     &priv->rx_ring_dma);
-
+	priv->rx_ring = pci_zalloc_consistent(priv->pdev, priv->rx_ring_sz * 32,
+					      &priv->rx_ring_dma);
 	if (!priv->rx_ring || (unsigned long)priv->rx_ring & 0xFF) {
 		wiphy_err(dev->wiphy, "Cannot allocate RX ring\n");
 		return -ENOMEM;
 	}
 
-	memset(priv->rx_ring, 0, priv->rx_ring_sz * 32);
 	priv->rx_idx = 0;
 
 	for (i = 0; i < 32; i++) {
@@ -1032,14 +1029,14 @@ static int rtl8180_init_tx_ring(struct ieee80211_hw *dev,
 	dma_addr_t dma;
 	int i;
 
-	ring = pci_alloc_consistent(priv->pdev, sizeof(*ring) * entries, &dma);
+	ring = pci_zalloc_consistent(priv->pdev, sizeof(*ring) * entries,
+				     &dma);
 	if (!ring || (unsigned long)ring & 0xFF) {
 		wiphy_err(dev->wiphy, "Cannot allocate TX ring (prio = %d)\n",
 			  prio);
 		return -ENOMEM;
 	}
 
-	memset(ring, 0, sizeof(*ring)*entries);
 	priv->tx_ring[prio].desc = ring;
 	priv->tx_ring[prio].dma = dma;
 	priv->tx_ring[prio].idx = 0;
-- 
1.8.1.2.459.gbcd45b4.dirty

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

* [PATCH 18/22] rtlwifi: Use pci_zalloc_consistent
  2014-06-23 13:41 [PATCH 00/22] Add and use pci_zalloc_consistent Joe Perches
                   ` (10 preceding siblings ...)
  2014-06-23 13:41 ` [PATCH 17/22] rtl818x: " Joe Perches
@ 2014-06-23 13:41 ` Joe Perches
  2014-06-23 17:25 ` [PATCH 00/22] Add and use pci_zalloc_consistent Luis R. Rodriguez
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 33+ messages in thread
From: Joe Perches @ 2014-06-23 13:41 UTC (permalink / raw)
  To: linux-kernel
  Cc: Larry Finger, Chaoming Li, John W. Linville, linux-wireless,
	netdev

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <joe@perches.com>
---
 drivers/net/wireless/rtlwifi/pci.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)

diff --git a/drivers/net/wireless/rtlwifi/pci.c b/drivers/net/wireless/rtlwifi/pci.c
index dae5525..67d1ee6 100644
--- a/drivers/net/wireless/rtlwifi/pci.c
+++ b/drivers/net/wireless/rtlwifi/pci.c
@@ -1092,16 +1092,14 @@ static int _rtl_pci_init_tx_ring(struct ieee80211_hw *hw,
 	u32 nextdescaddress;
 	int i;
 
-	ring = pci_alloc_consistent(rtlpci->pdev,
-				    sizeof(*ring) * entries, &dma);
-
+	ring = pci_zalloc_consistent(rtlpci->pdev, sizeof(*ring) * entries,
+				     &dma);
 	if (!ring || (unsigned long)ring & 0xFF) {
 		RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
 			 "Cannot allocate TX ring (prio = %d)\n", prio);
 		return -ENOMEM;
 	}
 
-	memset(ring, 0, sizeof(*ring) * entries);
 	rtlpci->tx_ring[prio].desc = ring;
 	rtlpci->tx_ring[prio].dma = dma;
 	rtlpci->tx_ring[prio].idx = 0;
@@ -1139,10 +1137,9 @@ static int _rtl_pci_init_rx_ring(struct ieee80211_hw *hw)
 	for (rx_queue_idx = 0; rx_queue_idx < RTL_PCI_MAX_RX_QUEUE;
 	     rx_queue_idx++) {
 		rtlpci->rx_ring[rx_queue_idx].desc =
-		    pci_alloc_consistent(rtlpci->pdev,
-					 sizeof(*rtlpci->rx_ring[rx_queue_idx].
-						desc) * rtlpci->rxringcount,
-					 &rtlpci->rx_ring[rx_queue_idx].dma);
+			pci_zalloc_consistent(rtlpci->pdev,
+					      sizeof(*rtlpci->rx_ring[rx_queue_idx].desc) * rtlpci->rxringcount,
+					      &rtlpci->rx_ring[rx_queue_idx].dma);
 
 		if (!rtlpci->rx_ring[rx_queue_idx].desc ||
 		    (unsigned long)rtlpci->rx_ring[rx_queue_idx].desc & 0xFF) {
@@ -1151,10 +1148,6 @@ static int _rtl_pci_init_rx_ring(struct ieee80211_hw *hw)
 			return -ENOMEM;
 		}
 
-		memset(rtlpci->rx_ring[rx_queue_idx].desc, 0,
-		       sizeof(*rtlpci->rx_ring[rx_queue_idx].desc) *
-		       rtlpci->rxringcount);
-
 		rtlpci->rx_ring[rx_queue_idx].idx = 0;
 
 		/* If amsdu_8k is disabled, set buffersize to 4096. This
-- 
1.8.1.2.459.gbcd45b4.dirty

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

* Re: [PATCH 00/22] Add and use pci_zalloc_consistent
  2014-06-23 13:41 [PATCH 00/22] Add and use pci_zalloc_consistent Joe Perches
                   ` (11 preceding siblings ...)
  2014-06-23 13:41 ` [PATCH 18/22] rtlwifi: " Joe Perches
@ 2014-06-23 17:25 ` Luis R. Rodriguez
  2014-06-23 19:13   ` Joe Perches
       [not found] ` <cover.1403530604.git.joe-6d6DIl74uiNBDgjK7y7TUQ@public.gmane.org>
  2014-06-25 19:41 ` John W. Linville
  14 siblings, 1 reply; 33+ messages in thread
From: Luis R. Rodriguez @ 2014-06-23 17:25 UTC (permalink / raw)
  To: Joe Perches
  Cc: devel, linux-arch, linux-scsi, iss_storagedev, linux-rdma, netdev,
	linux-atm-general, linux-wireless, linux-kernel, dri-devel,
	linux-crypto, linux-media, linux-eata

On Mon, Jun 23, 2014 at 06:41:28AM -0700, Joe Perches wrote:
> Adding the helper reduces object code size as well as overall
> source size line count.
> 
> It's also consistent with all the various zalloc mechanisms
> in the kernel.
> 
> Done with a simple cocci script and some typing.

Awesome, any chance you can paste in the SmPL? Also any chance
we can get this added to a make coccicheck so that maintainers
moving forward can use that to ensure that no new code is
added that uses the old school API?

  Luis

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

* Re: [PATCH 08/22] amd: Use pci_zalloc_consistent
  2014-06-23 13:41 ` [PATCH 08/22] amd: " Joe Perches
@ 2014-06-23 18:02   ` Don Fry
  2014-06-23 19:15     ` Joe Perches
  0 siblings, 1 reply; 33+ messages in thread
From: Don Fry @ 2014-06-23 18:02 UTC (permalink / raw)
  To: Joe Perches; +Cc: linux-kernel, netdev

On Mon, 2014-06-23 at 06:41 -0700, Joe Perches wrote:
> Remove the now unnecessary memset too.
> 
> Signed-off-by: Joe Perches <joe@perches.com>
> ---
>  drivers/net/ethernet/amd/pcnet32.c | 16 ++++++----------
>  1 file changed, 6 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/net/ethernet/amd/pcnet32.c b/drivers/net/ethernet/amd/pcnet32.c
> index e7cc917..e5e2725 100644
> --- a/drivers/net/ethernet/amd/pcnet32.c
> +++ b/drivers/net/ethernet/amd/pcnet32.c
> @@ -484,15 +484,13 @@ static void pcnet32_realloc_tx_ring(struct net_device *dev,
>  
>  	pcnet32_purge_tx_ring(dev);
>  
> -	new_tx_ring = pci_alloc_consistent(lp->pci_dev,
> -					   sizeof(struct pcnet32_tx_head) *
> -					   (1 << size),
> -					   &new_ring_dma_addr);
> +	new_tx_ring = pci_zalloc_consistent(lp->pci_dev,
> +					    sizeof(struct pcnet32_tx_head) * (1 << size),

This causes the line length to be greater than 80 characters causing
checkpatch to complain.

> +					    &new_ring_dma_addr);
>  	if (new_tx_ring == NULL) {
>  		netif_err(lp, drv, dev, "Consistent memory allocation failed\n");
>  		return;
>  	}
> -	memset(new_tx_ring, 0, sizeof(struct pcnet32_tx_head) * (1 << size));
>  
>  	new_dma_addr_list = kcalloc(1 << size, sizeof(dma_addr_t),
>  				    GFP_ATOMIC);
> @@ -551,15 +549,13 @@ static void pcnet32_realloc_rx_ring(struct net_device *dev,
>  	int new, overlap;
>  	unsigned int entries = 1 << size;
>  
> -	new_rx_ring = pci_alloc_consistent(lp->pci_dev,
> -					   sizeof(struct pcnet32_rx_head) *
> -					   entries,
> -					   &new_ring_dma_addr);
> +	new_rx_ring = pci_zalloc_consistent(lp->pci_dev,
> +					    sizeof(struct pcnet32_rx_head) * entries,


This causes the line length to be greater than 80 characters causing
checkpatch to complain.

> +					    &new_ring_dma_addr);
>  	if (new_rx_ring == NULL) {
>  		netif_err(lp, drv, dev, "Consistent memory allocation failed\n");
>  		return;
>  	}
> -	memset(new_rx_ring, 0, sizeof(struct pcnet32_rx_head) * entries);
>  
>  	new_dma_addr_list = kcalloc(entries, sizeof(dma_addr_t), GFP_ATOMIC);
>  	if (!new_dma_addr_list)

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

* Re: [PATCH 00/22] Add and use pci_zalloc_consistent
  2014-06-23 17:25 ` [PATCH 00/22] Add and use pci_zalloc_consistent Luis R. Rodriguez
@ 2014-06-23 19:13   ` Joe Perches
  2014-06-23 23:27     ` Julian Calaby
  0 siblings, 1 reply; 33+ messages in thread
From: Joe Perches @ 2014-06-23 19:13 UTC (permalink / raw)
  To: Luis R. Rodriguez, Arnd Bergmann
  Cc: devel, linux-arch, linux-scsi, iss_storagedev, linux-rdma, netdev,
	linux-atm-general, linux-wireless, linux-kernel, dri-devel,
	linux-crypto, linux-media, linux-eata

On Mon, 2014-06-23 at 10:25 -0700, Luis R. Rodriguez wrote:
> On Mon, Jun 23, 2014 at 06:41:28AM -0700, Joe Perches wrote:
> > Adding the helper reduces object code size as well as overall
> > source size line count.
> > 
> > It's also consistent with all the various zalloc mechanisms
> > in the kernel.
> > 
> > Done with a simple cocci script and some typing.
> 
> Awesome, any chance you can paste in the SmPL? Also any chance
> we can get this added to a make coccicheck so that maintainers
> moving forward can use that to ensure that no new code is
> added that uses the old school API?

Not many of these are recent.

Arnd Bergmann reasonably suggested that the pci_alloc_consistent
api be converted the the more widely used dma_alloc_coherent.

https://lkml.org/lkml/2014/6/23/513

> Shouldn't these drivers just use the normal dma-mapping API now?

and I replied:

https://lkml.org/lkml/2014/6/23/525

> Maybe.  I wouldn't mind.
> They do seem to have a trivial bit of unnecessary overhead for 
> hwdev == NULL ? NULL : &hwdev->dev

Anyway, here's the little script.
I'm not sure it's worthwhile to add it though.

$ cat ./scripts/coccinelle/api/alloc/pci_zalloc_consistent.cocci
///
/// Use pci_zalloc_consistent rather than
///     pci_alloc_consistent followed by memset with 0
///
/// This considers some simple cases that are common and easy to validate
/// Note in particular that there are no ...s in the rule, so all of the
/// matched code has to be contiguous
///
/// Blatantly cribbed from: scripts/coccinelle/api/alloc/kzalloc-simple.cocci

@@
type T, T2;
expression x;
expression E1,E2,E3;
statement S;
@@

- x = (T)pci_alloc_consistent(E1,E2,E3);
+ x = pci_zalloc_consistent(E1,E2,E3);
  if ((x==NULL) || ...) S
- memset((T2)x,0,E2);

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

* Re: [PATCH 08/22] amd: Use pci_zalloc_consistent
  2014-06-23 18:02   ` Don Fry
@ 2014-06-23 19:15     ` Joe Perches
  2014-06-23 21:05       ` [PATCH V2 " Joe Perches
  2014-06-25 23:51       ` [PATCH V3 08/22] pcnet32: Use pci_zalloc_consistent Joe Perches
  0 siblings, 2 replies; 33+ messages in thread
From: Joe Perches @ 2014-06-23 19:15 UTC (permalink / raw)
  To: Don Fry; +Cc: linux-kernel, netdev

On Mon, 2014-06-23 at 11:02 -0700, Don Fry wrote:
> On Mon, 2014-06-23 at 06:41 -0700, Joe Perches wrote:
> > Remove the now unnecessary memset too.
[]
> > diff --git a/drivers/net/ethernet/amd/pcnet32.c b/drivers/net/ethernet/amd/pcnet32.c
[]
> > @@ -484,15 +484,13 @@ static void pcnet32_realloc_tx_ring(struct net_device *dev,
> >  
> >  	pcnet32_purge_tx_ring(dev);
> >  
> > -	new_tx_ring = pci_alloc_consistent(lp->pci_dev,
> > -					   sizeof(struct pcnet32_tx_head) *
> > -					   (1 << size),
> > -					   &new_ring_dma_addr);
> > +	new_tx_ring = pci_zalloc_consistent(lp->pci_dev,
> > +					    sizeof(struct pcnet32_tx_head) * (1 << size),
> 
> This causes the line length to be greater than 80 characters causing
> checkpatch to complain.

Which doesn't bother me a whit.
I prefer the multiply on the same line.

If you prefer 80 columns that strongly though,
let me know.

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

* [PATCH V2 08/22] amd: Use pci_zalloc_consistent
  2014-06-23 19:15     ` Joe Perches
@ 2014-06-23 21:05       ` Joe Perches
  2014-06-23 21:36         ` [PATCH] amd: Neaten and remove unnecessary OOM messages Joe Perches
                           ` (3 more replies)
  2014-06-25 23:51       ` [PATCH V3 08/22] pcnet32: Use pci_zalloc_consistent Joe Perches
  1 sibling, 4 replies; 33+ messages in thread
From: Joe Perches @ 2014-06-23 21:05 UTC (permalink / raw)
  To: Don Fry; +Cc: linux-kernel, netdev

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <joe@perches.com>
---
On Mon, 2014-06-23 at 12:15 -0700, Joe Perches wrote:
> On Mon, 2014-06-23 at 11:02 -0700, Don Fry wrote:
> > This causes the line length to be greater than 80 characters causing
> > checkpatch to complain.

V2: Don Fry is an 80 column neatnik.

Please remember this depends on patch 1/22 being applied
before this patch can be successfully applied.

 drivers/net/ethernet/amd/pcnet32.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/amd/pcnet32.c b/drivers/net/ethernet/amd/pcnet32.c
index e7cc917..8099fdc 100644
--- a/drivers/net/ethernet/amd/pcnet32.c
+++ b/drivers/net/ethernet/amd/pcnet32.c
@@ -484,15 +484,14 @@ static void pcnet32_realloc_tx_ring(struct net_device *dev,
 
 	pcnet32_purge_tx_ring(dev);
 
-	new_tx_ring = pci_alloc_consistent(lp->pci_dev,
-					   sizeof(struct pcnet32_tx_head) *
-					   (1 << size),
-					   &new_ring_dma_addr);
+	new_tx_ring = pci_zalloc_consistent(lp->pci_dev,
+					    sizeof(struct pcnet32_tx_head) *
+					    (1 << size),
+					    &new_ring_dma_addr);
 	if (new_tx_ring == NULL) {
 		netif_err(lp, drv, dev, "Consistent memory allocation failed\n");
 		return;
 	}
-	memset(new_tx_ring, 0, sizeof(struct pcnet32_tx_head) * (1 << size));
 
 	new_dma_addr_list = kcalloc(1 << size, sizeof(dma_addr_t),
 				    GFP_ATOMIC);
@@ -551,15 +550,14 @@ static void pcnet32_realloc_rx_ring(struct net_device *dev,
 	int new, overlap;
 	unsigned int entries = 1 << size;
 
-	new_rx_ring = pci_alloc_consistent(lp->pci_dev,
-					   sizeof(struct pcnet32_rx_head) *
-					   entries,
-					   &new_ring_dma_addr);
+	new_rx_ring = pci_zalloc_consistent(lp->pci_dev,
+					    sizeof(struct pcnet32_rx_head) *
+					    entries,
+					    &new_ring_dma_addr);
 	if (new_rx_ring == NULL) {
 		netif_err(lp, drv, dev, "Consistent memory allocation failed\n");
 		return;
 	}
-	memset(new_rx_ring, 0, sizeof(struct pcnet32_rx_head) * entries);
 
 	new_dma_addr_list = kcalloc(entries, sizeof(dma_addr_t), GFP_ATOMIC);
 	if (!new_dma_addr_list)

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

* [PATCH] amd: Neaten and remove unnecessary OOM messages
  2014-06-23 21:05       ` [PATCH V2 " Joe Perches
@ 2014-06-23 21:36         ` Joe Perches
  2014-06-23 22:42           ` Don Fry
  2014-06-25 23:32           ` David Miller
  2014-06-23 22:22         ` [PATCH V2 08/22] amd: Use pci_zalloc_consistent Don Fry
                           ` (2 subsequent siblings)
  3 siblings, 2 replies; 33+ messages in thread
From: Joe Perches @ 2014-06-23 21:36 UTC (permalink / raw)
  To: Don Fry; +Cc: linux-kernel, netdev

Make the code flow a little better for 80 columns.

Use a consistent style for the RX and TX rings allocation.
Use BIT macro.
Use a temporary unsiged int entries for (1<<size).
Remove the OOM messages as they duplicate the generic
OOM and dump_stack() provided by the memory subsystem.
Reflow allocs to 80 columns.

Signed-off-by: Joe Perches <joe@perches.com>
---
 drivers/net/ethernet/amd/pcnet32.c | 43 ++++++++++++++++----------------------
 1 file changed, 18 insertions(+), 25 deletions(-)

diff --git a/drivers/net/ethernet/amd/pcnet32.c b/drivers/net/ethernet/amd/pcnet32.c
index 8099fdc..4a8fdc4 100644
--- a/drivers/net/ethernet/amd/pcnet32.c
+++ b/drivers/net/ethernet/amd/pcnet32.c
@@ -481,36 +481,32 @@ static void pcnet32_realloc_tx_ring(struct net_device *dev,
 	dma_addr_t *new_dma_addr_list;
 	struct pcnet32_tx_head *new_tx_ring;
 	struct sk_buff **new_skb_list;
+	unsigned int entries = BIT(size);
 
 	pcnet32_purge_tx_ring(dev);
 
-	new_tx_ring = pci_zalloc_consistent(lp->pci_dev,
-					    sizeof(struct pcnet32_tx_head) *
-					    (1 << size),
-					    &new_ring_dma_addr);
-	if (new_tx_ring == NULL) {
-		netif_err(lp, drv, dev, "Consistent memory allocation failed\n");
+	new_tx_ring =
+		pci_zalloc_consistent(lp->pci_dev,
+				      sizeof(struct pcnet32_tx_head) * entries,
+				      &new_ring_dma_addr);
+	if (new_tx_ring == NULL)
 		return;
-	}
 
-	new_dma_addr_list = kcalloc(1 << size, sizeof(dma_addr_t),
-				    GFP_ATOMIC);
+	new_dma_addr_list = kcalloc(entries, sizeof(dma_addr_t), GFP_ATOMIC);
 	if (!new_dma_addr_list)
 		goto free_new_tx_ring;
 
-	new_skb_list = kcalloc(1 << size, sizeof(struct sk_buff *),
-			       GFP_ATOMIC);
+	new_skb_list = kcalloc(entries, sizeof(struct sk_buff *), GFP_ATOMIC);
 	if (!new_skb_list)
 		goto free_new_lists;
 
 	kfree(lp->tx_skbuff);
 	kfree(lp->tx_dma_addr);
 	pci_free_consistent(lp->pci_dev,
-			    sizeof(struct pcnet32_tx_head) *
-			    lp->tx_ring_size, lp->tx_ring,
-			    lp->tx_ring_dma_addr);
+			    sizeof(struct pcnet32_tx_head) * lp->tx_ring_size,
+			    lp->tx_ring, lp->tx_ring_dma_addr);
 
-	lp->tx_ring_size = (1 << size);
+	lp->tx_ring_size = entries;
 	lp->tx_mod_mask = lp->tx_ring_size - 1;
 	lp->tx_len_bits = (size << 12);
 	lp->tx_ring = new_tx_ring;
@@ -523,8 +519,7 @@ free_new_lists:
 	kfree(new_dma_addr_list);
 free_new_tx_ring:
 	pci_free_consistent(lp->pci_dev,
-			    sizeof(struct pcnet32_tx_head) *
-			    (1 << size),
+			    sizeof(struct pcnet32_tx_head) * entries,
 			    new_tx_ring,
 			    new_ring_dma_addr);
 }
@@ -548,16 +543,14 @@ static void pcnet32_realloc_rx_ring(struct net_device *dev,
 	struct pcnet32_rx_head *new_rx_ring;
 	struct sk_buff **new_skb_list;
 	int new, overlap;
-	unsigned int entries = 1 << size;
+	unsigned int entries = BIT(size);
 
-	new_rx_ring = pci_zalloc_consistent(lp->pci_dev,
-					    sizeof(struct pcnet32_rx_head) *
-					    entries,
-					    &new_ring_dma_addr);
-	if (new_rx_ring == NULL) {
-		netif_err(lp, drv, dev, "Consistent memory allocation failed\n");
+	new_rx_ring =
+		pci_zalloc_consistent(lp->pci_dev,
+				      sizeof(struct pcnet32_rx_head) * entries,
+				      &new_ring_dma_addr);
+	if (new_rx_ring == NULL)
 		return;
-	}
 
 	new_dma_addr_list = kcalloc(entries, sizeof(dma_addr_t), GFP_ATOMIC);
 	if (!new_dma_addr_list)

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

* Re: [PATCH 00/22] Add and use pci_zalloc_consistent
       [not found] ` <cover.1403530604.git.joe-6d6DIl74uiNBDgjK7y7TUQ@public.gmane.org>
@ 2014-06-23 21:49   ` David Miller
  0 siblings, 0 replies; 33+ messages in thread
From: David Miller @ 2014-06-23 21:49 UTC (permalink / raw)
  To: joe-6d6DIl74uiNBDgjK7y7TUQ
  Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-atm-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	netdev-u79uwXL29TY76Z2rM5mHXA, iss_storagedev-VXdhtT5mjnY,
	linux-crypto-u79uwXL29TY76Z2rM5mHXA,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	linux-media-u79uwXL29TY76Z2rM5mHXA,
	linux-wireless-u79uwXL29TY76Z2rM5mHXA,
	linux-scsi-u79uwXL29TY76Z2rM5mHXA,
	linux-eata-3umIvqjeSgIeIZ0/mPfg9Q,
	devel-gWbeCf7V1WCQmaza687I9mD2FQJk+8+b,
	linux-arch-u79uwXL29TY76Z2rM5mHXA

From: Joe Perches <joe-6d6DIl74uiNBDgjK7y7TUQ@public.gmane.org>
Date: Mon, 23 Jun 2014 06:41:28 -0700

> Adding the helper reduces object code size as well as overall
> source size line count.
> 
> It's also consistent with all the various zalloc mechanisms
> in the kernel.
> 
> Done with a simple cocci script and some typing.

For networking bits:

Acked-by: David S. Miller <davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH V2 08/22] amd: Use pci_zalloc_consistent
  2014-06-23 21:05       ` [PATCH V2 " Joe Perches
  2014-06-23 21:36         ` [PATCH] amd: Neaten and remove unnecessary OOM messages Joe Perches
@ 2014-06-23 22:22         ` Don Fry
  2014-06-25  4:49         ` Guenter Roeck
  2014-06-25 23:55         ` [PATCH V2] pcnet32: Neaten and remove unnecessary OOM messages Joe Perches
  3 siblings, 0 replies; 33+ messages in thread
From: Don Fry @ 2014-06-23 22:22 UTC (permalink / raw)
  To: Joe Perches; +Cc: linux-kernel, netdev

On Mon, 2014-06-23 at 14:05 -0700, Joe Perches wrote:
> Remove the now unnecessary memset too.
> 
> Signed-off-by: Joe Perches <joe@perches.com>
> ---
> On Mon, 2014-06-23 at 12:15 -0700, Joe Perches wrote:
> > On Mon, 2014-06-23 at 11:02 -0700, Don Fry wrote:
> > > This causes the line length to be greater than 80 characters causing
> > > checkpatch to complain.
> 
> V2: Don Fry is an 80 column neatnik.
> 
> Please remember this depends on patch 1/22 being applied
> before this patch can be successfully applied.
> 
>  drivers/net/ethernet/amd/pcnet32.c | 18 ++++++++----------
>  1 file changed, 8 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/net/ethernet/amd/pcnet32.c b/drivers/net/ethernet/amd/pcnet32.c
> index e7cc917..8099fdc 100644
> --- a/drivers/net/ethernet/amd/pcnet32.c
> +++ b/drivers/net/ethernet/amd/pcnet32.c
> @@ -484,15 +484,14 @@ static void pcnet32_realloc_tx_ring(struct net_device *dev,
>  
>  	pcnet32_purge_tx_ring(dev);
>  
> -	new_tx_ring = pci_alloc_consistent(lp->pci_dev,
> -					   sizeof(struct pcnet32_tx_head) *
> -					   (1 << size),
> -					   &new_ring_dma_addr);

Acked-By: Don Fry <pcnet32@frontier.com>

> 
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH] amd: Neaten and remove unnecessary OOM messages
  2014-06-23 21:36         ` [PATCH] amd: Neaten and remove unnecessary OOM messages Joe Perches
@ 2014-06-23 22:42           ` Don Fry
  2014-06-25 23:32           ` David Miller
  1 sibling, 0 replies; 33+ messages in thread
From: Don Fry @ 2014-06-23 22:42 UTC (permalink / raw)
  To: Joe Perches; +Cc: linux-kernel, netdev

On Mon, 2014-06-23 at 14:36 -0700, Joe Perches wrote:
> Make the code flow a little better for 80 columns.
> 
> Use a consistent style for the RX and TX rings allocation.
> Use BIT macro.
> Use a temporary unsiged int entries for (1<<size).
> Remove the OOM messages as they duplicate the generic
> OOM and dump_stack() provided by the memory subsystem.
> Reflow allocs to 80 columns.
> 
> Signed-off-by: Joe Perches <joe@perches.com>
> ---
>  drivers/net/ethernet/amd/pcnet32.c | 43 ++++++++++++++++----------------------
>  1 file changed, 18 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/net/ethernet/amd/pcnet32.c b/drivers/net/ethernet/amd/pcnet32.c
> index 8099fdc..4a8fdc4 100644
> --- a/drivers/net/ethernet/amd/pcnet32.c
> +++ b/drivers/net/ethernet/amd/pcnet32.c
> @@ -481,36 +481,32 @@ static void pcnet32_realloc_tx_ring(struct net_device *dev,
>  	dma_addr_t *new_dma_addr_list;

Acked-By: Don Fry <pcnet32@frontier.com>

> 
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 00/22] Add and use pci_zalloc_consistent
  2014-06-23 19:13   ` Joe Perches
@ 2014-06-23 23:27     ` Julian Calaby
  2014-06-24 11:32       ` Johannes Berg
  0 siblings, 1 reply; 33+ messages in thread
From: Julian Calaby @ 2014-06-23 23:27 UTC (permalink / raw)
  To: Joe Perches
  Cc: Luis R. Rodriguez, Arnd Bergmann, linux-kernel@vger.kernel.org,
	devel@driverdev.osuosl.org, linux-arch, linux-scsi,
	iss_storagedev, linux-rdma, netdev, linux-atm-general,
	linux-wireless, dri-devel, linux-crypto, linux-eata, linux-media

Hi Joe,

On Tue, Jun 24, 2014 at 5:13 AM, Joe Perches <joe@perches.com> wrote:
> On Mon, 2014-06-23 at 10:25 -0700, Luis R. Rodriguez wrote:
>> On Mon, Jun 23, 2014 at 06:41:28AM -0700, Joe Perches wrote:
>> > Adding the helper reduces object code size as well as overall
>> > source size line count.
>> >
>> > It's also consistent with all the various zalloc mechanisms
>> > in the kernel.
>> >
>> > Done with a simple cocci script and some typing.
>>
>> Awesome, any chance you can paste in the SmPL? Also any chance
>> we can get this added to a make coccicheck so that maintainers
>> moving forward can use that to ensure that no new code is
>> added that uses the old school API?
>
> Not many of these are recent.
>
> Arnd Bergmann reasonably suggested that the pci_alloc_consistent
> api be converted the the more widely used dma_alloc_coherent.
>
> https://lkml.org/lkml/2014/6/23/513
>
>> Shouldn't these drivers just use the normal dma-mapping API now?
>
> and I replied:
>
> https://lkml.org/lkml/2014/6/23/525
>
>> Maybe.  I wouldn't mind.
>> They do seem to have a trivial bit of unnecessary overhead for
>> hwdev == NULL ? NULL : &hwdev->dev
>
> Anyway, here's the little script.
> I'm not sure it's worthwhile to add it though.
>
> $ cat ./scripts/coccinelle/api/alloc/pci_zalloc_consistent.cocci
> ///
> /// Use pci_zalloc_consistent rather than
> ///     pci_alloc_consistent followed by memset with 0
> ///
> /// This considers some simple cases that are common and easy to validate
> /// Note in particular that there are no ...s in the rule, so all of the
> /// matched code has to be contiguous
> ///
> /// Blatantly cribbed from: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
>
> @@
> type T, T2;
> expression x;
> expression E1,E2,E3;
> statement S;
> @@
>
> - x = (T)pci_alloc_consistent(E1,E2,E3);
> + x = pci_zalloc_consistent(E1,E2,E3);
>   if ((x==NULL) || ...) S
> - memset((T2)x,0,E2);

I don't know much about SmPL, but wouldn't having that if statement
there reduce your matches?

Thanks,

-- 
Julian Calaby

Email: julian.calaby@gmail.com
Profile: http://www.google.com/profiles/julian.calaby/
.Plan: http://sites.google.com/site/juliancalaby/

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

* Re: [PATCH 00/22] Add and use pci_zalloc_consistent
  2014-06-23 23:27     ` Julian Calaby
@ 2014-06-24 11:32       ` Johannes Berg
  0 siblings, 0 replies; 33+ messages in thread
From: Johannes Berg @ 2014-06-24 11:32 UTC (permalink / raw)
  To: Julian Calaby
  Cc: Joe Perches, Luis R. Rodriguez, Arnd Bergmann,
	linux-kernel@vger.kernel.org, devel@driverdev.osuosl.org,
	linux-arch, linux-scsi, iss_storagedev, linux-rdma, netdev,
	linux-atm-general, linux-wireless, dri-devel, linux-crypto,
	linux-eata, linux-media

On Tue, 2014-06-24 at 09:27 +1000, Julian Calaby wrote:

> > - x = (T)pci_alloc_consistent(E1,E2,E3);
> > + x = pci_zalloc_consistent(E1,E2,E3);
> >   if ((x==NULL) || ...) S
> > - memset((T2)x,0,E2);
> 
> I don't know much about SmPL, but wouldn't having that if statement
> there reduce your matches?

Code that matched without the if statement would be buggy, since it
wouldn't be checking the pci_zalloc_consistent return value properly.l

johannes

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

* Re: [PATCH V2 08/22] amd: Use pci_zalloc_consistent
  2014-06-23 21:05       ` [PATCH V2 " Joe Perches
  2014-06-23 21:36         ` [PATCH] amd: Neaten and remove unnecessary OOM messages Joe Perches
  2014-06-23 22:22         ` [PATCH V2 08/22] amd: Use pci_zalloc_consistent Don Fry
@ 2014-06-25  4:49         ` Guenter Roeck
  2014-06-25  4:59           ` Joe Perches
  2014-06-25 23:55         ` [PATCH V2] pcnet32: Neaten and remove unnecessary OOM messages Joe Perches
  3 siblings, 1 reply; 33+ messages in thread
From: Guenter Roeck @ 2014-06-25  4:49 UTC (permalink / raw)
  To: Joe Perches, Don Fry; +Cc: linux-kernel, netdev

On 06/23/2014 02:05 PM, Joe Perches wrote:
> Remove the now unnecessary memset too.
>
> Signed-off-by: Joe Perches <joe@perches.com>
> ---
> On Mon, 2014-06-23 at 12:15 -0700, Joe Perches wrote:
>> On Mon, 2014-06-23 at 11:02 -0700, Don Fry wrote:
>>> This causes the line length to be greater than 80 characters causing
>>> checkpatch to complain.
>
> V2: Don Fry is an 80 column neatnik.
>

And you are an 'align with (' neatnik, so guess the two of you are even :-)

Guenter

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

* Re: [PATCH V2 08/22] amd: Use pci_zalloc_consistent
  2014-06-25  4:49         ` Guenter Roeck
@ 2014-06-25  4:59           ` Joe Perches
  0 siblings, 0 replies; 33+ messages in thread
From: Joe Perches @ 2014-06-25  4:59 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Don Fry, linux-kernel, netdev

On Tue, 2014-06-24 at 21:49 -0700, Guenter Roeck wrote:
> On 06/23/2014 02:05 PM, Joe Perches wrote:
> > V2: Don Fry is an 80 column neatnik.
> And you are an 'align with (' neatnik, so guess the two of you are even :-)

Guilty.

The editor (emacs in my case) allows me to forget I am one though.

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

* Re: [PATCH 00/22] Add and use pci_zalloc_consistent
  2014-06-23 13:41 [PATCH 00/22] Add and use pci_zalloc_consistent Joe Perches
                   ` (13 preceding siblings ...)
       [not found] ` <cover.1403530604.git.joe-6d6DIl74uiNBDgjK7y7TUQ@public.gmane.org>
@ 2014-06-25 19:41 ` John W. Linville
  14 siblings, 0 replies; 33+ messages in thread
From: John W. Linville @ 2014-06-25 19:41 UTC (permalink / raw)
  To: Joe Perches
  Cc: linux-kernel, linux-atm-general, netdev, iss_storagedev,
	linux-crypto, dri-devel, linux-rdma, linux-media, linux-wireless,
	linux-scsi, linux-eata, devel, linux-arch

On Mon, Jun 23, 2014 at 06:41:28AM -0700, Joe Perches wrote:
> Adding the helper reduces object code size as well as overall
> source size line count.
> 
> It's also consistent with all the various zalloc mechanisms
> in the kernel.
> 
> Done with a simple cocci script and some typing.
> 
> Joe Perches (22):

>   ipw2100: Use pci_zalloc_consistent
>   mwl8k: Use pci_zalloc_consistent
>   rtl818x: Use pci_zalloc_consistent
>   rtlwifi: Use pci_zalloc_consistent

Sure, fine by me.

-- 
John W. Linville		Someday the world will need a hero, and you
linville@tuxdriver.com			might be all we have.  Be ready.

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

* Re: [PATCH] amd: Neaten and remove unnecessary OOM messages
  2014-06-23 21:36         ` [PATCH] amd: Neaten and remove unnecessary OOM messages Joe Perches
  2014-06-23 22:42           ` Don Fry
@ 2014-06-25 23:32           ` David Miller
  1 sibling, 0 replies; 33+ messages in thread
From: David Miller @ 2014-06-25 23:32 UTC (permalink / raw)
  To: joe; +Cc: pcnet32, linux-kernel, netdev

From: Joe Perches <joe@perches.com>
Date: Mon, 23 Jun 2014 14:36:35 -0700

> Make the code flow a little better for 80 columns.
> 
> Use a consistent style for the RX and TX rings allocation.
> Use BIT macro.
> Use a temporary unsiged int entries for (1<<size).
> Remove the OOM messages as they duplicate the generic
> OOM and dump_stack() provided by the memory subsystem.
> Reflow allocs to 80 columns.
> 
> Signed-off-by: Joe Perches <joe@perches.com>

Please repost with adjusted subject prefix (amd --> pcnet32), thanks.

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

* [PATCH V3 08/22] pcnet32: Use pci_zalloc_consistent
  2014-06-23 19:15     ` Joe Perches
  2014-06-23 21:05       ` [PATCH V2 " Joe Perches
@ 2014-06-25 23:51       ` Joe Perches
  1 sibling, 0 replies; 33+ messages in thread
From: Joe Perches @ 2014-06-25 23:51 UTC (permalink / raw)
  To: Don Fry; +Cc: linux-kernel, netdev, Andrew Morton, David Miller

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <joe@perches.com>
Acked-by: Don Fry <pcnet32@frontier.com>
---
On Mon, 2014-06-23 at 12:15 -0700, Joe Perches wrote:
> On Mon, 2014-06-23 at 11:02 -0700, Don Fry wrote:
> > This causes the line length to be greater than 80 characters causing
> > checkpatch to complain.

V3: Use better patch prefix pcnet32, amd is too generic
V2: Don Fry is an 80 column neatnik.

Please remember this depends on patch 1/22 being applied
before this patch can be successfully applied.

 drivers/net/ethernet/amd/pcnet32.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/amd/pcnet32.c b/drivers/net/ethernet/amd/pcnet32.c
index e7cc917..8099fdc 100644
--- a/drivers/net/ethernet/amd/pcnet32.c
+++ b/drivers/net/ethernet/amd/pcnet32.c
@@ -484,15 +484,14 @@ static void pcnet32_realloc_tx_ring(struct net_device *dev,
 
 	pcnet32_purge_tx_ring(dev);
 
-	new_tx_ring = pci_alloc_consistent(lp->pci_dev,
-					   sizeof(struct pcnet32_tx_head) *
-					   (1 << size),
-					   &new_ring_dma_addr);
+	new_tx_ring = pci_zalloc_consistent(lp->pci_dev,
+					    sizeof(struct pcnet32_tx_head) *
+					    (1 << size),
+					    &new_ring_dma_addr);
 	if (new_tx_ring == NULL) {
 		netif_err(lp, drv, dev, "Consistent memory allocation failed\n");
 		return;
 	}
-	memset(new_tx_ring, 0, sizeof(struct pcnet32_tx_head) * (1 << size));
 
 	new_dma_addr_list = kcalloc(1 << size, sizeof(dma_addr_t),
 				    GFP_ATOMIC);
@@ -551,15 +550,14 @@ static void pcnet32_realloc_rx_ring(struct net_device *dev,
 	int new, overlap;
 	unsigned int entries = 1 << size;
 
-	new_rx_ring = pci_alloc_consistent(lp->pci_dev,
-					   sizeof(struct pcnet32_rx_head) *
-					   entries,
-					   &new_ring_dma_addr);
+	new_rx_ring = pci_zalloc_consistent(lp->pci_dev,
+					    sizeof(struct pcnet32_rx_head) *
+					    entries,
+					    &new_ring_dma_addr);
 	if (new_rx_ring == NULL) {
 		netif_err(lp, drv, dev, "Consistent memory allocation failed\n");
 		return;
 	}
-	memset(new_rx_ring, 0, sizeof(struct pcnet32_rx_head) * entries);
 
 	new_dma_addr_list = kcalloc(entries, sizeof(dma_addr_t), GFP_ATOMIC);
 	if (!new_dma_addr_list)

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

* [PATCH V2] pcnet32: Neaten and remove unnecessary OOM messages
  2014-06-23 21:05       ` [PATCH V2 " Joe Perches
                           ` (2 preceding siblings ...)
  2014-06-25  4:49         ` Guenter Roeck
@ 2014-06-25 23:55         ` Joe Perches
  2014-07-01 19:19           ` David Miller
  3 siblings, 1 reply; 33+ messages in thread
From: Joe Perches @ 2014-06-25 23:55 UTC (permalink / raw)
  To: Don Fry; +Cc: linux-kernel, netdev, Andrew Morton, David Miller

Make the code flow a little better for 80 columns.

Use a consistent style for the RX and TX rings allocation.
Use BIT macro.
Use a temporary unsigned int entries for (1<<size).
Remove the OOM messages as they duplicate the generic
OOM and dump_stack() provided by the memory subsystem.
Reflow allocs to 80 columns.

Signed-off-by: Joe Perches <joe@perches.com>
Acked-by: Don Fry <pcnet32@frontier.com>
---
V2: Use pcnet32 as patch prefix, amd is too generic

Still depends on patch 1/22: pci-dma-compat: Add pci_zalloc_consistent helper

 drivers/net/ethernet/amd/pcnet32.c | 43 ++++++++++++++++----------------------
 1 file changed, 18 insertions(+), 25 deletions(-)

diff --git a/drivers/net/ethernet/amd/pcnet32.c b/drivers/net/ethernet/amd/pcnet32.c
index 8099fdc..4a8fdc4 100644
--- a/drivers/net/ethernet/amd/pcnet32.c
+++ b/drivers/net/ethernet/amd/pcnet32.c
@@ -481,36 +481,32 @@ static void pcnet32_realloc_tx_ring(struct net_device *dev,
 	dma_addr_t *new_dma_addr_list;
 	struct pcnet32_tx_head *new_tx_ring;
 	struct sk_buff **new_skb_list;
+	unsigned int entries = BIT(size);
 
 	pcnet32_purge_tx_ring(dev);
 
-	new_tx_ring = pci_zalloc_consistent(lp->pci_dev,
-					    sizeof(struct pcnet32_tx_head) *
-					    (1 << size),
-					    &new_ring_dma_addr);
-	if (new_tx_ring == NULL) {
-		netif_err(lp, drv, dev, "Consistent memory allocation failed\n");
+	new_tx_ring =
+		pci_zalloc_consistent(lp->pci_dev,
+				      sizeof(struct pcnet32_tx_head) * entries,
+				      &new_ring_dma_addr);
+	if (new_tx_ring == NULL)
 		return;
-	}
 
-	new_dma_addr_list = kcalloc(1 << size, sizeof(dma_addr_t),
-				    GFP_ATOMIC);
+	new_dma_addr_list = kcalloc(entries, sizeof(dma_addr_t), GFP_ATOMIC);
 	if (!new_dma_addr_list)
 		goto free_new_tx_ring;
 
-	new_skb_list = kcalloc(1 << size, sizeof(struct sk_buff *),
-			       GFP_ATOMIC);
+	new_skb_list = kcalloc(entries, sizeof(struct sk_buff *), GFP_ATOMIC);
 	if (!new_skb_list)
 		goto free_new_lists;
 
 	kfree(lp->tx_skbuff);
 	kfree(lp->tx_dma_addr);
 	pci_free_consistent(lp->pci_dev,
-			    sizeof(struct pcnet32_tx_head) *
-			    lp->tx_ring_size, lp->tx_ring,
-			    lp->tx_ring_dma_addr);
+			    sizeof(struct pcnet32_tx_head) * lp->tx_ring_size,
+			    lp->tx_ring, lp->tx_ring_dma_addr);
 
-	lp->tx_ring_size = (1 << size);
+	lp->tx_ring_size = entries;
 	lp->tx_mod_mask = lp->tx_ring_size - 1;
 	lp->tx_len_bits = (size << 12);
 	lp->tx_ring = new_tx_ring;
@@ -523,8 +519,7 @@ free_new_lists:
 	kfree(new_dma_addr_list);
 free_new_tx_ring:
 	pci_free_consistent(lp->pci_dev,
-			    sizeof(struct pcnet32_tx_head) *
-			    (1 << size),
+			    sizeof(struct pcnet32_tx_head) * entries,
 			    new_tx_ring,
 			    new_ring_dma_addr);
 }
@@ -548,16 +543,14 @@ static void pcnet32_realloc_rx_ring(struct net_device *dev,
 	struct pcnet32_rx_head *new_rx_ring;
 	struct sk_buff **new_skb_list;
 	int new, overlap;
-	unsigned int entries = 1 << size;
+	unsigned int entries = BIT(size);
 
-	new_rx_ring = pci_zalloc_consistent(lp->pci_dev,
-					    sizeof(struct pcnet32_rx_head) *
-					    entries,
-					    &new_ring_dma_addr);
-	if (new_rx_ring == NULL) {
-		netif_err(lp, drv, dev, "Consistent memory allocation failed\n");
+	new_rx_ring =
+		pci_zalloc_consistent(lp->pci_dev,
+				      sizeof(struct pcnet32_rx_head) * entries,
+				      &new_ring_dma_addr);
+	if (new_rx_ring == NULL)
 		return;
-	}
 
 	new_dma_addr_list = kcalloc(entries, sizeof(dma_addr_t), GFP_ATOMIC);
 	if (!new_dma_addr_list)

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

* Re: [PATCH 10/22] enic: Use pci_zalloc_consistent
  2014-06-23 13:41 ` [PATCH 10/22] enic: " Joe Perches
@ 2014-06-26  6:27   ` Govindarajulu Varadarajan
  0 siblings, 0 replies; 33+ messages in thread
From: Govindarajulu Varadarajan @ 2014-06-26  6:27 UTC (permalink / raw)
  To: Joe Perches
  Cc: linux-kernel, Christian Benvenuti, Sujith Sankar,
	Govindarajulu Varadarajan, Neel Patel, netdev



On Mon, 23 Jun 2014, Joe Perches wrote:

> Remove the now unnecessary memset too.
>
> Signed-off-by: Joe Perches <joe@perches.com>

Looks good, thanks
Acked-by: Govindarajulu Varadarajan <_govind@gmx.com>

> ---
> drivers/net/ethernet/cisco/enic/vnic_dev.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/ethernet/cisco/enic/vnic_dev.c b/drivers/net/ethernet/cisco/enic/vnic_dev.c
> index e86a45c..8a4799c 100644
> --- a/drivers/net/ethernet/cisco/enic/vnic_dev.c
> +++ b/drivers/net/ethernet/cisco/enic/vnic_dev.c
> @@ -432,14 +432,12 @@ int vnic_dev_fw_info(struct vnic_dev *vdev,
> 	int err = 0;
>
> 	if (!vdev->fw_info) {
> -		vdev->fw_info = pci_alloc_consistent(vdev->pdev,
> -			sizeof(struct vnic_devcmd_fw_info),
> -			&vdev->fw_info_pa);
> +		vdev->fw_info = pci_zalloc_consistent(vdev->pdev,
> +						      sizeof(struct vnic_devcmd_fw_info),
> +						      &vdev->fw_info_pa);
> 		if (!vdev->fw_info)
> 			return -ENOMEM;
>
> -		memset(vdev->fw_info, 0, sizeof(struct vnic_devcmd_fw_info));
> -
> 		a0 = vdev->fw_info_pa;
> 		a1 = sizeof(struct vnic_devcmd_fw_info);
>
> -- 
> 1.8.1.2.459.gbcd45b4.dirty
>
>

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

* Re: [PATCH V2] pcnet32: Neaten and remove unnecessary OOM messages
  2014-06-25 23:55         ` [PATCH V2] pcnet32: Neaten and remove unnecessary OOM messages Joe Perches
@ 2014-07-01 19:19           ` David Miller
  2014-07-01 19:26             ` Joe Perches
  0 siblings, 1 reply; 33+ messages in thread
From: David Miller @ 2014-07-01 19:19 UTC (permalink / raw)
  To: joe; +Cc: pcnet32, linux-kernel, netdev, akpm

From: Joe Perches <joe@perches.com>
Date: Wed, 25 Jun 2014 16:55:25 -0700

> Make the code flow a little better for 80 columns.
> 
> Use a consistent style for the RX and TX rings allocation.
> Use BIT macro.
> Use a temporary unsigned int entries for (1<<size).
> Remove the OOM messages as they duplicate the generic
> OOM and dump_stack() provided by the memory subsystem.
> Reflow allocs to 80 columns.
> 
> Signed-off-by: Joe Perches <joe@perches.com>
> Acked-by: Don Fry <pcnet32@frontier.com>
> ---
> V2: Use pcnet32 as patch prefix, amd is too generic
> 
> Still depends on patch 1/22: pci-dma-compat: Add pci_zalloc_consistent helper

If this has a dependency on a patch I'm not added to my tree, I'm not
applying this one either.

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

* Re: [PATCH V2] pcnet32: Neaten and remove unnecessary OOM messages
  2014-07-01 19:19           ` David Miller
@ 2014-07-01 19:26             ` Joe Perches
  0 siblings, 0 replies; 33+ messages in thread
From: Joe Perches @ 2014-07-01 19:26 UTC (permalink / raw)
  To: David Miller; +Cc: pcnet32, linux-kernel, netdev, akpm

On Tue, 2014-07-01 at 12:19 -0700, David Miller wrote:
> From: Joe Perches <joe@perches.com> Date: Wed, 25 Jun 2014 16:55:25 -0700
> > Make the code flow a little better for 80 columns.
[]
> > Still depends on patch 1/22: pci-dma-compat: Add pci_zalloc_consistent helper
> 
> If this has a dependency on a patch I'm not added to my tree, I'm not
> applying this one either.

No worries, Andrew picked them up and they are
queued in -next (with the less good subject prefix)

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

end of thread, other threads:[~2014-07-01 19:26 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-23 13:41 [PATCH 00/22] Add and use pci_zalloc_consistent Joe Perches
2014-06-23 13:41 ` [PATCH 02/22] atm: Use pci_zalloc_consistent Joe Perches
2014-06-23 13:41 ` [PATCH 08/22] amd: " Joe Perches
2014-06-23 18:02   ` Don Fry
2014-06-23 19:15     ` Joe Perches
2014-06-23 21:05       ` [PATCH V2 " Joe Perches
2014-06-23 21:36         ` [PATCH] amd: Neaten and remove unnecessary OOM messages Joe Perches
2014-06-23 22:42           ` Don Fry
2014-06-25 23:32           ` David Miller
2014-06-23 22:22         ` [PATCH V2 08/22] amd: Use pci_zalloc_consistent Don Fry
2014-06-25  4:49         ` Guenter Roeck
2014-06-25  4:59           ` Joe Perches
2014-06-25 23:55         ` [PATCH V2] pcnet32: Neaten and remove unnecessary OOM messages Joe Perches
2014-07-01 19:19           ` David Miller
2014-07-01 19:26             ` Joe Perches
2014-06-25 23:51       ` [PATCH V3 08/22] pcnet32: Use pci_zalloc_consistent Joe Perches
2014-06-23 13:41 ` [PATCH 09/22] atl1e: " Joe Perches
2014-06-23 13:41 ` [PATCH 10/22] enic: " Joe Perches
2014-06-26  6:27   ` Govindarajulu Varadarajan
2014-06-23 13:41 ` [PATCH 11/22] sky2: " Joe Perches
2014-06-23 13:41 ` [PATCH 12/22] micrel: " Joe Perches
2014-06-23 13:41 ` [PATCH 13/22] qlogic: " Joe Perches
2014-06-23 13:41 ` [PATCH 14/22] irda: " Joe Perches
2014-06-23 13:41 ` [PATCH 15/22] ipw2100: " Joe Perches
2014-06-23 13:41 ` [PATCH 16/22] mwl8k: " Joe Perches
2014-06-23 13:41 ` [PATCH 17/22] rtl818x: " Joe Perches
2014-06-23 13:41 ` [PATCH 18/22] rtlwifi: " Joe Perches
2014-06-23 17:25 ` [PATCH 00/22] Add and use pci_zalloc_consistent Luis R. Rodriguez
2014-06-23 19:13   ` Joe Perches
2014-06-23 23:27     ` Julian Calaby
2014-06-24 11:32       ` Johannes Berg
     [not found] ` <cover.1403530604.git.joe-6d6DIl74uiNBDgjK7y7TUQ@public.gmane.org>
2014-06-23 21:49   ` David Miller
2014-06-25 19:41 ` John W. Linville

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).