Skip to contentSkip to conversation

wifi: wcn36xx: allocate chan_surveys with main struct

PATCH Applied Rosen Penev 3 participants 3 messages May 19 – Jun 6 Qualcomm WCN36XX wireless driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wifi: wcn36xx: allocate chan_surveys with main struct

Avoid allocating separately with a flexible array member. Simplifies allocation slightly.

---
 drivers/net/wireless/ath/wcn36xx/main.c    | 13 ++-----------
 drivers/net/wireless/ath/wcn36xx/wcn36xx.h |  2 +-
 2 files changed, 3 insertions(+), 12 deletions(-)
drivers/net/wireless/ath/wcn36xx/main.c +2 -11
index c3f0860873de..ad8a4bd910d2 100644
@@ -1568,7 +1568,8 @@ static int wcn36xx_probe(struct platform_device *pdev)
 
 	wcnss = dev_get_drvdata(pdev->dev.parent);
 
-	hw = ieee80211_alloc_hw(sizeof(struct wcn36xx), &wcn36xx_ops);
+	n_channels = wcn_band_2ghz.n_channels + wcn_band_5ghz.n_channels;
+	hw = ieee80211_alloc_hw(struct_size(wcn, chan_survey, n_channels), &wcn36xx_ops);
 	if (!hw) {
 		wcn36xx_err("failed to alloc hw\n");
 		ret = -ENOMEM;
@@ -1590,16 +1591,6 @@ static int wcn36xx_probe(struct platform_device *pdev)
 		goto out_wq;
 	}
 
-	n_channels = wcn_band_2ghz.n_channels + wcn_band_5ghz.n_channels;
-	wcn->chan_survey = devm_kcalloc(wcn->dev,
-					n_channels,
-					sizeof(struct wcn36xx_chan_survey),
-					GFP_KERNEL);
-	if (!wcn->chan_survey) {
-		ret = -ENOMEM;
-		goto out_wq;
-	}
-
 	ret = dma_set_mask_and_coherent(wcn->dev, DMA_BIT_MASK(32));
 	if (ret < 0) {
 		wcn36xx_err("failed to set DMA mask: %d\n", ret);
drivers/net/wireless/ath/wcn36xx/wcn36xx.h +1 -1
index 7ee79593cd23..8c43f67bd780 100644
@@ -298,7 +298,7 @@ struct wcn36xx {
 	struct ieee80211_channel *channel;
 
 	spinlock_t survey_lock;		/* protects chan_survey */
-	struct wcn36xx_chan_survey	*chan_survey;
+	struct wcn36xx_chan_survey	chan_survey[];
 };
 
 static inline bool wcn36xx_is_fw_version(struct wcn36xx *wcn,

--
2.54.0

maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Rosen Penev

Avoid allocating separately with a flexible array member. Simplifies allocation slightly.

Quoted 52 lines
---
 drivers/net/wireless/ath/wcn36xx/main.c    | 13 ++-----------
 drivers/net/wireless/ath/wcn36xx/wcn36xx.h |  2 +-
 2 files changed, 3 insertions(+), 12 deletions(-)
drivers/net/wireless/ath/wcn36xx/main.c +2 -11
index c3f0860873de..ad8a4bd910d2 100644
@@ -1568,7 +1568,8 @@ static int wcn36xx_probe(struct platform_device *pdev)
 
        wcnss = dev_get_drvdata(pdev->dev.parent);
 
-       hw = ieee80211_alloc_hw(sizeof(struct wcn36xx), &wcn36xx_ops);
+       n_channels = wcn_band_2ghz.n_channels + wcn_band_5ghz.n_channels;
+       hw = ieee80211_alloc_hw(struct_size(wcn, chan_survey, n_channels), &wcn36xx_ops);
        if (!hw) {
                wcn36xx_err("failed to alloc hw\n");
                ret = -ENOMEM;
@@ -1590,16 +1591,6 @@ static int wcn36xx_probe(struct platform_device *pdev)
                goto out_wq;
        }
 
-       n_channels = wcn_band_2ghz.n_channels + wcn_band_5ghz.n_channels;
-       wcn->chan_survey = devm_kcalloc(wcn->dev,
-                                       n_channels,
-                                       sizeof(struct wcn36xx_chan_survey),
-                                       GFP_KERNEL);
-       if (!wcn->chan_survey) {
-               ret = -ENOMEM;
-               goto out_wq;
-       }
-
        ret = dma_set_mask_and_coherent(wcn->dev, DMA_BIT_MASK(32));
        if (ret < 0) {
                wcn36xx_err("failed to set DMA mask: %d\n", ret);
drivers/net/wireless/ath/wcn36xx/wcn36xx.h +1 -2
index 7ee79593cd23..8c43f67bd780 100644
@@ -298,7 +298,7 @@ struct wcn36xx {
        struct ieee80211_channel *channel;
 
        spinlock_t survey_lock;         /* protects chan_survey */
-       struct wcn36xx_chan_survey      *chan_survey;
+       struct wcn36xx_chan_survey      chan_survey[];
 };
 
 static inline bool wcn36xx_is_fw_version(struct wcn36xx *wcn,
--

2.54.0

Applied
#2 lore raw
In reply to Rosen Penev
Quoted 4 lines · Rosen Penev

Avoid allocating separately with a flexible array member. Simplifies allocation slightly.

Applied, thanks!

[1/1] wifi: wcn36xx: allocate chan_surveys with main struct

      commit: 0bd50e363581a9f833c051f7543ffd1fd3455509

Best regards,

Signature · 1 line
Jeff Johnson <[email protected]>