2014-06-23 13:41:28

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:41:32

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 17:25:12

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 19:13:29

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 21:49:30

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 <davem-fT/PcQaiUtIeIZ0/[email protected]>

2014-06-23 23:27:25

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-24 11:32:49

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-25 19:41:12

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.