]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
wifi: ath9k: use kmemdup and kcalloc
authorRosen Penev <rosenp@gmail.com>
Mon, 23 Feb 2026 22:44:45 +0000 (14:44 -0800)
committerJeff Johnson <jeff.johnson@oss.qualcomm.com>
Thu, 30 Apr 2026 21:24:06 +0000 (14:24 -0700)
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>
Link: https://patch.msgid.link/20260223224445.27352-1-rosenp@gmail.com
Signed-off-by: Jeff Johnson <jeff.johnson@oss.qualcomm.com>
drivers/net/wireless/ath/ath9k/ar9002_hw.c
drivers/net/wireless/ath/ath9k/common-init.c
drivers/net/wireless/ath/ath9k/init.c
drivers/net/wireless/ath/ath9k/recv.c

index b262244800410c2ce17a32f208c5fe329ed705dc..0f24539b75eccf69f9e8ab65075b86b3d498ea93 100644 (file)
@@ -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)) {
index da102c791712e7f2eaac06d0d91b9ade08faf8f9..52e02e0752d8d55575863d56ee72b81b967ff6f2 100644 (file)
@@ -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 =
index ebd46307938838909ee03d040a95b76a89c3cb05..e1a67e8ed09fe747738b80ca15df754e631f1ddd 100644 (file)
@@ -285,7 +285,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);
@@ -339,8 +339,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;
 
@@ -370,8 +369,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;
 
index 34c74ed99b7b56df524632cdf54ca4457187ae33..93b41a1bb2af062b8efde93fe0dbfac69a4acc0d 100644 (file)
@@ -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;