2014-06-23 13:42:32

by Joe Perches

[permalink] [raw]
Subject: [PATCH 00/22] Add and use pci_zalloc_consistent

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


2014-06-23 13:42:13

by Joe Perches

[permalink] [raw]
Subject: [PATCH 01/22] pci-dma-compat: Add pci_zalloc_consistent helper

Add this helper for consistency with pci_zalloc_coherent
and the ability to remove unnecessary memset(,0,) uses.

Signed-off-by: Joe Perches <[email protected]>
---
include/asm-generic/pci-dma-compat.h | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/include/asm-generic/pci-dma-compat.h b/include/asm-generic/pci-dma-compat.h
index 1437b7d..c110843 100644
--- a/include/asm-generic/pci-dma-compat.h
+++ b/include/asm-generic/pci-dma-compat.h
@@ -19,6 +19,14 @@ pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
return dma_alloc_coherent(hwdev == NULL ? NULL : &hwdev->dev, size, dma_handle, GFP_ATOMIC);
}

+static inline void *
+pci_zalloc_consistent(struct pci_dev *hwdev, size_t size,
+ dma_addr_t *dma_handle)
+{
+ return dma_zalloc_coherent(hwdev == NULL ? NULL : &hwdev->dev,
+ size, dma_handle, GFP_ATOMIC);
+}
+
static inline void
pci_free_consistent(struct pci_dev *hwdev, size_t size,
void *vaddr, dma_addr_t dma_handle)
--
1.8.1.2.459.gbcd45b4.dirty

2014-06-23 13:42:19

by Joe Perches

[permalink] [raw]
Subject: [PATCH 03/22] block: Use pci_zalloc_consistent

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <[email protected]>
---
drivers/block/DAC960.c | 18 +++++++++---------
drivers/block/cciss.c | 11 ++++-------
drivers/block/skd_main.c | 25 +++++++++----------------
3 files changed, 22 insertions(+), 32 deletions(-)

diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c
index 125d845..811e11c 100644
--- a/drivers/block/DAC960.c
+++ b/drivers/block/DAC960.c
@@ -6741,11 +6741,11 @@ static long DAC960_gam_ioctl(struct file *file, unsigned int Request,
ErrorCode = -ENOMEM;
if (DataTransferLength > 0)
{
- DataTransferBuffer = pci_alloc_consistent(Controller->PCIDevice,
- DataTransferLength, &DataTransferBufferDMA);
+ DataTransferBuffer = pci_zalloc_consistent(Controller->PCIDevice,
+ DataTransferLength,
+ &DataTransferBufferDMA);
if (DataTransferBuffer == NULL)
break;
- memset(DataTransferBuffer, 0, DataTransferLength);
}
else if (DataTransferLength < 0)
{
@@ -6877,11 +6877,11 @@ static long DAC960_gam_ioctl(struct file *file, unsigned int Request,
ErrorCode = -ENOMEM;
if (DataTransferLength > 0)
{
- DataTransferBuffer = pci_alloc_consistent(Controller->PCIDevice,
- DataTransferLength, &DataTransferBufferDMA);
+ DataTransferBuffer = pci_zalloc_consistent(Controller->PCIDevice,
+ DataTransferLength,
+ &DataTransferBufferDMA);
if (DataTransferBuffer == NULL)
break;
- memset(DataTransferBuffer, 0, DataTransferLength);
}
else if (DataTransferLength < 0)
{
@@ -6899,14 +6899,14 @@ static long DAC960_gam_ioctl(struct file *file, unsigned int Request,
RequestSenseLength = UserCommand.RequestSenseLength;
if (RequestSenseLength > 0)
{
- RequestSenseBuffer = pci_alloc_consistent(Controller->PCIDevice,
- RequestSenseLength, &RequestSenseBufferDMA);
+ RequestSenseBuffer = pci_zalloc_consistent(Controller->PCIDevice,
+ RequestSenseLength,
+ &RequestSenseBufferDMA);
if (RequestSenseBuffer == NULL)
{
ErrorCode = -ENOMEM;
goto Failure2;
}
- memset(RequestSenseBuffer, 0, RequestSenseLength);
}
spin_lock_irqsave(&Controller->queue_lock, flags);
while ((Command = DAC960_AllocateCommand(Controller)) == NULL)
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 4595c22..ff20f19 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -1014,24 +1014,21 @@ static CommandList_struct *cmd_special_alloc(ctlr_info_t *h)
u64bit temp64;
dma_addr_t cmd_dma_handle, err_dma_handle;

- c = (CommandList_struct *) pci_alloc_consistent(h->pdev,
- sizeof(CommandList_struct), &cmd_dma_handle);
+ c = pci_zalloc_consistent(h->pdev, sizeof(CommandList_struct),
+ &cmd_dma_handle);
if (c == NULL)
return NULL;
- memset(c, 0, sizeof(CommandList_struct));

c->cmdindex = -1;

- c->err_info = (ErrorInfo_struct *)
- pci_alloc_consistent(h->pdev, sizeof(ErrorInfo_struct),
- &err_dma_handle);
+ c->err_info = pci_zalloc_consistent(h->pdev, sizeof(ErrorInfo_struct),
+ &err_dma_handle);

if (c->err_info == NULL) {
pci_free_consistent(h->pdev,
sizeof(CommandList_struct), c, cmd_dma_handle);
return NULL;
}
- memset(c->err_info, 0, sizeof(ErrorInfo_struct));

INIT_LIST_HEAD(&c->list);
c->busaddr = (__u32) cmd_dma_handle;
diff --git a/drivers/block/skd_main.c b/drivers/block/skd_main.c
index 608532d..f0a089d 100644
--- a/drivers/block/skd_main.c
+++ b/drivers/block/skd_main.c
@@ -4112,16 +4112,14 @@ static int skd_cons_skcomp(struct skd_device *skdev)
skdev->name, __func__, __LINE__,
nbytes, SKD_N_COMPLETION_ENTRY);

- skcomp = pci_alloc_consistent(skdev->pdev, nbytes,
- &skdev->cq_dma_address);
+ skcomp = pci_zalloc_consistent(skdev->pdev, nbytes,
+ &skdev->cq_dma_address);

if (skcomp == NULL) {
rc = -ENOMEM;
goto err_out;
}

- memset(skcomp, 0, nbytes);
-
skdev->skcomp_table = skcomp;
skdev->skerr_table = (struct fit_comp_error_info *)((char *)skcomp +
sizeof(*skcomp) *
@@ -4304,15 +4302,14 @@ static int skd_cons_skspcl(struct skd_device *skdev)

nbytes = SKD_N_SPECIAL_FITMSG_BYTES;

- skspcl->msg_buf = pci_alloc_consistent(skdev->pdev, nbytes,
- &skspcl->mb_dma_address);
+ skspcl->msg_buf =
+ pci_zalloc_consistent(skdev->pdev, nbytes,
+ &skspcl->mb_dma_address);
if (skspcl->msg_buf == NULL) {
rc = -ENOMEM;
goto err_out;
}

- memset(skspcl->msg_buf, 0, nbytes);
-
skspcl->req.sg = kzalloc(sizeof(struct scatterlist) *
SKD_N_SG_PER_SPECIAL, GFP_KERNEL);
if (skspcl->req.sg == NULL) {
@@ -4353,25 +4350,21 @@ static int skd_cons_sksb(struct skd_device *skdev)

nbytes = SKD_N_INTERNAL_BYTES;

- skspcl->data_buf = pci_alloc_consistent(skdev->pdev, nbytes,
- &skspcl->db_dma_address);
+ skspcl->data_buf = pci_zalloc_consistent(skdev->pdev, nbytes,
+ &skspcl->db_dma_address);
if (skspcl->data_buf == NULL) {
rc = -ENOMEM;
goto err_out;
}

- memset(skspcl->data_buf, 0, nbytes);
-
nbytes = SKD_N_SPECIAL_FITMSG_BYTES;
- skspcl->msg_buf = pci_alloc_consistent(skdev->pdev, nbytes,
- &skspcl->mb_dma_address);
+ skspcl->msg_buf = pci_zalloc_consistent(skdev->pdev, nbytes,
+ &skspcl->mb_dma_address);
if (skspcl->msg_buf == NULL) {
rc = -ENOMEM;
goto err_out;
}

- memset(skspcl->msg_buf, 0, nbytes);
-
skspcl->req.sksg_list = skd_cons_sg_list(skdev, 1,
&skspcl->req.sksg_dma_address);
if (skspcl->req.sksg_list == NULL) {
--
1.8.1.2.459.gbcd45b4.dirty

2014-06-23 13:42:26

by Joe Perches

[permalink] [raw]
Subject: [PATCH 05/22] infiniband: Use pci_zalloc_consistent

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <[email protected]>
---
drivers/infiniband/hw/amso1100/c2.c | 6 ++----
drivers/infiniband/hw/nes/nes_hw.c | 12 ++++++------
drivers/infiniband/hw/nes/nes_verbs.c | 5 ++---
3 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/drivers/infiniband/hw/amso1100/c2.c b/drivers/infiniband/hw/amso1100/c2.c
index 00400c3..766a71c 100644
--- a/drivers/infiniband/hw/amso1100/c2.c
+++ b/drivers/infiniband/hw/amso1100/c2.c
@@ -604,16 +604,14 @@ static int c2_up(struct net_device *netdev)
tx_size = c2_port->tx_ring.count * sizeof(struct c2_tx_desc);

c2_port->mem_size = tx_size + rx_size;
- c2_port->mem = pci_alloc_consistent(c2dev->pcidev, c2_port->mem_size,
- &c2_port->dma);
+ c2_port->mem = pci_zalloc_consistent(c2dev->pcidev, c2_port->mem_size,
+ &c2_port->dma);
if (c2_port->mem == NULL) {
pr_debug("Unable to allocate memory for "
"host descriptor rings\n");
return -ENOMEM;
}

- memset(c2_port->mem, 0, c2_port->mem_size);
-
/* Create the Rx host descriptor ring */
if ((ret =
c2_rx_ring_alloc(&c2_port->rx_ring, c2_port->mem, c2_port->dma,
diff --git a/drivers/infiniband/hw/nes/nes_hw.c b/drivers/infiniband/hw/nes/nes_hw.c
index 9020024..02120d3 100644
--- a/drivers/infiniband/hw/nes/nes_hw.c
+++ b/drivers/infiniband/hw/nes/nes_hw.c
@@ -1003,13 +1003,13 @@ int nes_init_cqp(struct nes_device *nesdev)
(sizeof(struct nes_hw_aeqe) * nesadapter->max_qp) +
sizeof(struct nes_hw_cqp_qp_context);

- nesdev->cqp_vbase = pci_alloc_consistent(nesdev->pcidev, nesdev->cqp_mem_size,
- &nesdev->cqp_pbase);
+ nesdev->cqp_vbase = pci_zalloc_consistent(nesdev->pcidev,
+ nesdev->cqp_mem_size,
+ &nesdev->cqp_pbase);
if (!nesdev->cqp_vbase) {
nes_debug(NES_DBG_INIT, "Unable to allocate memory for host descriptor rings\n");
return -ENOMEM;
}
- memset(nesdev->cqp_vbase, 0, nesdev->cqp_mem_size);

/* Allocate a twice the number of CQP requests as the SQ size */
nesdev->nes_cqp_requests = kzalloc(sizeof(struct nes_cqp_request) *
@@ -1691,13 +1691,13 @@ int nes_init_nic_qp(struct nes_device *nesdev, struct net_device *netdev)
(NES_NIC_WQ_SIZE * 2 * sizeof(struct nes_hw_nic_cqe)) +
sizeof(struct nes_hw_nic_qp_context);

- nesvnic->nic_vbase = pci_alloc_consistent(nesdev->pcidev, nesvnic->nic_mem_size,
- &nesvnic->nic_pbase);
+ nesvnic->nic_vbase = pci_zalloc_consistent(nesdev->pcidev,
+ nesvnic->nic_mem_size,
+ &nesvnic->nic_pbase);
if (!nesvnic->nic_vbase) {
nes_debug(NES_DBG_INIT, "Unable to allocate memory for NIC host descriptor rings\n");
return -ENOMEM;
}
- memset(nesvnic->nic_vbase, 0, nesvnic->nic_mem_size);
nes_debug(NES_DBG_INIT, "Allocated NIC QP structures at %p (phys = %016lX), size = %u.\n",
nesvnic->nic_vbase, (unsigned long)nesvnic->nic_pbase, nesvnic->nic_mem_size);

diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
index 218dd35..fef067c 100644
--- a/drivers/infiniband/hw/nes/nes_verbs.c
+++ b/drivers/infiniband/hw/nes/nes_verbs.c
@@ -1616,8 +1616,8 @@ static struct ib_cq *nes_create_cq(struct ib_device *ibdev, int entries,
entries, nescq->cq_mem_size, nescq->hw_cq.cq_number);

/* allocate the physical buffer space */
- mem = pci_alloc_consistent(nesdev->pcidev, nescq->cq_mem_size,
- &nescq->hw_cq.cq_pbase);
+ mem = pci_zalloc_consistent(nesdev->pcidev, nescq->cq_mem_size,
+ &nescq->hw_cq.cq_pbase);
if (!mem) {
printk(KERN_ERR PFX "Unable to allocate pci memory for cq\n");
nes_free_resource(nesadapter, nesadapter->allocated_cqs, cq_num);
@@ -1625,7 +1625,6 @@ static struct ib_cq *nes_create_cq(struct ib_device *ibdev, int entries,
return ERR_PTR(-ENOMEM);
}

- memset(mem, 0, nescq->cq_mem_size);
nescq->hw_cq.cq_vbase = mem;
nescq->hw_cq.cq_head = 0;
nes_debug(NES_DBG_CQ, "CQ%u virtual address @ %p, phys = 0x%08X\n",
--
1.8.1.2.459.gbcd45b4.dirty

2014-06-23 13:42:35

by Joe Perches

[permalink] [raw]
Subject: [PATCH 07/22] media: Use pci_zalloc_consistent

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <[email protected]>
---
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 +++--------
6 files changed, 22 insertions(+), 43 deletions(-)

diff --git a/drivers/media/common/saa7146/saa7146_core.c b/drivers/media/common/saa7146/saa7146_core.c
index 34b0d0d..97afee6 100644
--- a/drivers/media/common/saa7146/saa7146_core.c
+++ b/drivers/media/common/saa7146/saa7146_core.c
@@ -421,23 +421,20 @@ static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent
err = -ENOMEM;

/* get memory for various stuff */
- dev->d_rps0.cpu_addr = pci_alloc_consistent(pci, SAA7146_RPS_MEM,
- &dev->d_rps0.dma_handle);
+ dev->d_rps0.cpu_addr = pci_zalloc_consistent(pci, SAA7146_RPS_MEM,
+ &dev->d_rps0.dma_handle);
if (!dev->d_rps0.cpu_addr)
goto err_free_irq;
- memset(dev->d_rps0.cpu_addr, 0x0, SAA7146_RPS_MEM);

- dev->d_rps1.cpu_addr = pci_alloc_consistent(pci, SAA7146_RPS_MEM,
- &dev->d_rps1.dma_handle);
+ dev->d_rps1.cpu_addr = pci_zalloc_consistent(pci, SAA7146_RPS_MEM,
+ &dev->d_rps1.dma_handle);
if (!dev->d_rps1.cpu_addr)
goto err_free_rps0;
- memset(dev->d_rps1.cpu_addr, 0x0, SAA7146_RPS_MEM);

- dev->d_i2c.cpu_addr = pci_alloc_consistent(pci, SAA7146_RPS_MEM,
- &dev->d_i2c.dma_handle);
+ dev->d_i2c.cpu_addr = pci_zalloc_consistent(pci, SAA7146_RPS_MEM,
+ &dev->d_i2c.dma_handle);
if (!dev->d_i2c.cpu_addr)
goto err_free_rps1;
- memset(dev->d_i2c.cpu_addr, 0x0, SAA7146_RPS_MEM);

/* the rest + print status message */

diff --git a/drivers/media/common/saa7146/saa7146_fops.c b/drivers/media/common/saa7146/saa7146_fops.c
index eda01bc..a776a80 100644
--- a/drivers/media/common/saa7146/saa7146_fops.c
+++ b/drivers/media/common/saa7146/saa7146_fops.c
@@ -520,14 +520,15 @@ int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv)
configuration data) */
dev->ext_vv_data = ext_vv;

- vv->d_clipping.cpu_addr = pci_alloc_consistent(dev->pci, SAA7146_CLIPPING_MEM, &vv->d_clipping.dma_handle);
+ vv->d_clipping.cpu_addr =
+ pci_zalloc_consistent(dev->pci, SAA7146_CLIPPING_MEM,
+ &vv->d_clipping.dma_handle);
if( NULL == vv->d_clipping.cpu_addr ) {
ERR("out of memory. aborting.\n");
kfree(vv);
v4l2_ctrl_handler_free(hdl);
return -1;
}
- memset(vv->d_clipping.cpu_addr, 0x0, SAA7146_CLIPPING_MEM);

saa7146_video_uops.init(dev,vv);
if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
diff --git a/drivers/media/pci/bt8xx/bt878.c b/drivers/media/pci/bt8xx/bt878.c
index d0c281f..1176583 100644
--- a/drivers/media/pci/bt8xx/bt878.c
+++ b/drivers/media/pci/bt8xx/bt878.c
@@ -101,28 +101,20 @@ static int bt878_mem_alloc(struct bt878 *bt)
if (!bt->buf_cpu) {
bt->buf_size = 128 * 1024;

- bt->buf_cpu =
- pci_alloc_consistent(bt->dev, bt->buf_size,
- &bt->buf_dma);
-
+ bt->buf_cpu = pci_zalloc_consistent(bt->dev, bt->buf_size,
+ &bt->buf_dma);
if (!bt->buf_cpu)
return -ENOMEM;
-
- memset(bt->buf_cpu, 0, bt->buf_size);
}

if (!bt->risc_cpu) {
bt->risc_size = PAGE_SIZE;
- bt->risc_cpu =
- pci_alloc_consistent(bt->dev, bt->risc_size,
- &bt->risc_dma);
-
+ bt->risc_cpu = pci_zalloc_consistent(bt->dev, bt->risc_size,
+ &bt->risc_dma);
if (!bt->risc_cpu) {
bt878_mem_free(bt);
return -ENOMEM;
}
-
- memset(bt->risc_cpu, 0, bt->risc_size);
}

return 0;
diff --git a/drivers/media/pci/ngene/ngene-core.c b/drivers/media/pci/ngene/ngene-core.c
index 970e833..37dc149 100644
--- a/drivers/media/pci/ngene/ngene-core.c
+++ b/drivers/media/pci/ngene/ngene-core.c
@@ -1078,12 +1078,11 @@ static int AllocCommonBuffers(struct ngene *dev)
dev->ngenetohost = dev->FWInterfaceBuffer + 256;
dev->EventBuffer = dev->FWInterfaceBuffer + 512;

- dev->OverflowBuffer = pci_alloc_consistent(dev->pci_dev,
- OVERFLOW_BUFFER_SIZE,
- &dev->PAOverflowBuffer);
+ dev->OverflowBuffer = pci_zalloc_consistent(dev->pci_dev,
+ OVERFLOW_BUFFER_SIZE,
+ &dev->PAOverflowBuffer);
if (!dev->OverflowBuffer)
return -ENOMEM;
- memset(dev->OverflowBuffer, 0, OVERFLOW_BUFFER_SIZE);

for (i = STREAM_VIDEOIN1; i < MAX_STREAM; i++) {
int type = dev->card_info->io_type[i];
diff --git a/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c b/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
index f8a60c1..0d3194a 100644
--- a/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
+++ b/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
@@ -804,11 +804,9 @@ static int ttusb_alloc_iso_urbs(struct ttusb *ttusb)
{
int i;

- ttusb->iso_buffer = pci_alloc_consistent(NULL,
- ISO_FRAME_SIZE *
- FRAMES_PER_ISO_BUF *
- ISO_BUF_COUNT,
- &ttusb->iso_dma_handle);
+ ttusb->iso_buffer = pci_zalloc_consistent(NULL,
+ ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF * ISO_BUF_COUNT,
+ &ttusb->iso_dma_handle);

if (!ttusb->iso_buffer) {
dprintk("%s: pci_alloc_consistent - not enough memory\n",
@@ -816,9 +814,6 @@ static int ttusb_alloc_iso_urbs(struct ttusb *ttusb)
return -ENOMEM;
}

- memset(ttusb->iso_buffer, 0,
- ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF * ISO_BUF_COUNT);
-
for (i = 0; i < ISO_BUF_COUNT; i++) {
struct urb *urb;

diff --git a/drivers/media/usb/ttusb-dec/ttusb_dec.c b/drivers/media/usb/ttusb-dec/ttusb_dec.c
index 29724af..15ab584 100644
--- a/drivers/media/usb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/usb/ttusb-dec/ttusb_dec.c
@@ -1151,11 +1151,9 @@ static int ttusb_dec_alloc_iso_urbs(struct ttusb_dec *dec)

dprintk("%s\n", __func__);

- dec->iso_buffer = pci_alloc_consistent(NULL,
- ISO_FRAME_SIZE *
- (FRAMES_PER_ISO_BUF *
- ISO_BUF_COUNT),
- &dec->iso_dma_handle);
+ dec->iso_buffer = pci_zalloc_consistent(NULL,
+ ISO_FRAME_SIZE * (FRAMES_PER_ISO_BUF * ISO_BUF_COUNT),
+ &dec->iso_dma_handle);

if (!dec->iso_buffer) {
dprintk("%s: pci_alloc_consistent - not enough memory\n",
@@ -1163,9 +1161,6 @@ static int ttusb_dec_alloc_iso_urbs(struct ttusb_dec *dec)
return -ENOMEM;
}

- memset(dec->iso_buffer, 0,
- ISO_FRAME_SIZE * (FRAMES_PER_ISO_BUF * ISO_BUF_COUNT));
-
for (i = 0; i < ISO_BUF_COUNT; i++) {
struct urb *urb;

--
1.8.1.2.459.gbcd45b4.dirty

2014-06-23 13:42:42

by Joe Perches

[permalink] [raw]
Subject: [PATCH 10/22] enic: Use pci_zalloc_consistent

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <[email protected]>
---
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

2014-06-23 13:42:50

by Joe Perches

[permalink] [raw]
Subject: [PATCH 12/22] micrel: Use pci_zalloc_consistent

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <[email protected]>
---
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

2014-06-23 13:43:00

by Joe Perches

[permalink] [raw]
Subject: [PATCH 15/22] ipw2100: Use pci_zalloc_consistent

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <[email protected]>
---
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

2014-06-23 13:42:55

by Joe Perches

[permalink] [raw]
Subject: [PATCH 13/22] qlogic: Use pci_zalloc_consistent

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <[email protected]>
---
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

2014-06-23 13:43:06

by Joe Perches

[permalink] [raw]
Subject: [PATCH 17/22] rtl818x: Use pci_zalloc_consistent

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <[email protected]>
---
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

2014-06-23 13:43:14

by Joe Perches

[permalink] [raw]
Subject: [PATCH 18/22] rtlwifi: Use pci_zalloc_consistent

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <[email protected]>
---
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

2014-06-23 13:43:20

by Joe Perches

[permalink] [raw]
Subject: [PATCH 19/22] scsi: Use pci_zalloc_consistent

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <[email protected]>
---
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 ++---
12 files changed, 32 insertions(+), 59 deletions(-)

diff --git a/drivers/scsi/3w-sas.c b/drivers/scsi/3w-sas.c
index 4de3460..6da6cec 100644
--- a/drivers/scsi/3w-sas.c
+++ b/drivers/scsi/3w-sas.c
@@ -683,14 +683,13 @@ static int twl_allocate_memory(TW_Device_Extension *tw_dev, int size, int which)
unsigned long *cpu_addr;
int retval = 1;

- cpu_addr = pci_alloc_consistent(tw_dev->tw_pci_dev, size*TW_Q_LENGTH, &dma_handle);
+ cpu_addr = pci_zalloc_consistent(tw_dev->tw_pci_dev, size * TW_Q_LENGTH,
+ &dma_handle);
if (!cpu_addr) {
TW_PRINTK(tw_dev->host, TW_DRIVER, 0x5, "Memory allocation failed");
goto out;
}

- memset(cpu_addr, 0, size*TW_Q_LENGTH);
-
for (i = 0; i < TW_Q_LENGTH; i++) {
switch(which) {
case 0:
diff --git a/drivers/scsi/a100u2w.c b/drivers/scsi/a100u2w.c
index 0163457..d1474611 100644
--- a/drivers/scsi/a100u2w.c
+++ b/drivers/scsi/a100u2w.c
@@ -1125,23 +1125,19 @@ static int inia100_probe_one(struct pci_dev *pdev,

/* Get total memory needed for SCB */
sz = ORC_MAXQUEUE * sizeof(struct orc_scb);
- host->scb_virt = pci_alloc_consistent(pdev, sz,
- &host->scb_phys);
+ host->scb_virt = pci_zalloc_consistent(pdev, sz, &host->scb_phys);
if (!host->scb_virt) {
printk("inia100: SCB memory allocation error\n");
goto out_host_put;
}
- memset(host->scb_virt, 0, sz);

/* Get total memory needed for ESCB */
sz = ORC_MAXQUEUE * sizeof(struct orc_extended_scb);
- host->escb_virt = pci_alloc_consistent(pdev, sz,
- &host->escb_phys);
+ host->escb_virt = pci_zalloc_consistent(pdev, sz, &host->escb_phys);
if (!host->escb_virt) {
printk("inia100: ESCB memory allocation error\n");
goto out_free_scb_array;
}
- memset(host->escb_virt, 0, sz);

biosaddr = host->BIOScfg;
biosaddr = (biosaddr << 4);
diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c
index 5543490..e08def2 100644
--- a/drivers/scsi/be2iscsi/be_main.c
+++ b/drivers/scsi/be2iscsi/be_main.c
@@ -3538,10 +3538,9 @@ static int be_queue_alloc(struct beiscsi_hba *phba, struct be_queue_info *q,
q->len = len;
q->entry_size = entry_size;
mem->size = len * entry_size;
- mem->va = pci_alloc_consistent(phba->pcidev, mem->size, &mem->dma);
+ mem->va = pci_zalloc_consistent(phba->pcidev, mem->size, &mem->dma);
if (!mem->va)
return -ENOMEM;
- memset(mem->va, 0, mem->size);
return 0;
}

@@ -4318,9 +4317,9 @@ static int beiscsi_get_boot_info(struct beiscsi_hba *phba)
"BM_%d : No boot session\n");
return ret;
}
- nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
- sizeof(*session_resp),
- &nonemb_cmd.dma);
+ nonemb_cmd.va = pci_zalloc_consistent(phba->ctrl.pdev,
+ sizeof(*session_resp),
+ &nonemb_cmd.dma);
if (nonemb_cmd.va == NULL) {
beiscsi_log(phba, KERN_ERR,
BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
@@ -4330,7 +4329,6 @@ static int beiscsi_get_boot_info(struct beiscsi_hba *phba)
return -ENOMEM;
}

- memset(nonemb_cmd.va, 0, sizeof(*session_resp));
tag = mgmt_get_session_info(phba, s_handle,
&nonemb_cmd);
if (!tag) {
diff --git a/drivers/scsi/be2iscsi/be_mgmt.c b/drivers/scsi/be2iscsi/be_mgmt.c
index 6045aa7..49bf8fb 100644
--- a/drivers/scsi/be2iscsi/be_mgmt.c
+++ b/drivers/scsi/be2iscsi/be_mgmt.c
@@ -900,13 +900,12 @@ free_cmd:
static int mgmt_alloc_cmd_data(struct beiscsi_hba *phba, struct be_dma_mem *cmd,
int iscsi_cmd, int size)
{
- cmd->va = pci_alloc_consistent(phba->ctrl.pdev, size, &cmd->dma);
+ cmd->va = pci_zalloc_consistent(phba->ctrl.pdev, size, &cmd->dma);
if (!cmd->va) {
beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
"BG_%d : Failed to allocate memory for if info\n");
return -ENOMEM;
}
- memset(cmd->va, 0, size);
cmd->size = size;
be_cmd_hdr_prepare(cmd->va, CMD_SUBSYSTEM_ISCSI, iscsi_cmd, size);
return 0;
diff --git a/drivers/scsi/csiostor/csio_wr.c b/drivers/scsi/csiostor/csio_wr.c
index 4255ce2..773da14 100644
--- a/drivers/scsi/csiostor/csio_wr.c
+++ b/drivers/scsi/csiostor/csio_wr.c
@@ -232,7 +232,7 @@ csio_wr_alloc_q(struct csio_hw *hw, uint32_t qsize, uint32_t wrsize,

q = wrm->q_arr[free_idx];

- q->vstart = pci_alloc_consistent(hw->pdev, qsz, &q->pstart);
+ q->vstart = pci_zalloc_consistent(hw->pdev, qsz, &q->pstart);
if (!q->vstart) {
csio_err(hw,
"Failed to allocate DMA memory for "
@@ -240,12 +240,6 @@ csio_wr_alloc_q(struct csio_hw *hw, uint32_t qsize, uint32_t wrsize,
return -1;
}

- /*
- * We need to zero out the contents, importantly for ingress,
- * since we start with a generatiom bit of 1 for ingress.
- */
- memset(q->vstart, 0, qsz);
-
q->type = type;
q->owner = owner;
q->pidx = q->cidx = q->inc_idx = 0;
diff --git a/drivers/scsi/eata.c b/drivers/scsi/eata.c
index ebf5736..e3f746d 100644
--- a/drivers/scsi/eata.c
+++ b/drivers/scsi/eata.c
@@ -1238,8 +1238,8 @@ static int port_detect(unsigned long port_base, unsigned int j,
struct eata_config *cf;
dma_addr_t cf_dma_addr;

- cf = pci_alloc_consistent(pdev, sizeof(struct eata_config),
- &cf_dma_addr);
+ cf = pci_zalloc_consistent(pdev, sizeof(struct eata_config),
+ &cf_dma_addr);

if (!cf) {
printk
@@ -1249,7 +1249,6 @@ static int port_detect(unsigned long port_base, unsigned int j,
}

/* Set board configuration */
- memset((char *)cf, 0, sizeof(struct eata_config));
cf->len = (ushort) H2DEV16((ushort) 510);
cf->ocena = 1;

diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index 31184b3..5c465cd 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -4731,23 +4731,21 @@ static struct CommandList *cmd_special_alloc(struct ctlr_info *h)
union u64bit temp64;
dma_addr_t cmd_dma_handle, err_dma_handle;

- c = pci_alloc_consistent(h->pdev, sizeof(*c), &cmd_dma_handle);
+ c = pci_zalloc_consistent(h->pdev, sizeof(*c), &cmd_dma_handle);
if (c == NULL)
return NULL;
- memset(c, 0, sizeof(*c));

c->cmd_type = CMD_SCSI;
c->cmdindex = -1;

- c->err_info = pci_alloc_consistent(h->pdev, sizeof(*c->err_info),
- &err_dma_handle);
+ c->err_info = pci_zalloc_consistent(h->pdev, sizeof(*c->err_info),
+ &err_dma_handle);

if (c->err_info == NULL) {
pci_free_consistent(h->pdev,
sizeof(*c), c, cmd_dma_handle);
return NULL;
}
- memset(c->err_info, 0, sizeof(*c->err_info));

INIT_LIST_HEAD(&c->list);
c->busaddr = (u32) cmd_dma_handle;
diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
index e2237a9..531dce4 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -998,8 +998,9 @@ megaraid_alloc_cmd_packets(adapter_t *adapter)
* Allocate the common 16-byte aligned memory for the handshake
* mailbox.
*/
- raid_dev->una_mbox64 = pci_alloc_consistent(adapter->pdev,
- sizeof(mbox64_t), &raid_dev->una_mbox64_dma);
+ raid_dev->una_mbox64 = pci_zalloc_consistent(adapter->pdev,
+ sizeof(mbox64_t),
+ &raid_dev->una_mbox64_dma);

if (!raid_dev->una_mbox64) {
con_log(CL_ANN, (KERN_WARNING
@@ -1007,7 +1008,6 @@ megaraid_alloc_cmd_packets(adapter_t *adapter)
__LINE__));
return -1;
}
- memset(raid_dev->una_mbox64, 0, sizeof(mbox64_t));

/*
* Align the mailbox at 16-byte boundary
@@ -1026,8 +1026,8 @@ megaraid_alloc_cmd_packets(adapter_t *adapter)
align;

// Allocate memory for commands issued internally
- adapter->ibuf = pci_alloc_consistent(pdev, MBOX_IBUF_SIZE,
- &adapter->ibuf_dma_h);
+ adapter->ibuf = pci_zalloc_consistent(pdev, MBOX_IBUF_SIZE,
+ &adapter->ibuf_dma_h);
if (!adapter->ibuf) {

con_log(CL_ANN, (KERN_WARNING
@@ -1036,7 +1036,6 @@ megaraid_alloc_cmd_packets(adapter_t *adapter)

goto out_free_common_mbox;
}
- memset(adapter->ibuf, 0, MBOX_IBUF_SIZE);

// Allocate memory for our SCSI Command Blocks and their associated
// memory
@@ -2972,8 +2971,8 @@ megaraid_mbox_product_info(adapter_t *adapter)
* Issue an ENQUIRY3 command to find out certain adapter parameters,
* e.g., max channels, max commands etc.
*/
- pinfo = pci_alloc_consistent(adapter->pdev, sizeof(mraid_pinfo_t),
- &pinfo_dma_h);
+ pinfo = pci_zalloc_consistent(adapter->pdev, sizeof(mraid_pinfo_t),
+ &pinfo_dma_h);

if (pinfo == NULL) {
con_log(CL_ANN, (KERN_WARNING
@@ -2982,7 +2981,6 @@ megaraid_mbox_product_info(adapter_t *adapter)

return -1;
}
- memset(pinfo, 0, sizeof(mraid_pinfo_t));

mbox->xferaddr = (uint32_t)adapter->ibuf_dma_h;
memset((void *)adapter->ibuf, 0, MBOX_IBUF_SIZE);
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index 112799b..22a04e3 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -2038,9 +2038,9 @@ int megasas_sriov_start_heartbeat(struct megasas_instance *instance,

if (initial) {
instance->hb_host_mem =
- pci_alloc_consistent(instance->pdev,
- sizeof(struct MR_CTRL_HB_HOST_MEM),
- &instance->hb_host_mem_h);
+ pci_zalloc_consistent(instance->pdev,
+ sizeof(struct MR_CTRL_HB_HOST_MEM),
+ &instance->hb_host_mem_h);
if (!instance->hb_host_mem) {
printk(KERN_DEBUG "megasas: SR-IOV: Couldn't allocate"
" memory for heartbeat host memory for "
@@ -2048,8 +2048,6 @@ int megasas_sriov_start_heartbeat(struct megasas_instance *instance,
retval = -ENOMEM;
goto out;
}
- memset(instance->hb_host_mem, 0,
- sizeof(struct MR_CTRL_HB_HOST_MEM));
}

memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
diff --git a/drivers/scsi/mesh.c b/drivers/scsi/mesh.c
index e8a04ae..b4f0552 100644
--- a/drivers/scsi/mesh.c
+++ b/drivers/scsi/mesh.c
@@ -1915,14 +1915,12 @@ static int mesh_probe(struct macio_dev *mdev, const struct of_device_id *match)
/* We use the PCI APIs for now until the generic one gets fixed
* enough or until we get some macio-specific versions
*/
- dma_cmd_space = pci_alloc_consistent(macio_get_pci_dev(mdev),
- ms->dma_cmd_size,
- &dma_cmd_bus);
+ dma_cmd_space = pci_zalloc_consistent(macio_get_pci_dev(mdev),
+ ms->dma_cmd_size, &dma_cmd_bus);
if (dma_cmd_space == NULL) {
printk(KERN_ERR "mesh: can't allocate DMA table\n");
goto out_unmap;
}
- memset(dma_cmd_space, 0, ms->dma_cmd_size);

ms->dma_cmds = (struct dbdma_cmd *) DBDMA_ALIGN(dma_cmd_space);
ms->dma_cmd_space = dma_cmd_space;
diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index edbee8d..3e716b2 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -142,8 +142,8 @@ static struct mvumi_res *mvumi_alloc_mem_resource(struct mvumi_hba *mhba,

case RESOURCE_UNCACHED_MEMORY:
size = round_up(size, 8);
- res->virt_addr = pci_alloc_consistent(mhba->pdev, size,
- &res->bus_addr);
+ res->virt_addr = pci_zalloc_consistent(mhba->pdev, size,
+ &res->bus_addr);
if (!res->virt_addr) {
dev_err(&mhba->pdev->dev,
"unable to allocate consistent mem,"
@@ -151,7 +151,6 @@ static struct mvumi_res *mvumi_alloc_mem_resource(struct mvumi_hba *mhba,
kfree(res);
return NULL;
}
- memset(res->virt_addr, 0, size);
break;

default:
@@ -258,12 +257,10 @@ static int mvumi_internal_cmd_sgl(struct mvumi_hba *mhba, struct mvumi_cmd *cmd,
if (size == 0)
return 0;

- virt_addr = pci_alloc_consistent(mhba->pdev, size, &phy_addr);
+ virt_addr = pci_zalloc_consistent(mhba->pdev, size, &phy_addr);
if (!virt_addr)
return -1;

- memset(virt_addr, 0, size);
-
m_sg = (struct mvumi_sgl *) &cmd->frame->payload[0];
cmd->frame->sg_counts = 1;
cmd->data_buf = virt_addr;
diff --git a/drivers/scsi/pm8001/pm8001_sas.c b/drivers/scsi/pm8001/pm8001_sas.c
index 8a44bc9..6107e06 100644
--- a/drivers/scsi/pm8001/pm8001_sas.c
+++ b/drivers/scsi/pm8001/pm8001_sas.c
@@ -123,13 +123,12 @@ int pm8001_mem_alloc(struct pci_dev *pdev, void **virt_addr,
u64 align_offset = 0;
if (align)
align_offset = (dma_addr_t)align - 1;
- mem_virt_alloc =
- pci_alloc_consistent(pdev, mem_size + align, &mem_dma_handle);
+ mem_virt_alloc = pci_zalloc_consistent(pdev, mem_size + align,
+ &mem_dma_handle);
if (!mem_virt_alloc) {
pm8001_printk("memory allocation error\n");
return -1;
}
- memset((void *)mem_virt_alloc, 0, mem_size+align);
*pphys_addr = mem_dma_handle;
phys_align = (*pphys_addr + align_offset) & ~align_offset;
*virt_addr = (void *)mem_virt_alloc + phys_align - *pphys_addr;
--
1.8.1.2.459.gbcd45b4.dirty

2014-06-23 13:43:24

by Joe Perches

[permalink] [raw]
Subject: [PATCH 21/22] synclink_gt: Use pci_zalloc_consistent

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <[email protected]>
---
drivers/tty/synclink_gt.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
index c359a91..07ea71c 100644
--- a/drivers/tty/synclink_gt.c
+++ b/drivers/tty/synclink_gt.c
@@ -3387,12 +3387,11 @@ static int alloc_desc(struct slgt_info *info)
unsigned int pbufs;

/* allocate memory to hold descriptor lists */
- info->bufs = pci_alloc_consistent(info->pdev, DESC_LIST_SIZE, &info->bufs_dma_addr);
+ info->bufs = pci_zalloc_consistent(info->pdev, DESC_LIST_SIZE,
+ &info->bufs_dma_addr);
if (info->bufs == NULL)
return -ENOMEM;

- memset(info->bufs, 0, DESC_LIST_SIZE);
-
info->rbufs = (struct slgt_desc*)info->bufs;
info->tbufs = ((struct slgt_desc*)info->bufs) + info->rbuf_count;

--
1.8.1.2.459.gbcd45b4.dirty

2014-06-23 13:43:44

by Joe Perches

[permalink] [raw]
Subject: [PATCH 22/22] vme: bridges: Use pci_zalloc_consistent

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <[email protected]>
---
drivers/vme/bridges/vme_ca91cx42.c | 6 ++----
drivers/vme/bridges/vme_tsi148.c | 6 ++----
2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/vme/bridges/vme_ca91cx42.c b/drivers/vme/bridges/vme_ca91cx42.c
index bfb2d3f..18078ec 100644
--- a/drivers/vme/bridges/vme_ca91cx42.c
+++ b/drivers/vme/bridges/vme_ca91cx42.c
@@ -1555,16 +1555,14 @@ static int ca91cx42_crcsr_init(struct vme_bridge *ca91cx42_bridge,
}

/* Allocate mem for CR/CSR image */
- bridge->crcsr_kernel = pci_alloc_consistent(pdev, VME_CRCSR_BUF_SIZE,
- &bridge->crcsr_bus);
+ bridge->crcsr_kernel = pci_zalloc_consistent(pdev, VME_CRCSR_BUF_SIZE,
+ &bridge->crcsr_bus);
if (bridge->crcsr_kernel == NULL) {
dev_err(&pdev->dev, "Failed to allocate memory for CR/CSR "
"image\n");
return -ENOMEM;
}

- memset(bridge->crcsr_kernel, 0, VME_CRCSR_BUF_SIZE);
-
crcsr_addr = slot * (512 * 1024);
iowrite32(bridge->crcsr_bus - crcsr_addr, bridge->base + VCSR_TO);

diff --git a/drivers/vme/bridges/vme_tsi148.c b/drivers/vme/bridges/vme_tsi148.c
index 61e706c..e07cfa8 100644
--- a/drivers/vme/bridges/vme_tsi148.c
+++ b/drivers/vme/bridges/vme_tsi148.c
@@ -2275,16 +2275,14 @@ static int tsi148_crcsr_init(struct vme_bridge *tsi148_bridge,
bridge = tsi148_bridge->driver_priv;

/* Allocate mem for CR/CSR image */
- bridge->crcsr_kernel = pci_alloc_consistent(pdev, VME_CRCSR_BUF_SIZE,
- &bridge->crcsr_bus);
+ bridge->crcsr_kernel = pci_zalloc_consistent(pdev, VME_CRCSR_BUF_SIZE,
+ &bridge->crcsr_bus);
if (bridge->crcsr_kernel == NULL) {
dev_err(tsi148_bridge->parent, "Failed to allocate memory for "
"CR/CSR image\n");
return -ENOMEM;
}

- memset(bridge->crcsr_kernel, 0, VME_CRCSR_BUF_SIZE);
-
reg_split(bridge->crcsr_bus, &crcsr_bus_high, &crcsr_bus_low);

iowrite32be(crcsr_bus_high, bridge->base + TSI148_LCSR_CROU);
--
1.8.1.2.459.gbcd45b4.dirty

2014-06-23 13:44:18

by Joe Perches

[permalink] [raw]
Subject: [PATCH 20/22] staging: Use pci_zalloc_consistent

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <[email protected]>
---
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 +++++++++-------------------
5 files changed, 44 insertions(+), 93 deletions(-)

diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_core.c b/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
index 2920e40..5729cf6 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
@@ -2065,20 +2065,16 @@ static short rtl8192_alloc_rx_desc_ring(struct net_device *dev)
int i, rx_queue_idx;

for (rx_queue_idx = 0; rx_queue_idx < MAX_RX_QUEUE; rx_queue_idx++) {
- priv->rx_ring[rx_queue_idx] = pci_alloc_consistent(priv->pdev,
- sizeof(*priv->rx_ring[rx_queue_idx]) *
- priv->rxringcount,
- &priv->rx_ring_dma[rx_queue_idx]);
-
+ priv->rx_ring[rx_queue_idx] =
+ pci_zalloc_consistent(priv->pdev,
+ sizeof(*priv->rx_ring[rx_queue_idx]) * priv->rxringcount,
+ &priv->rx_ring_dma[rx_queue_idx]);
if (!priv->rx_ring[rx_queue_idx] ||
(unsigned long)priv->rx_ring[rx_queue_idx] & 0xFF) {
RT_TRACE(COMP_ERR, "Cannot allocate RX ring\n");
return -ENOMEM;
}

- memset(priv->rx_ring[rx_queue_idx], 0,
- sizeof(*priv->rx_ring[rx_queue_idx]) *
- priv->rxringcount);
priv->rx_idx[rx_queue_idx] = 0;

for (i = 0; i < priv->rxringcount; i++) {
@@ -2118,14 +2114,13 @@ static int rtl8192_alloc_tx_desc_ring(struct net_device *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) {
RT_TRACE(COMP_ERR, "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;
diff --git a/drivers/staging/rtl8192ee/pci.c b/drivers/staging/rtl8192ee/pci.c
index 3fe9b7b..ddfb25f 100644
--- a/drivers/staging/rtl8192ee/pci.c
+++ b/drivers/staging/rtl8192ee/pci.c
@@ -1224,10 +1224,10 @@ static int _rtl_pci_init_tx_ring(struct ieee80211_hw *hw,

/* alloc tx buffer desc for new trx flow*/
if (rtlpriv->use_new_trx_flow) {
- buffer_desc = pci_alloc_consistent(rtlpci->pdev,
- sizeof(*buffer_desc) * entries,
- &buffer_desc_dma);
-
+ buffer_desc =
+ pci_zalloc_consistent(rtlpci->pdev,
+ sizeof(*buffer_desc) * entries,
+ &buffer_desc_dma);
if (!buffer_desc || (unsigned long)buffer_desc & 0xFF) {
RT_TRACE(COMP_ERR, DBG_EMERG,
("Cannot allocate TX ring (prio = %d)\n",
@@ -1235,7 +1235,6 @@ static int _rtl_pci_init_tx_ring(struct ieee80211_hw *hw,
return -ENOMEM;
}

- memset(buffer_desc, 0, sizeof(*buffer_desc) * entries);
rtlpci->tx_ring[prio].buffer_desc = buffer_desc;
rtlpci->tx_ring[prio].buffer_desc_dma = buffer_desc_dma;

@@ -1245,16 +1244,14 @@ static int _rtl_pci_init_tx_ring(struct ieee80211_hw *hw,
}

/* alloc dma for this ring */
- desc = pci_alloc_consistent(rtlpci->pdev,
- sizeof(*desc) * entries, &desc_dma);
-
+ desc = pci_zalloc_consistent(rtlpci->pdev, sizeof(*desc) * entries,
+ &desc_dma);
if (!desc || (unsigned long)desc & 0xFF) {
RT_TRACE(COMP_ERR, DBG_EMERG,
("Cannot allocate TX ring (prio = %d)\n", prio));
return -ENOMEM;
}

- memset(desc, 0, sizeof(*desc) * entries);
rtlpci->tx_ring[prio].desc = desc;
rtlpci->tx_ring[prio].dma = desc_dma;

@@ -1290,11 +1287,9 @@ static int _rtl_pci_init_rx_ring(struct ieee80211_hw *hw, int rxring_idx)
struct rtl_rx_buffer_desc *entry = NULL;
/* alloc dma for this ring */
rtlpci->rx_ring[rxring_idx].buffer_desc =
- pci_alloc_consistent(rtlpci->pdev,
- sizeof(*rtlpci->rx_ring[rxring_idx].
- buffer_desc) *
- rtlpci->rxringcount,
- &rtlpci->rx_ring[rxring_idx].dma);
+ pci_zalloc_consistent(rtlpci->pdev,
+ sizeof(*rtlpci->rx_ring[rxring_idx].buffer_desc) * rtlpci->rxringcount,
+ &rtlpci->rx_ring[rxring_idx].dma);
if (!rtlpci->rx_ring[rxring_idx].buffer_desc ||
(unsigned long)rtlpci->rx_ring[rxring_idx].buffer_desc & 0xFF) {
RT_TRACE(COMP_ERR, DBG_EMERG,
@@ -1302,10 +1297,6 @@ static int _rtl_pci_init_rx_ring(struct ieee80211_hw *hw, int rxring_idx)
return -ENOMEM;
}

- memset(rtlpci->rx_ring[rxring_idx].buffer_desc, 0,
- sizeof(*rtlpci->rx_ring[rxring_idx].buffer_desc) *
- rtlpci->rxringcount);
-
/* init every desc in this ring */
rtlpci->rx_ring[rxring_idx].idx = 0;

@@ -1320,19 +1311,15 @@ static int _rtl_pci_init_rx_ring(struct ieee80211_hw *hw, int rxring_idx)
u8 tmp_one = 1;
/* alloc dma for this ring */
rtlpci->rx_ring[rxring_idx].desc =
- pci_alloc_consistent(rtlpci->pdev,
- sizeof(*rtlpci->rx_ring[rxring_idx].
- desc) * rtlpci->rxringcount,
- &rtlpci->rx_ring[rxring_idx].dma);
+ pci_zalloc_consistent(rtlpci->pdev,
+ sizeof(*rtlpci->rx_ring[rxring_idx].desc) * rtlpci->rxringcount,
+ &rtlpci->rx_ring[rxring_idx].dma);
if (!rtlpci->rx_ring[rxring_idx].desc ||
(unsigned long)rtlpci->rx_ring[rxring_idx].desc & 0xFF) {
RT_TRACE(COMP_ERR, DBG_EMERG,
("Cannot allocate RX ring\n"));
return -ENOMEM;
}
- memset(rtlpci->rx_ring[rxring_idx].desc, 0,
- sizeof(*rtlpci->rx_ring[rxring_idx].desc) *
- rtlpci->rxringcount);

/* init every desc in this ring */
rtlpci->rx_ring[rxring_idx].idx = 0;
diff --git a/drivers/staging/rtl8821ae/pci.c b/drivers/staging/rtl8821ae/pci.c
index e194ffe..f7efde1 100644
--- a/drivers/staging/rtl8821ae/pci.c
+++ b/drivers/staging/rtl8821ae/pci.c
@@ -1248,9 +1248,10 @@ static int _rtl_pci_init_tx_ring(struct ieee80211_hw *hw,

/* alloc tx buffer desc for new trx flow*/
if (rtlpriv->use_new_trx_flow) {
- buffer_desc = pci_alloc_consistent(rtlpci->pdev,
- sizeof(*buffer_desc) * entries,
- &buffer_desc_dma);
+ buffer_desc =
+ pci_zalloc_consistent(rtlpci->pdev,
+ sizeof(*buffer_desc) * entries,
+ &buffer_desc_dma);

if (!buffer_desc || (unsigned long)buffer_desc & 0xFF) {
RT_TRACE(COMP_ERR, DBG_EMERG,
@@ -1259,7 +1260,6 @@ static int _rtl_pci_init_tx_ring(struct ieee80211_hw *hw,
return -ENOMEM;
}

- memset(buffer_desc, 0, sizeof(*buffer_desc) * entries);
rtlpci->tx_ring[prio].buffer_desc = buffer_desc;
rtlpci->tx_ring[prio].buffer_desc_dma = buffer_desc_dma;

@@ -1270,8 +1270,8 @@ static int _rtl_pci_init_tx_ring(struct ieee80211_hw *hw,
}

/* alloc dma for this ring */
- desc = pci_alloc_consistent(rtlpci->pdev,
- sizeof(*desc) * entries, &desc_dma);
+ desc = pci_zalloc_consistent(rtlpci->pdev, sizeof(*desc) * entries,
+ &desc_dma);

if (!desc || (unsigned long)desc & 0xFF) {
RT_TRACE(COMP_ERR, DBG_EMERG,
@@ -1279,7 +1279,6 @@ static int _rtl_pci_init_tx_ring(struct ieee80211_hw *hw,
return -ENOMEM;
}

- memset(desc, 0, sizeof(*desc) * entries);
rtlpci->tx_ring[prio].desc = desc;
rtlpci->tx_ring[prio].dma = desc_dma;

@@ -1316,21 +1315,15 @@ static int _rtl_pci_init_rx_ring(struct ieee80211_hw *hw, int rxring_idx)
struct rtl_rx_buffer_desc *entry = NULL;
/* alloc dma for this ring */
rtlpci->rx_ring[rxring_idx].buffer_desc =
- pci_alloc_consistent(rtlpci->pdev,
- sizeof(*rtlpci->rx_ring[rxring_idx].
- buffer_desc) *
- rtlpci->rxringcount,
- &rtlpci->rx_ring[rxring_idx].dma);
+ pci_zalloc_consistent(rtlpci->pdev,
+ sizeof(*rtlpci->rx_ring[rxring_idx].buffer_desc) * rtlpci->rxringcount,
+ &rtlpci->rx_ring[rxring_idx].dma);
if (!rtlpci->rx_ring[rxring_idx].buffer_desc ||
(unsigned long)rtlpci->rx_ring[rxring_idx].buffer_desc & 0xFF) {
RT_TRACE(COMP_ERR, DBG_EMERG, ("Cannot allocate RX ring\n"));
return -ENOMEM;
}

- memset(rtlpci->rx_ring[rxring_idx].buffer_desc, 0,
- sizeof(*rtlpci->rx_ring[rxring_idx].buffer_desc) *
- rtlpci->rxringcount);
-
/* init every desc in this ring */
rtlpci->rx_ring[rxring_idx].idx = 0;
for (i = 0; i < rtlpci->rxringcount; i++) {
@@ -1344,10 +1337,9 @@ static int _rtl_pci_init_rx_ring(struct ieee80211_hw *hw, int rxring_idx)
u8 tmp_one = 1;
/* alloc dma for this ring */
rtlpci->rx_ring[rxring_idx].desc =
- pci_alloc_consistent(rtlpci->pdev,
- sizeof(*rtlpci->rx_ring[rxring_idx].
- desc) * rtlpci->rxringcount,
- &rtlpci->rx_ring[rxring_idx].dma);
+ pci_zalloc_consistent(rtlpci->pdev,
+ sizeof(*rtlpci->rx_ring[rxring_idx].desc) * rtlpci->rxringcount,
+ &rtlpci->rx_ring[rxring_idx].dma);
if (!rtlpci->rx_ring[rxring_idx].desc ||
(unsigned long)rtlpci->rx_ring[rxring_idx].desc & 0xFF) {
RT_TRACE(COMP_ERR, DBG_EMERG,
@@ -1355,10 +1347,6 @@ static int _rtl_pci_init_rx_ring(struct ieee80211_hw *hw, int rxring_idx)
return -ENOMEM;
}

- memset(rtlpci->rx_ring[rxring_idx].desc, 0,
- sizeof(*rtlpci->rx_ring[rxring_idx].desc) *
- rtlpci->rxringcount);
-
/* init every desc in this ring */
rtlpci->rx_ring[rxring_idx].idx = 0;
for (i = 0; i < rtlpci->rxringcount; i++) {
diff --git a/drivers/staging/slicoss/slicoss.c b/drivers/staging/slicoss/slicoss.c
index 48841e7..ebcbf91 100644
--- a/drivers/staging/slicoss/slicoss.c
+++ b/drivers/staging/slicoss/slicoss.c
@@ -1190,18 +1190,15 @@ static int slic_rspqueue_init(struct adapter *adapter)
rspq->num_pages = SLIC_RSPQ_PAGES_GB;

for (i = 0; i < rspq->num_pages; i++) {
- rspq->vaddr[i] = pci_alloc_consistent(adapter->pcidev,
- PAGE_SIZE,
- &rspq->paddr[i]);
+ rspq->vaddr[i] = pci_zalloc_consistent(adapter->pcidev,
+ PAGE_SIZE,
+ &rspq->paddr[i]);
if (!rspq->vaddr[i]) {
dev_err(&adapter->pcidev->dev,
"pci_alloc_consistent failed\n");
slic_rspqueue_free(adapter);
return -ENOMEM;
}
- /* FIXME:
- * do we really need this assertions (4K PAGE_SIZE aligned addr)? */
- memset(rspq->vaddr[i], 0, PAGE_SIZE);

if (paddrh == 0) {
slic_reg32_write(&slic_regs->slic_rbar,
diff --git a/drivers/staging/vt6655/device_main.c b/drivers/staging/vt6655/device_main.c
index 2327386..d17cb1a 100644
--- a/drivers/staging/vt6655/device_main.c
+++ b/drivers/staging/vt6655/device_main.c
@@ -1091,25 +1091,17 @@ static bool device_init_rings(PSDevice pDevice) {
void *vir_pool;

/*allocate all RD/TD rings a single pool*/
- vir_pool = pci_alloc_consistent(pDevice->pcid,
- pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
- pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
- pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
- pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
- &pDevice->pool_dma);
-
+ vir_pool = pci_zalloc_consistent(pDevice->pcid,
+ pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
+ pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
+ pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
+ pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
+ &pDevice->pool_dma);
if (vir_pool == NULL) {
DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s : allocate desc dma memory failed\n", pDevice->dev->name);
return false;
}

- memset(vir_pool, 0,
- pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
- pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
- pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
- pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
- );
-
pDevice->aRD0Ring = vir_pool;
pDevice->aRD1Ring = vir_pool +
pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
@@ -1118,13 +1110,12 @@ static bool device_init_rings(PSDevice pDevice) {
pDevice->rd1_pool_dma = pDevice->rd0_pool_dma +
pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);

- pDevice->tx0_bufs = pci_alloc_consistent(pDevice->pcid,
- pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
- pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
- CB_BEACON_BUF_SIZE +
- CB_MAX_BUF_SIZE,
- &pDevice->tx_bufs_dma0);
-
+ pDevice->tx0_bufs = pci_zalloc_consistent(pDevice->pcid,
+ pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
+ pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
+ CB_BEACON_BUF_SIZE +
+ CB_MAX_BUF_SIZE,
+ &pDevice->tx_bufs_dma0);
if (pDevice->tx0_bufs == NULL) {
DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: allocate buf dma memory failed\n", pDevice->dev->name);
pci_free_consistent(pDevice->pcid,
@@ -1137,13 +1128,6 @@ static bool device_init_rings(PSDevice pDevice) {
return false;
}

- memset(pDevice->tx0_bufs, 0,
- pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
- pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
- CB_BEACON_BUF_SIZE +
- CB_MAX_BUF_SIZE
- );
-
pDevice->td0_pool_dma = pDevice->rd1_pool_dma +
pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);

--
1.8.1.2.459.gbcd45b4.dirty

2014-06-23 13:45:47

by Joe Perches

[permalink] [raw]
Subject: [PATCH 16/22] mwl8k: Use pci_zalloc_consistent

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <[email protected]>
---
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

2014-06-23 13:46:34

by Joe Perches

[permalink] [raw]
Subject: [PATCH 14/22] irda: Use pci_zalloc_consistent

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <[email protected]>
---
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

2014-06-23 13:47:07

by Joe Perches

[permalink] [raw]
Subject: [PATCH 11/22] sky2: Use pci_zalloc_consistent

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <[email protected]>
---
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

2014-06-23 13:47:36

by Joe Perches

[permalink] [raw]
Subject: [PATCH 09/22] atl1e: Use pci_zalloc_consistent

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <[email protected]>
---
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

2014-06-23 13:48:23

by Joe Perches

[permalink] [raw]
Subject: [PATCH 08/22] amd: Use pci_zalloc_consistent

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <[email protected]>
---
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

2014-06-23 13:49:32

by Joe Perches

[permalink] [raw]
Subject: [PATCH 06/22] i810: Use pci_zalloc_consistent

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <[email protected]>
---
drivers/gpu/drm/i810/i810_dma.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
index e88bac1..bae897d 100644
--- a/drivers/gpu/drm/i810/i810_dma.c
+++ b/drivers/gpu/drm/i810/i810_dma.c
@@ -393,15 +393,14 @@ static int i810_dma_initialize(struct drm_device *dev,

/* Program Hardware Status Page */
dev_priv->hw_status_page =
- pci_alloc_consistent(dev->pdev, PAGE_SIZE,
- &dev_priv->dma_status_page);
+ pci_zalloc_consistent(dev->pdev, PAGE_SIZE,
+ &dev_priv->dma_status_page);
if (!dev_priv->hw_status_page) {
dev->dev_private = (void *)dev_priv;
i810_dma_cleanup(dev);
DRM_ERROR("Can not allocate hardware status page\n");
return -ENOMEM;
}
- memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
DRM_DEBUG("hw status page @ %p\n", dev_priv->hw_status_page);

I810_WRITE(0x02080, dev_priv->dma_status_page);
--
1.8.1.2.459.gbcd45b4.dirty

2014-06-23 13:49:49

by Joe Perches

[permalink] [raw]
Subject: [PATCH 04/22] crypto: Use pci_zalloc_consistent

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <[email protected]>
---
drivers/crypto/hifn_795x.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
index 12fea3e..8d2a772 100644
--- a/drivers/crypto/hifn_795x.c
+++ b/drivers/crypto/hifn_795x.c
@@ -2617,14 +2617,13 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
}
}

- dev->desc_virt = pci_alloc_consistent(pdev, sizeof(struct hifn_dma),
- &dev->desc_dma);
+ dev->desc_virt = pci_zalloc_consistent(pdev, sizeof(struct hifn_dma),
+ &dev->desc_dma);
if (!dev->desc_virt) {
dprintk("Failed to allocate descriptor rings.\n");
err = -ENOMEM;
goto err_out_unmap_bars;
}
- memset(dev->desc_virt, 0, sizeof(struct hifn_dma));

dev->pdev = pdev;
dev->irq = pdev->irq;
--
1.8.1.2.459.gbcd45b4.dirty

2014-06-23 13:50:19

by Joe Perches

[permalink] [raw]
Subject: [PATCH 02/22] atm: Use pci_zalloc_consistent

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <[email protected]>
---
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

2014-06-23 13:53:23

by Arnd Bergmann

[permalink] [raw]
Subject: Re: [PATCH 01/22] pci-dma-compat: Add pci_zalloc_consistent helper

On Monday 23 June 2014 06:41:29 Joe Perches wrote:
> Add this helper for consistency with pci_zalloc_coherent
> and the ability to remove unnecessary memset(,0,) uses.
>
> Signed-off-by: Joe Perches <[email protected]>
>

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

Arnd

2014-06-23 13:57:37

by Steve Wise

[permalink] [raw]
Subject: Re: [PATCH 05/22] infiniband: Use pci_zalloc_consistent

For the amso1100 change...

Acked-by: Steve Wise <[email protected]>

2014-06-23 14:03:36

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 01/22] pci-dma-compat: Add pci_zalloc_consistent helper

On Mon, 2014-06-23 at 15:53 +0200, Arnd Bergmann wrote:
> On Monday 23 June 2014 06:41:29 Joe Perches wrote:
> > Add this helper for consistency with pci_zalloc_coherent
> > and the ability to remove unnecessary memset(,0,) uses.

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

Maybe. I wouldn't mind.

They do seem to have a trivial bit of unnecessary overhead for

hwdev == NULL ? NULL : &hwdev->dev

2014-06-23 16:15:09

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 20/22] staging: Use pci_zalloc_consistent

On Mon, Jun 23, 2014 at 06:41:48AM -0700, Joe Perches wrote:
> Remove the now unnecessary memset too.
>
> Signed-off-by: Joe Perches <[email protected]>
> ---
> 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 +++++++++-------------------
> 5 files changed, 44 insertions(+), 93 deletions(-)

Acked-by: Greg Kroah-Hartman <[email protected]>

2014-06-23 16:15:23

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 21/22] synclink_gt: Use pci_zalloc_consistent

On Mon, Jun 23, 2014 at 06:41:49AM -0700, Joe Perches wrote:
> Remove the now unnecessary memset too.
>
> Signed-off-by: Joe Perches <[email protected]>
> ---
> drivers/tty/synclink_gt.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)

Acked-by: Greg Kroah-Hartman <[email protected]>

2014-06-23 16:15:20

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 22/22] vme: bridges: Use pci_zalloc_consistent

On Mon, Jun 23, 2014 at 06:41:50AM -0700, Joe Perches wrote:
> Remove the now unnecessary memset too.
>
> Signed-off-by: Joe Perches <[email protected]>
> ---
> drivers/vme/bridges/vme_ca91cx42.c | 6 ++----
> drivers/vme/bridges/vme_tsi148.c | 6 ++----
> 2 files changed, 4 insertions(+), 8 deletions(-)

Acked-by: Greg Kroah-Hartman <[email protected]>

2014-06-23 17:25:23

by Luis Chamberlain

[permalink] [raw]
Subject: Re: [PATCH 00/22] Add and use pci_zalloc_consistent

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

2014-06-23 18:08:13

by Don Fry

[permalink] [raw]
Subject: Re: [PATCH 08/22] amd: Use pci_zalloc_consistent

On Mon, 2014-06-23 at 06:41 -0700, Joe Perches wrote:
> Remove the now unnecessary memset too.
>
> Signed-off-by: Joe Perches <[email protected]>
> ---
> 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)

2014-06-23 19:13:37

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 00/22] Add and use pci_zalloc_consistent

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

2014-06-23 19:15:55

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 08/22] amd: Use pci_zalloc_consistent

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.

2014-06-23 21:05:13

by Joe Perches

[permalink] [raw]
Subject: [PATCH V2 08/22] amd: Use pci_zalloc_consistent

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <[email protected]>
---
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)


2014-06-23 21:36:40

by Joe Perches

[permalink] [raw]
Subject: [PATCH] amd: Neaten and remove unnecessary OOM messages

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 <[email protected]>
---
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)

2014-06-23 21:49:33

by David Miller

[permalink] [raw]
Subject: Re: [PATCH 00/22] Add and use pci_zalloc_consistent

From: Joe Perches <[email protected]>
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 <[email protected]>

2014-06-23 22:31:45

by Don Fry

[permalink] [raw]
Subject: Re: [PATCH V2 08/22] amd: Use pci_zalloc_consistent

On Mon, 2014-06-23 at 14:05 -0700, Joe Perches wrote:
> Remove the now unnecessary memset too.
>
> Signed-off-by: Joe Perches <[email protected]>
> ---
> 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 <[email protected]>

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

2014-06-23 22:42:27

by Don Fry

[permalink] [raw]
Subject: Re: [PATCH] amd: Neaten and remove unnecessary OOM messages

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 <[email protected]>
> ---
> 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 <[email protected]>

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

2014-06-23 23:27:50

by Julian Calaby

[permalink] [raw]
Subject: Re: [PATCH 00/22] Add and use pci_zalloc_consistent

Hi Joe,

On Tue, Jun 24, 2014 at 5:13 AM, Joe Perches <[email protected]> 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: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/
.Plan: http://sites.google.com/site/juliancalaby/

2014-06-23 23:48:47

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 00/22] Add and use pci_zalloc_consistent

(Adding Julia Lawall and removing almost all other cc's)

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

Hello Julian.

> > $ 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?

No, not really.

Almost none of the pci_alloc_consistent calls
do not have a test for failure immediately after
them.

Coccinelle is a very cool code transformation tool,
quite useful for these sorts of patch conversions.

http://coccinelle.lip6.fr/documentation.php

2014-06-24 05:24:53

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH 00/22] Add and use pci_zalloc_consistent



On Mon, 23 Jun 2014, Joe Perches wrote:

> (Adding Julia Lawall and removing almost all other cc's)
>
> On Tue, 2014-06-24 at 09:27 +1000, Julian Calaby wrote:
> > Hi Joe,
>
> Hello Julian.
>
> > > $ 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?
>
> No, not really.
>
> Almost none of the pci_alloc_consistent calls
> do not have a test for failure immediately after
> them.

Do not or do?

The advantage of the if is that you are sure that nothing strange happens
to x between alloc and memset. But a problem can be that sometimes people
allocate two things, and then do error checking for both of them. Then
you rule would not match. Or the set the return variable to an error code
before doing the check rather than in the if branch.

You could put the following between the malloc and the memset in stead of
the if.

... when != ( f(...,x,...) | <+...x...+> = E3 )
when != ( while(...) S | for(...;...;...) S )

This has given reasonable results for kmalloc and memset.

julia

> Coccinelle is a very cool code transformation tool,
> quite useful for these sorts of patch conversions.
>
> http://coccinelle.lip6.fr/documentation.php
>
>
>

2014-06-24 07:16:04

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 00/22] Add and use pci_zalloc_consistent

On Tue, 2014-06-24 at 07:24 +0200, Julia Lawall wrote
> On Mon, 23 Jun 2014, Joe Perches wrote:
> > > > $ 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?
> >
> > No, not really.
> >
> > Almost none of the pci_alloc_consistent calls
> > do not have a test for failure immediately after
> > them.

> Do not or do?

Sorry, English double negative.

As far as I know, almost every instance of pci_alloc_consistent
is followed by an if.

Exceptions exist in:

drivers/isdn/hardware/eicon/divasmain.c
drivers/staging/slicoss/slicoss.c
drivers/tty/synclink_gt.c

There might be others, but I didn't look too hard.

> The advantage of the if is that you are sure that nothing strange happens
> to x between alloc and memset. But a problem can be that sometimes people
> allocate two things, and then do error checking for both of them. Then
> you rule would not match. Or the set the return variable to an error code
> before doing the check rather than in the if branch.
>
> You could put the following between the malloc and the memset in stead of
> the if.
>
> ... when != ( f(...,x,...) | <+...x...+> = E3 )
> when != ( while(...) S | for(...;...;...) S )
>
> This has given reasonable results for kmalloc and memset.

Thanks for that.

It might be nice to add that to the kzalloc example
in scripts/coccinelle


2014-06-24 11:33:38

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH 00/22] Add and use pci_zalloc_consistent

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

2014-06-24 12:11:25

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH 00/22] Add and use pci_zalloc_consistent



On Tue, 24 Jun 2014, Joe Perches wrote:

> On Tue, 2014-06-24 at 07:24 +0200, Julia Lawall wrote
> > On Mon, 23 Jun 2014, Joe Perches wrote:
> > > > > $ 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?
> > >
> > > No, not really.
> > >
> > > Almost none of the pci_alloc_consistent calls
> > > do not have a test for failure immediately after
> > > them.
>
> > Do not or do?
>
> Sorry, English double negative.
>
> As far as I know, almost every instance of pci_alloc_consistent
> is followed by an if.
>
> Exceptions exist in:
>
> drivers/isdn/hardware/eicon/divasmain.c
> drivers/staging/slicoss/slicoss.c
> drivers/tty/synclink_gt.c
>
> There might be others, but I didn't look too hard.
>
> > The advantage of the if is that you are sure that nothing strange happens
> > to x between alloc and memset. But a problem can be that sometimes people
> > allocate two things, and then do error checking for both of them. Then
> > you rule would not match. Or the set the return variable to an error code
> > before doing the check rather than in the if branch.
> >
> > You could put the following between the malloc and the memset in stead of
> > the if.
> >
> > ... when != ( f(...,x,...) | <+...x...+> = E3 )
> > when != ( while(...) S | for(...;...;...) S )
> >
> > This has given reasonable results for kmalloc and memset.
>
> Thanks for that.
>
> It might be nice to add that to the kzalloc example
> in scripts/coccinelle

I will do that. Thanks.

julia

2014-06-25 04:49:19

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH V2 08/22] amd: Use pci_zalloc_consistent

On 06/23/2014 02:05 PM, Joe Perches wrote:
> Remove the now unnecessary memset too.
>
> Signed-off-by: Joe Perches <[email protected]>
> ---
> 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

2014-06-25 05:00:01

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH V2 08/22] amd: Use pci_zalloc_consistent

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.

2014-06-25 19:27:58

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH 01/22] pci-dma-compat: Add pci_zalloc_consistent helper

On Mon, 23 Jun 2014 06:41:29 -0700 Joe Perches <[email protected]> wrote:

> Add this helper for consistency with pci_zalloc_coherent
> and the ability to remove unnecessary memset(,0,) uses.

While we're being anal.. I'm not a big fan of the patch titles. Worst
is "amd: Use pci_zalloc_consistent". "amd" is quite a poor identifier
- it's only when you get in and look at the diff that you realise it's
an ethernet driver.

People sometimes address this by using

"drivers: net: ethernet: amd: use pci_zalloc_consistent"

which strikes me as utterly perverse. We already have a nice way of
representing the hierarchy and that's using '/'.

So when the irritation gets too high and when I can be bothered I'll
rewrite things like that to

"drivers/net/ethernet/amd: use pci_zalloc_consistent"

which strikes me as being blindingly obvious, but apparently I'm in a
small minority :(

> --- a/include/asm-generic/pci-dma-compat.h
> +++ b/include/asm-generic/pci-dma-compat.h
> @@ -19,6 +19,14 @@ pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
> return dma_alloc_coherent(hwdev == NULL ? NULL : &hwdev->dev, size, dma_handle, GFP_ATOMIC);
> }
>
> +static inline void *
> +pci_zalloc_consistent(struct pci_dev *hwdev, size_t size,
> + dma_addr_t *dma_handle)
> +{
> + return dma_zalloc_coherent(hwdev == NULL ? NULL : &hwdev->dev,
> + size, dma_handle, GFP_ATOMIC);
> +}
> +

We'd get a smaller kernel by uninlining this. It is hardly
performance-sensitive. Uninlining would presumably use more stack,
but GFP_ATOMIC won't use a ton of stack anyway.

2014-06-25 19:45:15

by John W. Linville

[permalink] [raw]
Subject: Re: [PATCH 00/22] Add and use pci_zalloc_consistent

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
[email protected] might be all we have. Be ready.

2014-06-25 21:51:56

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 01/22] pci-dma-compat: Add pci_zalloc_consistent helper

On Wed, 2014-06-25 at 12:27 -0700, Andrew Morton wrote:
> On Mon, 23 Jun 2014 06:41:29 -0700 Joe Perches <[email protected]> wrote:
>
> > Add this helper for consistency with pci_zalloc_coherent
> > and the ability to remove unnecessary memset(,0,) uses.
>
> While we're being anal.. I'm not a big fan of the patch titles. Worst
> is "amd: Use pci_zalloc_consistent". "amd" is quite a poor identifier
> - it's only when you get in and look at the diff that you realise it's
> an ethernet driver.

Yeah, those "amd:" prefixes should really have been "pcnet32:"

> People sometimes address this by using
>
> "drivers: net: ethernet: amd: use pci_zalloc_consistent"
>
> which strikes me as utterly perverse. We already have a nice way of
> representing the hierarchy and that's using '/'.

I used to do that until several people complained.
Now I don't. btw: Documentation/SubmittingPatches says:

15) The canonical patch format

The canonical patch subject line is:

Subject: [PATCH 001/123] subsystem: summary phrase


> So when the irritation gets too high and when I can be bothered I'll
> rewrite things like that to
>
> "drivers/net/ethernet/amd: use pci_zalloc_consistent"
>
> which strikes me as being blindingly obvious, but apparently I'm in a
> small minority :(
>
> > --- a/include/asm-generic/pci-dma-compat.h
> > +++ b/include/asm-generic/pci-dma-compat.h
> > @@ -19,6 +19,14 @@ pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
> > return dma_alloc_coherent(hwdev == NULL ? NULL : &hwdev->dev, size, dma_handle, GFP_ATOMIC);
> > }
> >
> > +static inline void *
> > +pci_zalloc_consistent(struct pci_dev *hwdev, size_t size,
> > + dma_addr_t *dma_handle)
> > +{
> > + return dma_zalloc_coherent(hwdev == NULL ? NULL : &hwdev->dev,
> > + size, dma_handle, GFP_ATOMIC);
> > +}
> > +
>
> We'd get a smaller kernel by uninlining this. It is hardly
> performance-sensitive. Uninlining would presumably use more stack,
> but GFP_ATOMIC won't use a ton of stack anyway.

True. Maybe via a follow-on patch.

Another option would be to remove pci_[z]alloc_consistent
and just use dma_alloc_coherent instead.

2014-06-25 21:57:47

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH 01/22] pci-dma-compat: Add pci_zalloc_consistent helper

On Wed, 25 Jun 2014 14:51:51 -0700 Joe Perches <[email protected]> wrote:

> > People sometimes address this by using
> >
> > "drivers: net: ethernet: amd: use pci_zalloc_consistent"
> >
> > which strikes me as utterly perverse. We already have a nice way of
> > representing the hierarchy and that's using '/'.
>
> I used to do that until several people complained.

Slap 'em.

I don't know where this thing is coming from - I'd suspected there must
be some misguided doc somewhere but I don't know where it is. Some
vast conspiracy against common sense.

> Now I don't. btw: Documentation/SubmittingPatches says:
>
> 15) The canonical patch format
>
> The canonical patch subject line is:
>
> Subject: [PATCH 001/123] subsystem: summary phrase

Yes, that doesn't go into how to identify the subsystem.

I don't want to be overly proscriptive here, but it's a bit maddening
when you're skimming patch titles and cannot work out which part of the
kernel is being patched :(

2014-06-25 22:14:06

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 01/22] pci-dma-compat: Add pci_zalloc_consistent helper

On Wed, 2014-06-25 at 14:57 -0700, Andrew Morton wrote:
> On Wed, 25 Jun 2014 14:51:51 -0700 Joe Perches <[email protected]> wrote:
>
> > > People sometimes address this by using
> > >
> > > "drivers: net: ethernet: amd: use pci_zalloc_consistent"
> > >
> > > which strikes me as utterly perverse. We already have a nice way of
> > > representing the hierarchy and that's using '/'.
> >
> > I used to do that until several people complained.
>
> Slap 'em.

And get booked for assault? No thanks.
My mild-mannered persona thinks that a poor plan.

My actual feeling is I don't much care.

btw: https://lkml.org/lkml/2010/11/15/387

I also proposed a scheme where the prescriptive
patch subject pedants could put some pattern
into MAINTAINERS so that these subject lines
could be more automatically generated.

https://lkml.org/lkml/2010/11/16/245

> I don't know where this thing is coming from - I'd suspected there must
> be some misguided doc somewhere but I don't know where it is. Some
> vast conspiracy against common sense.

> I don't want to be overly proscriptive here, but it's a bit maddening
> when you're skimming patch titles and cannot work out which part of the
> kernel is being patched :(

Yup.

2014-06-25 22:31:15

by David Miller

[permalink] [raw]
Subject: Re: [PATCH 01/22] pci-dma-compat: Add pci_zalloc_consistent helper

From: Joe Perches <[email protected]>
Date: Wed, 25 Jun 2014 14:51:51 -0700

> On Wed, 2014-06-25 at 12:27 -0700, Andrew Morton wrote:
>> On Mon, 23 Jun 2014 06:41:29 -0700 Joe Perches <[email protected]> wrote:
>>
>> > Add this helper for consistency with pci_zalloc_coherent
>> > and the ability to remove unnecessary memset(,0,) uses.
>>
>> While we're being anal.. I'm not a big fan of the patch titles. Worst
>> is "amd: Use pci_zalloc_consistent". "amd" is quite a poor identifier
>> - it's only when you get in and look at the diff that you realise it's
>> an ethernet driver.
>
> Yeah, those "amd:" prefixes should really have been "pcnet32:"
>
>> People sometimes address this by using
>>
>> "drivers: net: ethernet: amd: use pci_zalloc_consistent"
>>
>> which strikes me as utterly perverse. We already have a nice way of
>> representing the hierarchy and that's using '/'.
>
> I used to do that until several people complained.
> Now I don't. btw: Documentation/SubmittingPatches says:
>
> 15) The canonical patch format
>
> The canonical patch subject line is:
>
> Subject: [PATCH 001/123] subsystem: summary phrase

+1

We've been representing subsystems using colon prefixes for ages, and
I can't seen the value of starting to use something inconsistent with
a decade of precedence.

2014-06-25 23:32:32

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] amd: Neaten and remove unnecessary OOM messages

From: Joe Perches <[email protected]>
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 <[email protected]>

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

2014-06-25 23:51:44

by Joe Perches

[permalink] [raw]
Subject: [PATCH V3 08/22] pcnet32: Use pci_zalloc_consistent

Remove the now unnecessary memset too.

Signed-off-by: Joe Perches <[email protected]>
Acked-by: Don Fry <[email protected]>
---
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)




2014-06-25 23:55:31

by Joe Perches

[permalink] [raw]
Subject: [PATCH V2] pcnet32: Neaten and remove unnecessary OOM messages

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 <[email protected]>
Acked-by: Don Fry <[email protected]>
---
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)

Subject: Re: [PATCH 10/22] enic: Use pci_zalloc_consistent



On Mon, 23 Jun 2014, Joe Perches wrote:

> Remove the now unnecessary memset too.
>
> Signed-off-by: Joe Perches <[email protected]>

Looks good, thanks
Acked-by: Govindarajulu Varadarajan <[email protected]>

> ---
> 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
>
>

2014-06-27 08:20:52

by Hans Verkuil

[permalink] [raw]
Subject: Re: [PATCH 07/22] media: Use pci_zalloc_consistent

Hi Joe,

For the media subsystem:

Acked-by: Hans Verkuil <[email protected]>

Regards,

Hans

On 06/23/2014 03:41 PM, Joe Perches wrote:
> Remove the now unnecessary memset too.
>
> Signed-off-by: Joe Perches <[email protected]>
> ---
> 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 +++--------
> 6 files changed, 22 insertions(+), 43 deletions(-)
>
> diff --git a/drivers/media/common/saa7146/saa7146_core.c b/drivers/media/common/saa7146/saa7146_core.c
> index 34b0d0d..97afee6 100644
> --- a/drivers/media/common/saa7146/saa7146_core.c
> +++ b/drivers/media/common/saa7146/saa7146_core.c
> @@ -421,23 +421,20 @@ static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent
> err = -ENOMEM;
>
> /* get memory for various stuff */
> - dev->d_rps0.cpu_addr = pci_alloc_consistent(pci, SAA7146_RPS_MEM,
> - &dev->d_rps0.dma_handle);
> + dev->d_rps0.cpu_addr = pci_zalloc_consistent(pci, SAA7146_RPS_MEM,
> + &dev->d_rps0.dma_handle);
> if (!dev->d_rps0.cpu_addr)
> goto err_free_irq;
> - memset(dev->d_rps0.cpu_addr, 0x0, SAA7146_RPS_MEM);
>
> - dev->d_rps1.cpu_addr = pci_alloc_consistent(pci, SAA7146_RPS_MEM,
> - &dev->d_rps1.dma_handle);
> + dev->d_rps1.cpu_addr = pci_zalloc_consistent(pci, SAA7146_RPS_MEM,
> + &dev->d_rps1.dma_handle);
> if (!dev->d_rps1.cpu_addr)
> goto err_free_rps0;
> - memset(dev->d_rps1.cpu_addr, 0x0, SAA7146_RPS_MEM);
>
> - dev->d_i2c.cpu_addr = pci_alloc_consistent(pci, SAA7146_RPS_MEM,
> - &dev->d_i2c.dma_handle);
> + dev->d_i2c.cpu_addr = pci_zalloc_consistent(pci, SAA7146_RPS_MEM,
> + &dev->d_i2c.dma_handle);
> if (!dev->d_i2c.cpu_addr)
> goto err_free_rps1;
> - memset(dev->d_i2c.cpu_addr, 0x0, SAA7146_RPS_MEM);
>
> /* the rest + print status message */
>
> diff --git a/drivers/media/common/saa7146/saa7146_fops.c b/drivers/media/common/saa7146/saa7146_fops.c
> index eda01bc..a776a80 100644
> --- a/drivers/media/common/saa7146/saa7146_fops.c
> +++ b/drivers/media/common/saa7146/saa7146_fops.c
> @@ -520,14 +520,15 @@ int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv)
> configuration data) */
> dev->ext_vv_data = ext_vv;
>
> - vv->d_clipping.cpu_addr = pci_alloc_consistent(dev->pci, SAA7146_CLIPPING_MEM, &vv->d_clipping.dma_handle);
> + vv->d_clipping.cpu_addr =
> + pci_zalloc_consistent(dev->pci, SAA7146_CLIPPING_MEM,
> + &vv->d_clipping.dma_handle);
> if( NULL == vv->d_clipping.cpu_addr ) {
> ERR("out of memory. aborting.\n");
> kfree(vv);
> v4l2_ctrl_handler_free(hdl);
> return -1;
> }
> - memset(vv->d_clipping.cpu_addr, 0x0, SAA7146_CLIPPING_MEM);
>
> saa7146_video_uops.init(dev,vv);
> if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
> diff --git a/drivers/media/pci/bt8xx/bt878.c b/drivers/media/pci/bt8xx/bt878.c
> index d0c281f..1176583 100644
> --- a/drivers/media/pci/bt8xx/bt878.c
> +++ b/drivers/media/pci/bt8xx/bt878.c
> @@ -101,28 +101,20 @@ static int bt878_mem_alloc(struct bt878 *bt)
> if (!bt->buf_cpu) {
> bt->buf_size = 128 * 1024;
>
> - bt->buf_cpu =
> - pci_alloc_consistent(bt->dev, bt->buf_size,
> - &bt->buf_dma);
> -
> + bt->buf_cpu = pci_zalloc_consistent(bt->dev, bt->buf_size,
> + &bt->buf_dma);
> if (!bt->buf_cpu)
> return -ENOMEM;
> -
> - memset(bt->buf_cpu, 0, bt->buf_size);
> }
>
> if (!bt->risc_cpu) {
> bt->risc_size = PAGE_SIZE;
> - bt->risc_cpu =
> - pci_alloc_consistent(bt->dev, bt->risc_size,
> - &bt->risc_dma);
> -
> + bt->risc_cpu = pci_zalloc_consistent(bt->dev, bt->risc_size,
> + &bt->risc_dma);
> if (!bt->risc_cpu) {
> bt878_mem_free(bt);
> return -ENOMEM;
> }
> -
> - memset(bt->risc_cpu, 0, bt->risc_size);
> }
>
> return 0;
> diff --git a/drivers/media/pci/ngene/ngene-core.c b/drivers/media/pci/ngene/ngene-core.c
> index 970e833..37dc149 100644
> --- a/drivers/media/pci/ngene/ngene-core.c
> +++ b/drivers/media/pci/ngene/ngene-core.c
> @@ -1078,12 +1078,11 @@ static int AllocCommonBuffers(struct ngene *dev)
> dev->ngenetohost = dev->FWInterfaceBuffer + 256;
> dev->EventBuffer = dev->FWInterfaceBuffer + 512;
>
> - dev->OverflowBuffer = pci_alloc_consistent(dev->pci_dev,
> - OVERFLOW_BUFFER_SIZE,
> - &dev->PAOverflowBuffer);
> + dev->OverflowBuffer = pci_zalloc_consistent(dev->pci_dev,
> + OVERFLOW_BUFFER_SIZE,
> + &dev->PAOverflowBuffer);
> if (!dev->OverflowBuffer)
> return -ENOMEM;
> - memset(dev->OverflowBuffer, 0, OVERFLOW_BUFFER_SIZE);
>
> for (i = STREAM_VIDEOIN1; i < MAX_STREAM; i++) {
> int type = dev->card_info->io_type[i];
> diff --git a/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c b/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
> index f8a60c1..0d3194a 100644
> --- a/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
> +++ b/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
> @@ -804,11 +804,9 @@ static int ttusb_alloc_iso_urbs(struct ttusb *ttusb)
> {
> int i;
>
> - ttusb->iso_buffer = pci_alloc_consistent(NULL,
> - ISO_FRAME_SIZE *
> - FRAMES_PER_ISO_BUF *
> - ISO_BUF_COUNT,
> - &ttusb->iso_dma_handle);
> + ttusb->iso_buffer = pci_zalloc_consistent(NULL,
> + ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF * ISO_BUF_COUNT,
> + &ttusb->iso_dma_handle);
>
> if (!ttusb->iso_buffer) {
> dprintk("%s: pci_alloc_consistent - not enough memory\n",
> @@ -816,9 +814,6 @@ static int ttusb_alloc_iso_urbs(struct ttusb *ttusb)
> return -ENOMEM;
> }
>
> - memset(ttusb->iso_buffer, 0,
> - ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF * ISO_BUF_COUNT);
> -
> for (i = 0; i < ISO_BUF_COUNT; i++) {
> struct urb *urb;
>
> diff --git a/drivers/media/usb/ttusb-dec/ttusb_dec.c b/drivers/media/usb/ttusb-dec/ttusb_dec.c
> index 29724af..15ab584 100644
> --- a/drivers/media/usb/ttusb-dec/ttusb_dec.c
> +++ b/drivers/media/usb/ttusb-dec/ttusb_dec.c
> @@ -1151,11 +1151,9 @@ static int ttusb_dec_alloc_iso_urbs(struct ttusb_dec *dec)
>
> dprintk("%s\n", __func__);
>
> - dec->iso_buffer = pci_alloc_consistent(NULL,
> - ISO_FRAME_SIZE *
> - (FRAMES_PER_ISO_BUF *
> - ISO_BUF_COUNT),
> - &dec->iso_dma_handle);
> + dec->iso_buffer = pci_zalloc_consistent(NULL,
> + ISO_FRAME_SIZE * (FRAMES_PER_ISO_BUF * ISO_BUF_COUNT),
> + &dec->iso_dma_handle);
>
> if (!dec->iso_buffer) {
> dprintk("%s: pci_alloc_consistent - not enough memory\n",
> @@ -1163,9 +1161,6 @@ static int ttusb_dec_alloc_iso_urbs(struct ttusb_dec *dec)
> return -ENOMEM;
> }
>
> - memset(dec->iso_buffer, 0,
> - ISO_FRAME_SIZE * (FRAMES_PER_ISO_BUF * ISO_BUF_COUNT));
> -
> for (i = 0; i < ISO_BUF_COUNT; i++) {
> struct urb *urb;
>
>

2014-06-27 10:55:28

by Mauro Carvalho Chehab

[permalink] [raw]
Subject: Re: [PATCH 07/22] media: Use pci_zalloc_consistent

Em Fri, 27 Jun 2014 10:20:33 +0200
Hans Verkuil <[email protected]> escreveu:

> Hi Joe,
>
> For the media subsystem:
>
> Acked-by: Hans Verkuil <[email protected]>

Err... I would rather prefer to apply this patch on our subsystem, in order
to avoid potential conflicts with other patches. Not really a big deal, as
those drivers aren't being touched for a while, but who knows what patches
may appear for them up to the next merge tree?

Regards,
Mauro

>
> Regards,
>
> Hans
>
> On 06/23/2014 03:41 PM, Joe Perches wrote:
> > Remove the now unnecessary memset too.
> >
> > Signed-off-by: Joe Perches <[email protected]>
> > ---
> > 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 +++--------
> > 6 files changed, 22 insertions(+), 43 deletions(-)
> >
> > diff --git a/drivers/media/common/saa7146/saa7146_core.c b/drivers/media/common/saa7146/saa7146_core.c
> > index 34b0d0d..97afee6 100644
> > --- a/drivers/media/common/saa7146/saa7146_core.c
> > +++ b/drivers/media/common/saa7146/saa7146_core.c
> > @@ -421,23 +421,20 @@ static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent
> > err = -ENOMEM;
> >
> > /* get memory for various stuff */
> > - dev->d_rps0.cpu_addr = pci_alloc_consistent(pci, SAA7146_RPS_MEM,
> > - &dev->d_rps0.dma_handle);
> > + dev->d_rps0.cpu_addr = pci_zalloc_consistent(pci, SAA7146_RPS_MEM,
> > + &dev->d_rps0.dma_handle);
> > if (!dev->d_rps0.cpu_addr)
> > goto err_free_irq;
> > - memset(dev->d_rps0.cpu_addr, 0x0, SAA7146_RPS_MEM);
> >
> > - dev->d_rps1.cpu_addr = pci_alloc_consistent(pci, SAA7146_RPS_MEM,
> > - &dev->d_rps1.dma_handle);
> > + dev->d_rps1.cpu_addr = pci_zalloc_consistent(pci, SAA7146_RPS_MEM,
> > + &dev->d_rps1.dma_handle);
> > if (!dev->d_rps1.cpu_addr)
> > goto err_free_rps0;
> > - memset(dev->d_rps1.cpu_addr, 0x0, SAA7146_RPS_MEM);
> >
> > - dev->d_i2c.cpu_addr = pci_alloc_consistent(pci, SAA7146_RPS_MEM,
> > - &dev->d_i2c.dma_handle);
> > + dev->d_i2c.cpu_addr = pci_zalloc_consistent(pci, SAA7146_RPS_MEM,
> > + &dev->d_i2c.dma_handle);
> > if (!dev->d_i2c.cpu_addr)
> > goto err_free_rps1;
> > - memset(dev->d_i2c.cpu_addr, 0x0, SAA7146_RPS_MEM);
> >
> > /* the rest + print status message */
> >
> > diff --git a/drivers/media/common/saa7146/saa7146_fops.c b/drivers/media/common/saa7146/saa7146_fops.c
> > index eda01bc..a776a80 100644
> > --- a/drivers/media/common/saa7146/saa7146_fops.c
> > +++ b/drivers/media/common/saa7146/saa7146_fops.c
> > @@ -520,14 +520,15 @@ int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv)
> > configuration data) */
> > dev->ext_vv_data = ext_vv;
> >
> > - vv->d_clipping.cpu_addr = pci_alloc_consistent(dev->pci, SAA7146_CLIPPING_MEM, &vv->d_clipping.dma_handle);
> > + vv->d_clipping.cpu_addr =
> > + pci_zalloc_consistent(dev->pci, SAA7146_CLIPPING_MEM,
> > + &vv->d_clipping.dma_handle);
> > if( NULL == vv->d_clipping.cpu_addr ) {
> > ERR("out of memory. aborting.\n");
> > kfree(vv);
> > v4l2_ctrl_handler_free(hdl);
> > return -1;
> > }
> > - memset(vv->d_clipping.cpu_addr, 0x0, SAA7146_CLIPPING_MEM);
> >
> > saa7146_video_uops.init(dev,vv);
> > if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
> > diff --git a/drivers/media/pci/bt8xx/bt878.c b/drivers/media/pci/bt8xx/bt878.c
> > index d0c281f..1176583 100644
> > --- a/drivers/media/pci/bt8xx/bt878.c
> > +++ b/drivers/media/pci/bt8xx/bt878.c
> > @@ -101,28 +101,20 @@ static int bt878_mem_alloc(struct bt878 *bt)
> > if (!bt->buf_cpu) {
> > bt->buf_size = 128 * 1024;
> >
> > - bt->buf_cpu =
> > - pci_alloc_consistent(bt->dev, bt->buf_size,
> > - &bt->buf_dma);
> > -
> > + bt->buf_cpu = pci_zalloc_consistent(bt->dev, bt->buf_size,
> > + &bt->buf_dma);
> > if (!bt->buf_cpu)
> > return -ENOMEM;
> > -
> > - memset(bt->buf_cpu, 0, bt->buf_size);
> > }
> >
> > if (!bt->risc_cpu) {
> > bt->risc_size = PAGE_SIZE;
> > - bt->risc_cpu =
> > - pci_alloc_consistent(bt->dev, bt->risc_size,
> > - &bt->risc_dma);
> > -
> > + bt->risc_cpu = pci_zalloc_consistent(bt->dev, bt->risc_size,
> > + &bt->risc_dma);
> > if (!bt->risc_cpu) {
> > bt878_mem_free(bt);
> > return -ENOMEM;
> > }
> > -
> > - memset(bt->risc_cpu, 0, bt->risc_size);
> > }
> >
> > return 0;
> > diff --git a/drivers/media/pci/ngene/ngene-core.c b/drivers/media/pci/ngene/ngene-core.c
> > index 970e833..37dc149 100644
> > --- a/drivers/media/pci/ngene/ngene-core.c
> > +++ b/drivers/media/pci/ngene/ngene-core.c
> > @@ -1078,12 +1078,11 @@ static int AllocCommonBuffers(struct ngene *dev)
> > dev->ngenetohost = dev->FWInterfaceBuffer + 256;
> > dev->EventBuffer = dev->FWInterfaceBuffer + 512;
> >
> > - dev->OverflowBuffer = pci_alloc_consistent(dev->pci_dev,
> > - OVERFLOW_BUFFER_SIZE,
> > - &dev->PAOverflowBuffer);
> > + dev->OverflowBuffer = pci_zalloc_consistent(dev->pci_dev,
> > + OVERFLOW_BUFFER_SIZE,
> > + &dev->PAOverflowBuffer);
> > if (!dev->OverflowBuffer)
> > return -ENOMEM;
> > - memset(dev->OverflowBuffer, 0, OVERFLOW_BUFFER_SIZE);
> >
> > for (i = STREAM_VIDEOIN1; i < MAX_STREAM; i++) {
> > int type = dev->card_info->io_type[i];
> > diff --git a/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c b/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
> > index f8a60c1..0d3194a 100644
> > --- a/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
> > +++ b/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
> > @@ -804,11 +804,9 @@ static int ttusb_alloc_iso_urbs(struct ttusb *ttusb)
> > {
> > int i;
> >
> > - ttusb->iso_buffer = pci_alloc_consistent(NULL,
> > - ISO_FRAME_SIZE *
> > - FRAMES_PER_ISO_BUF *
> > - ISO_BUF_COUNT,
> > - &ttusb->iso_dma_handle);
> > + ttusb->iso_buffer = pci_zalloc_consistent(NULL,
> > + ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF * ISO_BUF_COUNT,
> > + &ttusb->iso_dma_handle);
> >
> > if (!ttusb->iso_buffer) {
> > dprintk("%s: pci_alloc_consistent - not enough memory\n",
> > @@ -816,9 +814,6 @@ static int ttusb_alloc_iso_urbs(struct ttusb *ttusb)
> > return -ENOMEM;
> > }
> >
> > - memset(ttusb->iso_buffer, 0,
> > - ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF * ISO_BUF_COUNT);
> > -
> > for (i = 0; i < ISO_BUF_COUNT; i++) {
> > struct urb *urb;
> >
> > diff --git a/drivers/media/usb/ttusb-dec/ttusb_dec.c b/drivers/media/usb/ttusb-dec/ttusb_dec.c
> > index 29724af..15ab584 100644
> > --- a/drivers/media/usb/ttusb-dec/ttusb_dec.c
> > +++ b/drivers/media/usb/ttusb-dec/ttusb_dec.c
> > @@ -1151,11 +1151,9 @@ static int ttusb_dec_alloc_iso_urbs(struct ttusb_dec *dec)
> >
> > dprintk("%s\n", __func__);
> >
> > - dec->iso_buffer = pci_alloc_consistent(NULL,
> > - ISO_FRAME_SIZE *
> > - (FRAMES_PER_ISO_BUF *
> > - ISO_BUF_COUNT),
> > - &dec->iso_dma_handle);
> > + dec->iso_buffer = pci_zalloc_consistent(NULL,
> > + ISO_FRAME_SIZE * (FRAMES_PER_ISO_BUF * ISO_BUF_COUNT),
> > + &dec->iso_dma_handle);
> >
> > if (!dec->iso_buffer) {
> > dprintk("%s: pci_alloc_consistent - not enough memory\n",
> > @@ -1163,9 +1161,6 @@ static int ttusb_dec_alloc_iso_urbs(struct ttusb_dec *dec)
> > return -ENOMEM;
> > }
> >
> > - memset(dec->iso_buffer, 0,
> > - ISO_FRAME_SIZE * (FRAMES_PER_ISO_BUF * ISO_BUF_COUNT));
> > -
> > for (i = 0; i < ISO_BUF_COUNT; i++) {
> > struct urb *urb;
> >
> >

2014-07-01 19:19:38

by David Miller

[permalink] [raw]
Subject: Re: [PATCH V2] pcnet32: Neaten and remove unnecessary OOM messages

From: Joe Perches <[email protected]>
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 <[email protected]>
> Acked-by: Don Fry <[email protected]>
> ---
> 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.

2014-07-01 19:26:58

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH V2] pcnet32: Neaten and remove unnecessary OOM messages

On Tue, 2014-07-01 at 12:19 -0700, David Miller wrote:
> From: Joe Perches <[email protected]> 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)

2014-07-08 10:13:33

by Daniel Vetter

[permalink] [raw]
Subject: Re: [PATCH 06/22] i810: Use pci_zalloc_consistent

On Mon, Jun 23, 2014 at 06:41:34AM -0700, Joe Perches wrote:
> Remove the now unnecessary memset too.
>
> Signed-off-by: Joe Perches <[email protected]>

Since I seem to be the last idiot to have touched i810.ko:
Acked-by: Daniel Vetter <[email protected]>

> ---
> drivers/gpu/drm/i810/i810_dma.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
> index e88bac1..bae897d 100644
> --- a/drivers/gpu/drm/i810/i810_dma.c
> +++ b/drivers/gpu/drm/i810/i810_dma.c
> @@ -393,15 +393,14 @@ static int i810_dma_initialize(struct drm_device *dev,
>
> /* Program Hardware Status Page */
> dev_priv->hw_status_page =
> - pci_alloc_consistent(dev->pdev, PAGE_SIZE,
> - &dev_priv->dma_status_page);
> + pci_zalloc_consistent(dev->pdev, PAGE_SIZE,
> + &dev_priv->dma_status_page);
> if (!dev_priv->hw_status_page) {
> dev->dev_private = (void *)dev_priv;
> i810_dma_cleanup(dev);
> DRM_ERROR("Can not allocate hardware status page\n");
> return -ENOMEM;
> }
> - memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
> DRM_DEBUG("hw status page @ %p\n", dev_priv->hw_status_page);
>
> I810_WRITE(0x02080, dev_priv->dma_status_page);
> --
> 1.8.1.2.459.gbcd45b4.dirty
>
> _______________________________________________
> dri-devel mailing list
> [email protected]
> http://lists.freedesktop.org/mailman/listinfo/dri-devel

--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch