* [PATCH ath-next] wifi: ath9k: use kmemdup and kcalloc
@ 2026-02-23 22:44 Rosen Penev
2026-04-16 19:21 ` Toke Høiland-Jørgensen
2026-04-16 23:09 ` Jeff Johnson
0 siblings, 2 replies; 4+ messages in thread
From: Rosen Penev @ 2026-02-23 22:44 UTC (permalink / raw)
To: linux-wireless; +Cc: Toke Høiland-Jørgensen, open list
Simplifies the code slightly by removing temporary variables.
multiplication overflow is also gained for free.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/net/wireless/ath/ath9k/ar9002_hw.c | 6 +++---
drivers/net/wireless/ath/ath9k/common-init.c | 8 ++------
drivers/net/wireless/ath/ath9k/init.c | 8 +++-----
drivers/net/wireless/ath/ath9k/recv.c | 4 +---
4 files changed, 9 insertions(+), 17 deletions(-)
diff --git a/drivers/net/wireless/ath/ath9k/ar9002_hw.c b/drivers/net/wireless/ath/ath9k/ar9002_hw.c
index b26224480041..0f24539b75ec 100644
--- a/drivers/net/wireless/ath/ath9k/ar9002_hw.c
+++ b/drivers/net/wireless/ath/ath9k/ar9002_hw.c
@@ -80,14 +80,14 @@ static int ar9002_hw_init_mode_regs(struct ath_hw *ah)
/* iniAddac needs to be modified for these chips */
if (AR_SREV_9160(ah) || !AR_SREV_5416_22_OR_LATER(ah)) {
struct ar5416IniArray *addac = &ah->iniAddac;
- u32 size = sizeof(u32) * addac->ia_rows * addac->ia_columns;
+ u32 n = addac->ia_rows * addac->ia_columns;
u32 *data;
- data = devm_kzalloc(ah->dev, size, GFP_KERNEL);
+ data = devm_kmemdup_array(ah->dev, addac->ia_array, n, sizeof(u32),
+ GFP_KERNEL);
if (!data)
return -ENOMEM;
- memcpy(data, addac->ia_array, size);
addac->ia_array = data;
if (!AR_SREV_5416_22_OR_LATER(ah)) {
diff --git a/drivers/net/wireless/ath/ath9k/common-init.c b/drivers/net/wireless/ath/ath9k/common-init.c
index da102c791712..52e02e0752d8 100644
--- a/drivers/net/wireless/ath/ath9k/common-init.c
+++ b/drivers/net/wireless/ath/ath9k/common-init.c
@@ -133,13 +133,11 @@ int ath9k_cmn_init_channels_rates(struct ath_common *common)
ATH9K_NUM_CHANNELS);
if (ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ) {
- channels = devm_kzalloc(ah->dev,
+ channels = devm_kmemdup(ah->dev, ath9k_2ghz_chantable,
sizeof(ath9k_2ghz_chantable), GFP_KERNEL);
if (!channels)
return -ENOMEM;
- memcpy(channels, ath9k_2ghz_chantable,
- sizeof(ath9k_2ghz_chantable));
common->sbands[NL80211_BAND_2GHZ].channels = channels;
common->sbands[NL80211_BAND_2GHZ].band = NL80211_BAND_2GHZ;
common->sbands[NL80211_BAND_2GHZ].n_channels =
@@ -150,13 +148,11 @@ int ath9k_cmn_init_channels_rates(struct ath_common *common)
}
if (ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ) {
- channels = devm_kzalloc(ah->dev,
+ channels = devm_kmemdup(ah->dev, ath9k_5ghz_chantable,
sizeof(ath9k_5ghz_chantable), GFP_KERNEL);
if (!channels)
return -ENOMEM;
- memcpy(channels, ath9k_5ghz_chantable,
- sizeof(ath9k_5ghz_chantable));
common->sbands[NL80211_BAND_5GHZ].channels = channels;
common->sbands[NL80211_BAND_5GHZ].band = NL80211_BAND_5GHZ;
common->sbands[NL80211_BAND_5GHZ].n_channels =
diff --git a/drivers/net/wireless/ath/ath9k/init.c b/drivers/net/wireless/ath/ath9k/init.c
index b52ddb237dcf..e52775dda6a7 100644
--- a/drivers/net/wireless/ath/ath9k/init.c
+++ b/drivers/net/wireless/ath/ath9k/init.c
@@ -297,7 +297,7 @@ int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
{
struct ath_common *common = ath9k_hw_common(sc->sc_ah);
u8 *ds;
- int i, bsize, desc_len;
+ int i, desc_len;
ath_dbg(common, CONFIG, "%s DMA: %u buffers %u desc/buf\n",
name, nbuf, ndesc);
@@ -351,8 +351,7 @@ int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
if (is_tx) {
struct ath_buf *bf;
- bsize = sizeof(struct ath_buf) * nbuf;
- bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL);
+ bf = devm_kcalloc(sc->dev, sizeof(*bf), nbuf, GFP_KERNEL);
if (!bf)
return -ENOMEM;
@@ -382,8 +381,7 @@ int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
} else {
struct ath_rxbuf *bf;
- bsize = sizeof(struct ath_rxbuf) * nbuf;
- bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL);
+ bf = devm_kcalloc(sc->dev, sizeof(struct ath_rxbuf), nbuf, GFP_KERNEL);
if (!bf)
return -ENOMEM;
diff --git a/drivers/net/wireless/ath/ath9k/recv.c b/drivers/net/wireless/ath/ath9k/recv.c
index 34c74ed99b7b..93b41a1bb2af 100644
--- a/drivers/net/wireless/ath/ath9k/recv.c
+++ b/drivers/net/wireless/ath/ath9k/recv.c
@@ -202,7 +202,6 @@ static int ath_rx_edma_init(struct ath_softc *sc, int nbufs)
struct sk_buff *skb;
struct ath_rxbuf *bf;
int error = 0, i;
- u32 size;
ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
ah->caps.rx_status_len);
@@ -212,8 +211,7 @@ static int ath_rx_edma_init(struct ath_softc *sc, int nbufs)
ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_HP],
ah->caps.rx_hp_qdepth);
- size = sizeof(struct ath_rxbuf) * nbufs;
- bf = devm_kzalloc(sc->dev, size, GFP_KERNEL);
+ bf = devm_kcalloc(sc->dev, sizeof(struct ath_rxbuf), nbufs, GFP_KERNEL);
if (!bf)
return -ENOMEM;
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH ath-next] wifi: ath9k: use kmemdup and kcalloc
2026-02-23 22:44 [PATCH ath-next] wifi: ath9k: use kmemdup and kcalloc Rosen Penev
@ 2026-04-16 19:21 ` Toke Høiland-Jørgensen
2026-04-16 23:09 ` Jeff Johnson
1 sibling, 0 replies; 4+ messages in thread
From: Toke Høiland-Jørgensen @ 2026-04-16 19:21 UTC (permalink / raw)
To: Rosen Penev, linux-wireless; +Cc: open list
Rosen Penev <rosenp@gmail.com> writes:
> Simplifies the code slightly by removing temporary variables.
> multiplication overflow is also gained for free.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Toke Høiland-Jørgensen <toke@toke.dk>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH ath-next] wifi: ath9k: use kmemdup and kcalloc
2026-02-23 22:44 [PATCH ath-next] wifi: ath9k: use kmemdup and kcalloc Rosen Penev
2026-04-16 19:21 ` Toke Høiland-Jørgensen
@ 2026-04-16 23:09 ` Jeff Johnson
2026-04-16 23:42 ` Rosen Penev
1 sibling, 1 reply; 4+ messages in thread
From: Jeff Johnson @ 2026-04-16 23:09 UTC (permalink / raw)
To: Rosen Penev, linux-wireless; +Cc: Toke Høiland-Jørgensen, open list
On 2/23/2026 2:44 PM, Rosen Penev wrote:
> Simplifies the code slightly by removing temporary variables.
> multiplication overflow is also gained for free.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
> drivers/net/wireless/ath/ath9k/ar9002_hw.c | 6 +++---
> drivers/net/wireless/ath/ath9k/common-init.c | 8 ++------
> drivers/net/wireless/ath/ath9k/init.c | 8 +++-----
> drivers/net/wireless/ath/ath9k/recv.c | 4 +---
> 4 files changed, 9 insertions(+), 17 deletions(-)
>
...
> diff --git a/drivers/net/wireless/ath/ath9k/init.c b/drivers/net/wireless/ath/ath9k/init.c
> index b52ddb237dcf..e52775dda6a7 100644
> --- a/drivers/net/wireless/ath/ath9k/init.c
> +++ b/drivers/net/wireless/ath/ath9k/init.c
> @@ -297,7 +297,7 @@ int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
> {
> struct ath_common *common = ath9k_hw_common(sc->sc_ah);
> u8 *ds;
> - int i, bsize, desc_len;
> + int i, desc_len;
>
> ath_dbg(common, CONFIG, "%s DMA: %u buffers %u desc/buf\n",
> name, nbuf, ndesc);
> @@ -351,8 +351,7 @@ int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
> if (is_tx) {
> struct ath_buf *bf;
>
> - bsize = sizeof(struct ath_buf) * nbuf;
> - bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL);
> + bf = devm_kcalloc(sc->dev, sizeof(*bf), nbuf, GFP_KERNEL);
> if (!bf)
> return -ENOMEM;
>
> @@ -382,8 +381,7 @@ int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
> } else {
> struct ath_rxbuf *bf;
>
> - bsize = sizeof(struct ath_rxbuf) * nbuf;
> - bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL);
> + bf = devm_kcalloc(sc->dev, sizeof(struct ath_rxbuf), nbuf, GFP_KERNEL);
use sizeof(*bf) here as well?
If so, I can fix this in my pending branch
> if (!bf)
> return -ENOMEM;
>
> diff --git a/drivers/net/wireless/ath/ath9k/recv.c b/drivers/net/wireless/ath/ath9k/recv.c
> index 34c74ed99b7b..93b41a1bb2af 100644
> --- a/drivers/net/wireless/ath/ath9k/recv.c
> +++ b/drivers/net/wireless/ath/ath9k/recv.c
> @@ -202,7 +202,6 @@ static int ath_rx_edma_init(struct ath_softc *sc, int nbufs)
> struct sk_buff *skb;
> struct ath_rxbuf *bf;
> int error = 0, i;
> - u32 size;
>
> ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
> ah->caps.rx_status_len);
> @@ -212,8 +211,7 @@ static int ath_rx_edma_init(struct ath_softc *sc, int nbufs)
> ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_HP],
> ah->caps.rx_hp_qdepth);
>
> - size = sizeof(struct ath_rxbuf) * nbufs;
> - bf = devm_kzalloc(sc->dev, size, GFP_KERNEL);
> + bf = devm_kcalloc(sc->dev, sizeof(struct ath_rxbuf), nbufs, GFP_KERNEL);
here as well?
> if (!bf)
> return -ENOMEM;
>
> --
> 2.53.0
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH ath-next] wifi: ath9k: use kmemdup and kcalloc
2026-04-16 23:09 ` Jeff Johnson
@ 2026-04-16 23:42 ` Rosen Penev
0 siblings, 0 replies; 4+ messages in thread
From: Rosen Penev @ 2026-04-16 23:42 UTC (permalink / raw)
To: Jeff Johnson; +Cc: linux-wireless, Toke Høiland-Jørgensen, open list
On Thu, Apr 16, 2026 at 4:09 PM Jeff Johnson
<jeff.johnson@oss.qualcomm.com> wrote:
>
> On 2/23/2026 2:44 PM, Rosen Penev wrote:
> > Simplifies the code slightly by removing temporary variables.
> > multiplication overflow is also gained for free.
> >
> > Signed-off-by: Rosen Penev <rosenp@gmail.com>
> > ---
> > drivers/net/wireless/ath/ath9k/ar9002_hw.c | 6 +++---
> > drivers/net/wireless/ath/ath9k/common-init.c | 8 ++------
> > drivers/net/wireless/ath/ath9k/init.c | 8 +++-----
> > drivers/net/wireless/ath/ath9k/recv.c | 4 +---
> > 4 files changed, 9 insertions(+), 17 deletions(-)
> >
> ...
> > diff --git a/drivers/net/wireless/ath/ath9k/init.c b/drivers/net/wireless/ath/ath9k/init.c
> > index b52ddb237dcf..e52775dda6a7 100644
> > --- a/drivers/net/wireless/ath/ath9k/init.c
> > +++ b/drivers/net/wireless/ath/ath9k/init.c
> > @@ -297,7 +297,7 @@ int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
> > {
> > struct ath_common *common = ath9k_hw_common(sc->sc_ah);
> > u8 *ds;
> > - int i, bsize, desc_len;
> > + int i, desc_len;
> >
> > ath_dbg(common, CONFIG, "%s DMA: %u buffers %u desc/buf\n",
> > name, nbuf, ndesc);
> > @@ -351,8 +351,7 @@ int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
> > if (is_tx) {
> > struct ath_buf *bf;
> >
> > - bsize = sizeof(struct ath_buf) * nbuf;
> > - bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL);
> > + bf = devm_kcalloc(sc->dev, sizeof(*bf), nbuf, GFP_KERNEL);
> > if (!bf)
> > return -ENOMEM;
> >
> > @@ -382,8 +381,7 @@ int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
> > } else {
> > struct ath_rxbuf *bf;
> >
> > - bsize = sizeof(struct ath_rxbuf) * nbuf;
> > - bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL);
> > + bf = devm_kcalloc(sc->dev, sizeof(struct ath_rxbuf), nbuf, GFP_KERNEL);
>
> use sizeof(*bf) here as well?
> If so, I can fix this in my pending branch
Sure
>
> > if (!bf)
> > return -ENOMEM;
> >
> > diff --git a/drivers/net/wireless/ath/ath9k/recv.c b/drivers/net/wireless/ath/ath9k/recv.c
> > index 34c74ed99b7b..93b41a1bb2af 100644
> > --- a/drivers/net/wireless/ath/ath9k/recv.c
> > +++ b/drivers/net/wireless/ath/ath9k/recv.c
> > @@ -202,7 +202,6 @@ static int ath_rx_edma_init(struct ath_softc *sc, int nbufs)
> > struct sk_buff *skb;
> > struct ath_rxbuf *bf;
> > int error = 0, i;
> > - u32 size;
> >
> > ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
> > ah->caps.rx_status_len);
> > @@ -212,8 +211,7 @@ static int ath_rx_edma_init(struct ath_softc *sc, int nbufs)
> > ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_HP],
> > ah->caps.rx_hp_qdepth);
> >
> > - size = sizeof(struct ath_rxbuf) * nbufs;
> > - bf = devm_kzalloc(sc->dev, size, GFP_KERNEL);
> > + bf = devm_kcalloc(sc->dev, sizeof(struct ath_rxbuf), nbufs, GFP_KERNEL);
>
> here as well?
Sure
>
> > if (!bf)
> > return -ENOMEM;
> >
> > --
> > 2.53.0
> >
> >
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-04-16 23:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-23 22:44 [PATCH ath-next] wifi: ath9k: use kmemdup and kcalloc Rosen Penev
2026-04-16 19:21 ` Toke Høiland-Jørgensen
2026-04-16 23:09 ` Jeff Johnson
2026-04-16 23:42 ` Rosen Penev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox