wifi: ath9k: use kmemdup and kcalloc
PATCH 1/1 wifi: ath9k: use kmemdup and kcalloc
Simplifies the code slightly by removing temporary variables. multiplication overflow is also gained for free.
--- 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(-)
drivers/net/wireless/ath/ath9k/ar9002_hw.c +3 -3
@@ -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)) {
drivers/net/wireless/ath/ath9k/common-init.c +2 -6
@@ -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 =
drivers/net/wireless/ath/ath9k/init.c +3 -5
@@ -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 ;
drivers/net/wireless/ath/ath9k/recv.c +1 -3
@@ -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
Quoted 4 lines · Rosen Penev
Simplifies the code slightly by removing temporary variables. multiplication overflow is also gained for free.
Signed-off-by Rosen Penev <[email protected]>
Quoted 11 lines · Rosen Penev
Simplifies the code slightly by removing temporary variables. multiplication overflow is also gained for free.
Signed-off-by Rosen Penev <[email protected]>--- 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(-)
...
Quoted 24 lines
drivers/net/wireless/ath/ath9k/init.c +2
-3@@ -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 ;
drivers/net/wireless/ath/ath9k/init.c int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd, · line 384
Quoted 6 lines
drivers/net/wireless/ath/ath9k/init.c +1
-2@@ -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
Quoted 16 lines
drivers/net/wireless/ath/ath9k/init.c +0
-0if (!bf)return -ENOMEM ;drivers/net/wireless/ath/ath9k/recv.c +0
-1@@ -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);
drivers/net/wireless/ath/ath9k/recv.c static int ath_rx_edma_init(struct ath_softc *sc, int nbufs) · line 214
Quoted 6 lines
drivers/net/wireless/ath/ath9k/recv.c +1
-2@@ -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?
Quoted 7 lines
drivers/net/wireless/ath/ath9k/recv.c +0
-1if (!bf)return -ENOMEM ; --2.53.0
Quoted 41 lines · Jeff Johnson
Quoted 11 lines · Rosen Penev
Simplifies the code slightly by removing temporary variables. multiplication overflow is also gained for free.
Signed-off-by Rosen Penev <[email protected]>--- 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(-)...
Quoted 27 lines
drivers/net/wireless/ath/ath9k/init.c +2
-3@@ -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;
Quoted 6 lines
drivers/net/wireless/ath/ath9k/init.c int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd, · line 384
Quoted 3 lines
drivers/net/wireless/ath/ath9k/init.c +1
-2- 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
Quoted 20 lines
Quoted 20 lines
drivers/net/wireless/ath/ath9k/init.c +0
-0if (!bf)return -ENOMEM ;drivers/net/wireless/ath/ath9k/recv.c +0
-1@@ -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);
Quoted 5 lines
drivers/net/wireless/ath/ath9k/recv.c static int ath_rx_edma_init(struct ath_softc *sc, int nbufs) · line 214
Quoted 3 lines
drivers/net/wireless/ath/ath9k/recv.c +1
-2- 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
Quoted 9 lines
Quoted 8 lines
drivers/net/wireless/ath/ath9k/recv.c +0
-1if (!bf)return -ENOMEM ; --2.53.0
Quoted 70 lines · Rosen Penev
Quoted 41 lines · Jeff Johnson
Quoted 11 lines · Rosen Penev
Simplifies the code slightly by removing temporary variables. multiplication overflow is also gained for free.
Signed-off-by Rosen Penev <[email protected]>--- 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(-)...
Quoted 27 lines
drivers/net/wireless/ath/ath9k/init.c +2
-3@@ -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;Quoted 6 lines
drivers/net/wireless/ath/ath9k/init.c int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd, · line 384
Quoted 3 lines
drivers/net/wireless/ath/ath9k/init.c +1
-2- 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 branchSure
Quoted 20 lines
Quoted 20 lines
drivers/net/wireless/ath/ath9k/init.c +0
-0if (!bf)return -ENOMEM ;drivers/net/wireless/ath/ath9k/recv.c +0
-1@@ -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);
Quoted 15 lines
Quoted 5 lines
drivers/net/wireless/ath/ath9k/recv.c static int ath_rx_edma_init(struct ath_softc *sc, int nbufs) · line 214
Quoted 3 lines
drivers/net/wireless/ath/ath9k/recv.c +1
-2- 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
Quoted 9 lines
Quoted 8 lines
drivers/net/wireless/ath/ath9k/recv.c +0
-1if (!bf)return -ENOMEM ; --2.53.0
FYI I'm going to take your patch as-is since there are other instances of ath9k using sizeof(type). These can be cleaned up separately.
/jeff
Jeff Johnson
AppliedQuoted 4 lines · Rosen Penev
Simplifies the code slightly by removing temporary variables. multiplication overflow is also gained for free.
Applied, thanks!
[1/1] wifi: ath9k: use kmemdup and kcalloc
commit: 3042a9d403b9ead7c35b55e697eeae7974e04653
Best regards,
Signature · 1 line
Jeff Johnson <[email protected]>