* [PATCH 15/22] ipw2100: Use pci_zalloc_consistent
2014-06-23 13:41 [PATCH 00/22] Add and use pci_zalloc_consistent Joe Perches
@ 2014-06-23 13:41 ` Joe Perches
2014-06-23 13:41 ` [PATCH 16/22] mwl8k: " Joe Perches
` (5 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Joe Perches @ 2014-06-23 13:41 UTC (permalink / raw)
To: linux-kernel; +Cc: Stanislav Yakovlev, John W. Linville, linux-wireless, netdev
Remove the now unnecessary memset too.
Signed-off-by: Joe Perches <joe@perches.com>
---
drivers/net/wireless/ipw2x00/ipw2100.c | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
diff --git a/drivers/net/wireless/ipw2x00/ipw2100.c b/drivers/net/wireless/ipw2x00/ipw2100.c
index dfc6dfc..1ab8e50 100644
--- a/drivers/net/wireless/ipw2x00/ipw2100.c
+++ b/drivers/net/wireless/ipw2x00/ipw2100.c
@@ -3449,8 +3449,9 @@ static int ipw2100_msg_allocate(struct ipw2100_priv *priv)
return -ENOMEM;
for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
- v = pci_alloc_consistent(priv->pci_dev,
- sizeof(struct ipw2100_cmd_header), &p);
+ v = pci_zalloc_consistent(priv->pci_dev,
+ sizeof(struct ipw2100_cmd_header),
+ &p);
if (!v) {
printk(KERN_ERR DRV_NAME ": "
"%s: PCI alloc failed for msg "
@@ -3459,8 +3460,6 @@ static int ipw2100_msg_allocate(struct ipw2100_priv *priv)
break;
}
- memset(v, 0, sizeof(struct ipw2100_cmd_header));
-
priv->msg_buffers[i].type = COMMAND;
priv->msg_buffers[i].info.c_struct.cmd =
(struct ipw2100_cmd_header *)v;
@@ -4336,16 +4335,12 @@ static int status_queue_allocate(struct ipw2100_priv *priv, int entries)
IPW_DEBUG_INFO("enter\n");
q->size = entries * sizeof(struct ipw2100_status);
- q->drv =
- (struct ipw2100_status *)pci_alloc_consistent(priv->pci_dev,
- q->size, &q->nic);
+ q->drv = pci_zalloc_consistent(priv->pci_dev, q->size, &q->nic);
if (!q->drv) {
IPW_DEBUG_WARNING("Can not allocate status queue.\n");
return -ENOMEM;
}
- memset(q->drv, 0, q->size);
-
IPW_DEBUG_INFO("exit\n");
return 0;
@@ -4374,13 +4369,12 @@ static int bd_queue_allocate(struct ipw2100_priv *priv,
q->entries = entries;
q->size = entries * sizeof(struct ipw2100_bd);
- q->drv = pci_alloc_consistent(priv->pci_dev, q->size, &q->nic);
+ q->drv = pci_zalloc_consistent(priv->pci_dev, q->size, &q->nic);
if (!q->drv) {
IPW_DEBUG_INFO
("can't allocate shared memory for buffer descriptors\n");
return -ENOMEM;
}
- memset(q->drv, 0, q->size);
IPW_DEBUG_INFO("exit\n");
--
1.8.1.2.459.gbcd45b4.dirty
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 16/22] mwl8k: Use pci_zalloc_consistent
2014-06-23 13:41 [PATCH 00/22] Add and use pci_zalloc_consistent Joe Perches
2014-06-23 13:41 ` [PATCH 15/22] ipw2100: Use pci_zalloc_consistent Joe Perches
@ 2014-06-23 13:41 ` Joe Perches
2014-06-23 13:41 ` [PATCH 17/22] rtl818x: " Joe Perches
` (4 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Joe Perches @ 2014-06-23 13:41 UTC (permalink / raw)
To: linux-kernel; +Cc: Lennert Buytenhek, John W. Linville, linux-wireless, netdev
Remove the now unnecessary memset too.
Signed-off-by: Joe Perches <joe@perches.com>
---
drivers/net/wireless/mwl8k.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/net/wireless/mwl8k.c b/drivers/net/wireless/mwl8k.c
index 3c0a0a8..7e6b981 100644
--- a/drivers/net/wireless/mwl8k.c
+++ b/drivers/net/wireless/mwl8k.c
@@ -1159,12 +1159,11 @@ static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
- rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
+ rxq->rxd = pci_zalloc_consistent(priv->pdev, size, &rxq->rxd_dma);
if (rxq->rxd == NULL) {
wiphy_err(hw->wiphy, "failed to alloc RX descriptors\n");
return -ENOMEM;
}
- memset(rxq->rxd, 0, size);
rxq->buf = kcalloc(MWL8K_RX_DESCS, sizeof(*rxq->buf), GFP_KERNEL);
if (rxq->buf == NULL) {
@@ -1451,12 +1450,11 @@ static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
- txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
+ txq->txd = pci_zalloc_consistent(priv->pdev, size, &txq->txd_dma);
if (txq->txd == NULL) {
wiphy_err(hw->wiphy, "failed to alloc TX descriptors\n");
return -ENOMEM;
}
- memset(txq->txd, 0, size);
txq->skb = kcalloc(MWL8K_TX_DESCS, sizeof(*txq->skb), GFP_KERNEL);
if (txq->skb == NULL) {
--
1.8.1.2.459.gbcd45b4.dirty
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 17/22] rtl818x: Use pci_zalloc_consistent
2014-06-23 13:41 [PATCH 00/22] Add and use pci_zalloc_consistent Joe Perches
2014-06-23 13:41 ` [PATCH 15/22] ipw2100: Use pci_zalloc_consistent Joe Perches
2014-06-23 13:41 ` [PATCH 16/22] mwl8k: " Joe Perches
@ 2014-06-23 13:41 ` Joe Perches
2014-06-23 13:41 ` [PATCH 18/22] rtlwifi: " Joe Perches
` (3 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Joe Perches @ 2014-06-23 13:41 UTC (permalink / raw)
To: linux-kernel; +Cc: John W. Linville, linux-wireless, netdev
Remove the now unnecessary memset too.
Signed-off-by: Joe Perches <joe@perches.com>
---
drivers/net/wireless/rtl818x/rtl8180/dev.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/drivers/net/wireless/rtl818x/rtl8180/dev.c b/drivers/net/wireless/rtl818x/rtl8180/dev.c
index 1e25929..7577e01 100644
--- a/drivers/net/wireless/rtl818x/rtl8180/dev.c
+++ b/drivers/net/wireless/rtl818x/rtl8180/dev.c
@@ -964,16 +964,13 @@ static int rtl8180_init_rx_ring(struct ieee80211_hw *dev)
else
priv->rx_ring_sz = sizeof(struct rtl8180_rx_desc);
- priv->rx_ring = pci_alloc_consistent(priv->pdev,
- priv->rx_ring_sz * 32,
- &priv->rx_ring_dma);
-
+ priv->rx_ring = pci_zalloc_consistent(priv->pdev, priv->rx_ring_sz * 32,
+ &priv->rx_ring_dma);
if (!priv->rx_ring || (unsigned long)priv->rx_ring & 0xFF) {
wiphy_err(dev->wiphy, "Cannot allocate RX ring\n");
return -ENOMEM;
}
- memset(priv->rx_ring, 0, priv->rx_ring_sz * 32);
priv->rx_idx = 0;
for (i = 0; i < 32; i++) {
@@ -1032,14 +1029,14 @@ static int rtl8180_init_tx_ring(struct ieee80211_hw *dev,
dma_addr_t dma;
int i;
- ring = pci_alloc_consistent(priv->pdev, sizeof(*ring) * entries, &dma);
+ ring = pci_zalloc_consistent(priv->pdev, sizeof(*ring) * entries,
+ &dma);
if (!ring || (unsigned long)ring & 0xFF) {
wiphy_err(dev->wiphy, "Cannot allocate TX ring (prio = %d)\n",
prio);
return -ENOMEM;
}
- memset(ring, 0, sizeof(*ring)*entries);
priv->tx_ring[prio].desc = ring;
priv->tx_ring[prio].dma = dma;
priv->tx_ring[prio].idx = 0;
--
1.8.1.2.459.gbcd45b4.dirty
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 18/22] rtlwifi: Use pci_zalloc_consistent
2014-06-23 13:41 [PATCH 00/22] Add and use pci_zalloc_consistent Joe Perches
` (2 preceding siblings ...)
2014-06-23 13:41 ` [PATCH 17/22] rtl818x: " Joe Perches
@ 2014-06-23 13:41 ` Joe Perches
2014-06-23 17:25 ` [PATCH 00/22] Add and use pci_zalloc_consistent Luis R. Rodriguez
` (2 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Joe Perches @ 2014-06-23 13:41 UTC (permalink / raw)
To: linux-kernel
Cc: Larry Finger, Chaoming Li, John W. Linville, linux-wireless,
netdev
Remove the now unnecessary memset too.
Signed-off-by: Joe Perches <joe@perches.com>
---
drivers/net/wireless/rtlwifi/pci.c | 17 +++++------------
1 file changed, 5 insertions(+), 12 deletions(-)
diff --git a/drivers/net/wireless/rtlwifi/pci.c b/drivers/net/wireless/rtlwifi/pci.c
index dae5525..67d1ee6 100644
--- a/drivers/net/wireless/rtlwifi/pci.c
+++ b/drivers/net/wireless/rtlwifi/pci.c
@@ -1092,16 +1092,14 @@ static int _rtl_pci_init_tx_ring(struct ieee80211_hw *hw,
u32 nextdescaddress;
int i;
- ring = pci_alloc_consistent(rtlpci->pdev,
- sizeof(*ring) * entries, &dma);
-
+ ring = pci_zalloc_consistent(rtlpci->pdev, sizeof(*ring) * entries,
+ &dma);
if (!ring || (unsigned long)ring & 0xFF) {
RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
"Cannot allocate TX ring (prio = %d)\n", prio);
return -ENOMEM;
}
- memset(ring, 0, sizeof(*ring) * entries);
rtlpci->tx_ring[prio].desc = ring;
rtlpci->tx_ring[prio].dma = dma;
rtlpci->tx_ring[prio].idx = 0;
@@ -1139,10 +1137,9 @@ static int _rtl_pci_init_rx_ring(struct ieee80211_hw *hw)
for (rx_queue_idx = 0; rx_queue_idx < RTL_PCI_MAX_RX_QUEUE;
rx_queue_idx++) {
rtlpci->rx_ring[rx_queue_idx].desc =
- pci_alloc_consistent(rtlpci->pdev,
- sizeof(*rtlpci->rx_ring[rx_queue_idx].
- desc) * rtlpci->rxringcount,
- &rtlpci->rx_ring[rx_queue_idx].dma);
+ pci_zalloc_consistent(rtlpci->pdev,
+ sizeof(*rtlpci->rx_ring[rx_queue_idx].desc) * rtlpci->rxringcount,
+ &rtlpci->rx_ring[rx_queue_idx].dma);
if (!rtlpci->rx_ring[rx_queue_idx].desc ||
(unsigned long)rtlpci->rx_ring[rx_queue_idx].desc & 0xFF) {
@@ -1151,10 +1148,6 @@ static int _rtl_pci_init_rx_ring(struct ieee80211_hw *hw)
return -ENOMEM;
}
- memset(rtlpci->rx_ring[rx_queue_idx].desc, 0,
- sizeof(*rtlpci->rx_ring[rx_queue_idx].desc) *
- rtlpci->rxringcount);
-
rtlpci->rx_ring[rx_queue_idx].idx = 0;
/* If amsdu_8k is disabled, set buffersize to 4096. This
--
1.8.1.2.459.gbcd45b4.dirty
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH 00/22] Add and use pci_zalloc_consistent
2014-06-23 13:41 [PATCH 00/22] Add and use pci_zalloc_consistent Joe Perches
` (3 preceding siblings ...)
2014-06-23 13:41 ` [PATCH 18/22] rtlwifi: " Joe Perches
@ 2014-06-23 17:25 ` Luis R. Rodriguez
2014-06-23 19:13 ` Joe Perches
2014-06-23 21:49 ` David Miller
2014-06-25 19:41 ` John W. Linville
6 siblings, 1 reply; 11+ messages in thread
From: Luis R. Rodriguez @ 2014-06-23 17:25 UTC (permalink / raw)
To: Joe Perches
Cc: linux-kernel, devel, linux-arch, linux-scsi, iss_storagedev,
linux-rdma, netdev, linux-atm-general, linux-wireless, dri-devel,
linux-crypto, linux-eata, linux-media
On Mon, Jun 23, 2014 at 06:41:28AM -0700, Joe Perches wrote:
> Adding the helper reduces object code size as well as overall
> source size line count.
>
> It's also consistent with all the various zalloc mechanisms
> in the kernel.
>
> Done with a simple cocci script and some typing.
Awesome, any chance you can paste in the SmPL? Also any chance
we can get this added to a make coccicheck so that maintainers
moving forward can use that to ensure that no new code is
added that uses the old school API?
Luis
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH 00/22] Add and use pci_zalloc_consistent
2014-06-23 17:25 ` [PATCH 00/22] Add and use pci_zalloc_consistent Luis R. Rodriguez
@ 2014-06-23 19:13 ` Joe Perches
2014-06-23 23:27 ` Julian Calaby
0 siblings, 1 reply; 11+ messages in thread
From: Joe Perches @ 2014-06-23 19:13 UTC (permalink / raw)
To: Luis R. Rodriguez, Arnd Bergmann
Cc: linux-kernel, devel, linux-arch, linux-scsi, iss_storagedev,
linux-rdma, netdev, linux-atm-general, linux-wireless, dri-devel,
linux-crypto, linux-eata, linux-media
On Mon, 2014-06-23 at 10:25 -0700, Luis R. Rodriguez wrote:
> On Mon, Jun 23, 2014 at 06:41:28AM -0700, Joe Perches wrote:
> > Adding the helper reduces object code size as well as overall
> > source size line count.
> >
> > It's also consistent with all the various zalloc mechanisms
> > in the kernel.
> >
> > Done with a simple cocci script and some typing.
>
> Awesome, any chance you can paste in the SmPL? Also any chance
> we can get this added to a make coccicheck so that maintainers
> moving forward can use that to ensure that no new code is
> added that uses the old school API?
Not many of these are recent.
Arnd Bergmann reasonably suggested that the pci_alloc_consistent
api be converted the the more widely used dma_alloc_coherent.
https://lkml.org/lkml/2014/6/23/513
> Shouldn't these drivers just use the normal dma-mapping API now?
and I replied:
https://lkml.org/lkml/2014/6/23/525
> Maybe. I wouldn't mind.
> They do seem to have a trivial bit of unnecessary overhead for
> hwdev == NULL ? NULL : &hwdev->dev
Anyway, here's the little script.
I'm not sure it's worthwhile to add it though.
$ cat ./scripts/coccinelle/api/alloc/pci_zalloc_consistent.cocci
///
/// Use pci_zalloc_consistent rather than
/// pci_alloc_consistent followed by memset with 0
///
/// This considers some simple cases that are common and easy to validate
/// Note in particular that there are no ...s in the rule, so all of the
/// matched code has to be contiguous
///
/// Blatantly cribbed from: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
@@
type T, T2;
expression x;
expression E1,E2,E3;
statement S;
@@
- x = (T)pci_alloc_consistent(E1,E2,E3);
+ x = pci_zalloc_consistent(E1,E2,E3);
if ((x==NULL) || ...) S
- memset((T2)x,0,E2);
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 00/22] Add and use pci_zalloc_consistent
2014-06-23 19:13 ` Joe Perches
@ 2014-06-23 23:27 ` Julian Calaby
2014-06-24 11:32 ` Johannes Berg
0 siblings, 1 reply; 11+ messages in thread
From: Julian Calaby @ 2014-06-23 23:27 UTC (permalink / raw)
To: Joe Perches
Cc: Luis R. Rodriguez, Arnd Bergmann, linux-kernel@vger.kernel.org,
devel@driverdev.osuosl.org, linux-arch, linux-scsi,
iss_storagedev, linux-rdma, netdev, linux-atm-general,
linux-wireless, dri-devel, linux-crypto, linux-eata, linux-media
Hi Joe,
On Tue, Jun 24, 2014 at 5:13 AM, Joe Perches <joe@perches.com> wrote:
> On Mon, 2014-06-23 at 10:25 -0700, Luis R. Rodriguez wrote:
>> On Mon, Jun 23, 2014 at 06:41:28AM -0700, Joe Perches wrote:
>> > Adding the helper reduces object code size as well as overall
>> > source size line count.
>> >
>> > It's also consistent with all the various zalloc mechanisms
>> > in the kernel.
>> >
>> > Done with a simple cocci script and some typing.
>>
>> Awesome, any chance you can paste in the SmPL? Also any chance
>> we can get this added to a make coccicheck so that maintainers
>> moving forward can use that to ensure that no new code is
>> added that uses the old school API?
>
> Not many of these are recent.
>
> Arnd Bergmann reasonably suggested that the pci_alloc_consistent
> api be converted the the more widely used dma_alloc_coherent.
>
> https://lkml.org/lkml/2014/6/23/513
>
>> Shouldn't these drivers just use the normal dma-mapping API now?
>
> and I replied:
>
> https://lkml.org/lkml/2014/6/23/525
>
>> Maybe. I wouldn't mind.
>> They do seem to have a trivial bit of unnecessary overhead for
>> hwdev == NULL ? NULL : &hwdev->dev
>
> Anyway, here's the little script.
> I'm not sure it's worthwhile to add it though.
>
> $ cat ./scripts/coccinelle/api/alloc/pci_zalloc_consistent.cocci
> ///
> /// Use pci_zalloc_consistent rather than
> /// pci_alloc_consistent followed by memset with 0
> ///
> /// This considers some simple cases that are common and easy to validate
> /// Note in particular that there are no ...s in the rule, so all of the
> /// matched code has to be contiguous
> ///
> /// Blatantly cribbed from: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
>
> @@
> type T, T2;
> expression x;
> expression E1,E2,E3;
> statement S;
> @@
>
> - x = (T)pci_alloc_consistent(E1,E2,E3);
> + x = pci_zalloc_consistent(E1,E2,E3);
> if ((x==NULL) || ...) S
> - memset((T2)x,0,E2);
I don't know much about SmPL, but wouldn't having that if statement
there reduce your matches?
Thanks,
--
Julian Calaby
Email: julian.calaby@gmail.com
Profile: http://www.google.com/profiles/julian.calaby/
.Plan: http://sites.google.com/site/juliancalaby/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 00/22] Add and use pci_zalloc_consistent
2014-06-23 23:27 ` Julian Calaby
@ 2014-06-24 11:32 ` Johannes Berg
0 siblings, 0 replies; 11+ messages in thread
From: Johannes Berg @ 2014-06-24 11:32 UTC (permalink / raw)
To: Julian Calaby
Cc: Joe Perches, Luis R. Rodriguez, Arnd Bergmann,
linux-kernel@vger.kernel.org, devel@driverdev.osuosl.org,
linux-arch, linux-scsi, iss_storagedev, linux-rdma, netdev,
linux-atm-general, linux-wireless, dri-devel, linux-crypto,
linux-eata, linux-media
On Tue, 2014-06-24 at 09:27 +1000, Julian Calaby wrote:
> > - x = (T)pci_alloc_consistent(E1,E2,E3);
> > + x = pci_zalloc_consistent(E1,E2,E3);
> > if ((x==NULL) || ...) S
> > - memset((T2)x,0,E2);
>
> I don't know much about SmPL, but wouldn't having that if statement
> there reduce your matches?
Code that matched without the if statement would be buggy, since it
wouldn't be checking the pci_zalloc_consistent return value properly.l
johannes
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 00/22] Add and use pci_zalloc_consistent
2014-06-23 13:41 [PATCH 00/22] Add and use pci_zalloc_consistent Joe Perches
` (4 preceding siblings ...)
2014-06-23 17:25 ` [PATCH 00/22] Add and use pci_zalloc_consistent Luis R. Rodriguez
@ 2014-06-23 21:49 ` David Miller
2014-06-25 19:41 ` John W. Linville
6 siblings, 0 replies; 11+ messages in thread
From: David Miller @ 2014-06-23 21:49 UTC (permalink / raw)
To: joe
Cc: linux-kernel, linux-atm-general, netdev, iss_storagedev,
linux-crypto, dri-devel, linux-rdma, linux-media, linux-wireless,
linux-scsi, linux-eata, devel, linux-arch
From: Joe Perches <joe@perches.com>
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@davemloft.net>
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH 00/22] Add and use pci_zalloc_consistent
2014-06-23 13:41 [PATCH 00/22] Add and use pci_zalloc_consistent Joe Perches
` (5 preceding siblings ...)
2014-06-23 21:49 ` David Miller
@ 2014-06-25 19:41 ` John W. Linville
6 siblings, 0 replies; 11+ messages in thread
From: John W. Linville @ 2014-06-25 19:41 UTC (permalink / raw)
To: Joe Perches
Cc: linux-kernel, linux-atm-general, netdev, iss_storagedev,
linux-crypto, dri-devel, linux-rdma, linux-media, linux-wireless,
linux-scsi, linux-eata, devel, linux-arch
On Mon, Jun 23, 2014 at 06:41:28AM -0700, Joe Perches wrote:
> Adding the helper reduces object code size as well as overall
> source size line count.
>
> It's also consistent with all the various zalloc mechanisms
> in the kernel.
>
> Done with a simple cocci script and some typing.
>
> Joe Perches (22):
> ipw2100: Use pci_zalloc_consistent
> mwl8k: Use pci_zalloc_consistent
> rtl818x: Use pci_zalloc_consistent
> rtlwifi: Use pci_zalloc_consistent
Sure, fine by me.
--
John W. Linville Someday the world will need a hero, and you
linville@tuxdriver.com might be all we have. Be ready.
^ permalink raw reply [flat|nested] 11+ messages in thread