wfx: use container_of() to get vif
PATCH 1/1 wfx: use container_of() to get vif
Currently, upon virtual interface creation, wfx_add_interface() stores a reference to the corresponding struct ieee80211_vif in private data, for later usage. This is not needed when using the container_of construct. This construct already has all the info it needs to retrieve the reference to the corresponding struct from the offset that is already available, inherent in container_of(), between its type and member inputs (struct ieee80211_vif and drv_priv, respectively). Remove vif (which was previously storing the reference to the struct ieee80211_vif) from the struct wfx_vif, define a function wvif_to_vif(wvif) for container_of(), and replace all wvif->vif with the newly defined container_of construct.
---
Changes from staging to wireless-next tree
- changed macro into function and named it back to wvif_to_vif
- fit all lines in patch to 80 columns
- decared a reference to vif at the beginning of the functions
NOTE: Jérôme is going to be testing this patch on his hardware
drivers/net/wireless/silabs/wfx/wfx.h | 6 +- drivers/net/wireless/silabs/wfx/data_rx.c | 5 +- drivers/net/wireless/silabs/wfx/data_tx.c | 3 +- drivers/net/wireless/silabs/wfx/key.c | 4 +- drivers/net/wireless/silabs/wfx/queue.c | 3 +- drivers/net/wireless/silabs/wfx/scan.c | 9 ++- drivers/net/wireless/silabs/wfx/sta.c | 69 ++++++++++++++--------- 7 files changed, 63 insertions(+), 36 deletions(-)
drivers/net/wireless/silabs/wfx/wfx.h +5 -1
@@ -61,7 +61,6 @@ struct wfx_dev {struct wfx_vif {struct wfx_dev *wdev; -struct ieee80211_vif *vif;struct ieee80211_channel *channel;int id;
@@ -91,6 +90,11 @@ struct wfx_vif {struct completion set_pm_mode_complete; }; +static inline struct ieee80211_vif *wvif_to_vif (struct wfx_vif *wvif) +{ + return container_of((void *)wvif, struct ieee80211_vif, drv_priv); +} +static inline struct wfx_vif *wdev_to_wvif (struct wfx_dev *wdev,int vif_id) {if (vif_id >=ARRAY_SIZE (wdev->vif)) {
drivers/net/wireless/silabs/wfx/data_rx.c +3 -2
@@ -16,6 +16,7 @@static void wfx_rx_handle_ba (struct wfx_vif *wvif,struct ieee80211_mgmt *mgmt) {int params, tid; +struct ieee80211_vif *vif =wvif_to_vif (wvif);if (wfx_api_older_than (wvif->wdev,3 ,6 ))return ;
@@ -24,12 +25,12 @@ static void wfx_rx_handle_ba(struct wfx_vif *wvif, struct ieee80211_mgmt *mgmt)case WLAN_ACTION_ADDBA_REQ : params =le16_to_cpu (mgmt->u.action.u.addba_req.capab); tid = (params &IEEE80211_ADDBA_PARAM_TID_MASK ) >>2 ; -ieee80211_start_rx_ba_session_offl (wvif->vif, mgmt->sa, tid); +ieee80211_start_rx_ba_session_offl (vif, mgmt->sa, tid);break ;case WLAN_ACTION_DELBA : params =le16_to_cpu (mgmt->u.action.u.delba.params); tid = (params &IEEE80211_DELBA_PARAM_TID_MASK ) >>12 ; -ieee80211_stop_rx_ba_session_offl (wvif->vif, mgmt->sa, tid); +ieee80211_stop_rx_ba_session_offl (vif, mgmt->sa, tid);break ; } }
drivers/net/wireless/silabs/wfx/data_tx.c +2 -1
@@ -213,10 +213,11 @@ static u8 wfx_tx_get_link_id(struct wfx_vif *wvif, struct ieee80211_sta *sta, {struct wfx_sta_priv *sta_priv = sta ? (struct wfx_sta_priv *)&sta->drv_priv :NULL ;const u8 *da =ieee80211_get_DA (hdr); +struct ieee80211_vif *vif =wvif_to_vif (wvif);if (sta_priv && sta_priv->link_id)return sta_priv->link_id; -if (wvif->vif->type !=NL80211_IFTYPE_AP ) +if (vif->type !=NL80211_IFTYPE_AP )return 0 ;if (is_multicast_ether_addr (da))return 0 ;
drivers/net/wireless/silabs/wfx/key.c +2 -2
@@ -156,6 +156,7 @@ static int wfx_add_key(struct wfx_vif *wvif, struct ieee80211_sta *sta,struct wfx_dev *wdev = wvif->wdev;int idx =wfx_alloc_key (wvif->wdev);bool pairwise = key->flags &IEEE80211_KEY_FLAG_PAIRWISE ; +struct ieee80211_vif *vif =wvif_to_vif (wvif);WARN (key->flags &IEEE80211_KEY_FLAG_PAIRWISE && !sta,"inconsistent data" );ieee80211_get_key_rx_seq (key,0 , &seq);
@@ -174,7 +175,7 @@ static int wfx_add_key(struct wfx_vif *wvif, struct ieee80211_sta *sta, k.type =fill_tkip_pair (&k.key.tkip_pairwise_key, key, sta->addr); else k.type = fill_tkip_group(&k.key.tkip_group_key, key, &seq, - wvif->vif->type); + vif->type); }else if (key->cipher ==WLAN_CIPHER_SUITE_CCMP ) {if (pairwise) k.type =fill_ccmp_pair (&k.key.aes_pairwise_key, key, sta->addr);
@@ -224,4 +225,3 @@ int wfx_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, struct ieee80211_mutex_unlock (&wvif->wdev->conf_mutex);return ret; } -
drivers/net/wireless/silabs/wfx/queue.c +2 -1
@@ -206,8 +206,9 @@ unsigned int wfx_pending_get_pkt_us_delay(struct wfx_dev *wdev, struct sk_buff *bool wfx_tx_queues_has_cab (struct wfx_vif *wvif) {int i; +struct ieee80211_vif *vif =wvif_to_vif (wvif); -if (wvif->vif->type !=NL80211_IFTYPE_AP ) +if (vif->type !=NL80211_IFTYPE_AP )return false;for (i =0 ; i <IEEE80211_NUM_ACS ; ++i)/* Note: since only AP can have mcast frames in queue and only one vif can be AP,
drivers/net/wireless/silabs/wfx/scan.c +6 -3
@@ -24,8 +24,10 @@ static void wfx_ieee80211_scan_completed_compat(struct ieee80211_hw *hw, bool abstatic int update_probe_tmpl (struct wfx_vif *wvif,struct cfg80211_scan_request *req) {struct sk_buff *skb; +struct ieee80211_vif *vif =wvif_to_vif (wvif); - skb =ieee80211_probereq_get (wvif->wdev->hw, wvif->vif->addr,NULL ,0 , req->ie_len); + skb =ieee80211_probereq_get (wvif->wdev->hw, vif->addr,NULL ,0 , + req->ie_len);if (!skb)return -ENOMEM ;
@@ -39,6 +41,7 @@ static int send_scan_req(struct wfx_vif *wvif, struct cfg80211_scan_request *req {int i, ret;struct ieee80211_channel *ch_start, *ch_cur; +struct ieee80211_vif *vif =wvif_to_vif (wvif);for (i = start_idx; i < req->n_channels; i++) { ch_start = req->channels[start_idx];
@@ -75,8 +78,8 @@ static int send_scan_req(struct wfx_vif *wvif, struct cfg80211_scan_request *req }else { ret = wvif->scan_nb_chan_done; } -if (req->channels[start_idx]->max_power != wvif->vif->bss_conf.txpower) -wfx_hif_set_output_power (wvif, wvif->vif->bss_conf.txpower); +if (req->channels[start_idx]->max_power != vif->bss_conf.txpower) +wfx_hif_set_output_power (wvif, vif->bss_conf.txpower);wfx_tx_unlock (wvif->wdev);return ret; }
drivers/net/wireless/silabs/wfx/sta.c +43 -26
188 lines not on this page · raw message
Signature · 1 line
2.25.1
Jérôme Pouiller
maintainerQuoted 14 lines · On Monday 18 April 2022 05:51:10 CEST Jaehee Park wrote:
Currently, upon virtual interface creation,
wfx_add_interface()stores a reference to the corresponding structieee80211_vifin private data, for later usage. This is not needed when using thecontainer_ofconstruct. This construct already has all the info it needs to retrieve the reference to the corresponding struct from the offset that is already available, inherent incontainer_of(), between its type and member inputs (structieee80211_vifanddrv_priv, respectively). Remove vif (which was previously storing the reference to the structieee80211_vif) from the structwfx_vif, define a functionwvif_to_vif(wvif)forcontainer_of(), and replace allwvif->vifwith the newly definedcontainer_ofconstruct.Signed-off-by Jaehee Park <[email protected]>
Quoted 8 lines
---
Changes from staging to wireless-next tree
- changed macro into function and named it back towvif_to_vif
- fit all lines in patch to 80 columns
- decared a reference to vif at the beginning of the functionsNOTE: Jérôme is going to be testing this patch on his hardware
Don't forget to increment the version number of your submission (option -v of git send-email).
Quoted 38 lines
drivers/net/wireless/silabs/wfx/wfx.h | 6 +- drivers/net/wireless/silabs/wfx/data_rx.c | 5 +- drivers/net/wireless/silabs/wfx/data_tx.c | 3 +- drivers/net/wireless/silabs/wfx/key.c | 4 +- drivers/net/wireless/silabs/wfx/queue.c | 3 +- drivers/net/wireless/silabs/wfx/scan.c | 9 ++- drivers/net/wireless/silabs/wfx/sta.c | 69 ++++++++++++++--------- 7 files changed, 63 insertions(+), 36 deletions(-)drivers/net/wireless/silabs/wfx/wfx.h +5
-1@@ -61,7 +61,6 @@ struct wfx_dev {struct wfx_vif {struct wfx_dev *wdev; -struct ieee80211_vif *vif;struct ieee80211_channel *channel;int id;@@ -91,6 +90,11 @@ struct wfx_vif {struct completion set_pm_mode_complete; }; +static inline struct ieee80211_vif *wvif_to_vif (struct wfx_vif *wvif) +{ + return container_of((void *)wvif, struct ieee80211_vif, drv_priv); +} +static inline struct wfx_vif *wdev_to_wvif (struct wfx_dev *wdev,int vif_id) {if (vif_id >=ARRAY_SIZE (wdev->vif)) {drivers/net/wireless/silabs/wfx/data_rx.c +0
-0
drivers/net/wireless/silabs/wfx/data_rx.c line 19
Quoted 4 lines
drivers/net/wireless/silabs/wfx/data_rx.c +1
-0@@ -16,6 +16,7 @@static void wfx_rx_handle_ba (struct wfx_vif *wvif,struct ieee80211_mgmt *mgmt) {int params, tid; +struct ieee80211_vif *vif =wvif_to_vif (wvif);
When you can, try to place the longest declaration first ("reverse Christmas tree order").
[...]
Quoted 4 lines
drivers/net/wireless/silabs/wfx/sta.c +0
-0
[...]
Quoted 16 lines
drivers/net/wireless/silabs/wfx/sta.c +4
-6@@ -152,19 +153,28 @@ static int wfx_get_ps_timeout(struct wfx_vif *wvif, bool *enable_ps) {struct ieee80211_channel *chan0 =NULL , *chan1 =NULL ;struct ieee80211_conf *conf = &wvif->wdev->hw->conf; +struct ieee80211_vif *vif =wvif_to_vif (wvif); -WARN (!wvif->vif->bss_conf.assoc && enable_ps, +WARN (!vif->bss_conf.assoc && enable_ps,"enable_ps is reliable only if associated" ); -if (wdev_to_wvif (wvif->wdev,0 )) - chan0 =wdev_to_wvif (wvif->wdev,0 )->vif->bss_conf.chandef.chan; -if (wdev_to_wvif (wvif->wdev,1 )) - chan1 =wdev_to_wvif (wvif->wdev,1 )->vif->bss_conf.chandef.chan; -if (chan0 && chan1 && wvif->vif->type !=NL80211_IFTYPE_AP ) { +if (wdev_to_wvif (wvif->wdev,0 )) { +struct wfx_vif *wvif_ch0 =wdev_to_wvif (wvif->wdev,0 );
drivers/net/wireless/silabs/wfx/sta.c static int wfx_get_ps_timeout(struct wfx_vif *wvif, bool *enable_ps) · line 171
Quoted 10 lines
drivers/net/wireless/silabs/wfx/sta.c +10
-0+struct ieee80211_vif *vif_ch0 =wvif_to_vif (wvif_ch0); + + chan0 = vif_ch0->bss_conf.chandef.chan; + } +if (wdev_to_wvif (wvif->wdev,1 )) { +struct wfx_vif *wvif_ch1 =wdev_to_wvif (wvif->wdev,1 ); +struct ieee80211_vif *vif_ch1 =wvif_to_vif (wvif_ch1); + + chan1 = vif_ch1->bss_conf.chandef.chan; + }
I think this code could be simplified into:
if (wvif->wdev->vif[1])
chan1 = wvif->wdev->vif[1]->bss_conf.chandef.chan;(If you choose this way, I suggest to place this change in a separate patch)
[...]
Signature · 1 line
Jérôme Pouiller
Quoted 64 lines · Jérôme Pouiller
Quoted 14 lines · On Monday 18 April 2022 05:51:10 CEST Jaehee Park wrote:
Currently, upon virtual interface creation,
wfx_add_interface()stores a reference to the corresponding structieee80211_vifin private data, for later usage. This is not needed when using thecontainer_ofconstruct. This construct already has all the info it needs to retrieve the reference to the corresponding struct from the offset that is already available, inherent incontainer_of(), between its type and member inputs (structieee80211_vifanddrv_priv, respectively). Remove vif (which was previously storing the reference to the structieee80211_vif) from the structwfx_vif, define a functionwvif_to_vif(wvif)forcontainer_of(), and replace allwvif->vifwith the newly definedcontainer_ofconstruct.Signed-off-by Jaehee Park <[email protected]>Quoted 8 lines
---
Changes from staging to wireless-next tree
- changed macro into function and named it back towvif_to_vif
- fit all lines in patch to 80 columns
- decared a reference to vif at the beginning of the functionsNOTE: Jérôme is going to be testing this patch on his hardware
Don't forget to increment the version number of your submission (option -v of git send-email).
Quoted 37 lines
drivers/net/wireless/silabs/wfx/wfx.h | 6 +- drivers/net/wireless/silabs/wfx/data_rx.c | 5 +- drivers/net/wireless/silabs/wfx/data_tx.c | 3 +- drivers/net/wireless/silabs/wfx/key.c | 4 +- drivers/net/wireless/silabs/wfx/queue.c | 3 +- drivers/net/wireless/silabs/wfx/scan.c | 9 ++- drivers/net/wireless/silabs/wfx/sta.c | 69 ++++++++++++++--------- 7 files changed, 63 insertions(+), 36 deletions(-)drivers/net/wireless/silabs/wfx/wfx.h +5
-1@@ -61,7 +61,6 @@ struct wfx_dev {struct wfx_vif {struct wfx_dev *wdev; -struct ieee80211_vif *vif;struct ieee80211_channel *channel;int id;@@ -91,6 +90,11 @@ struct wfx_vif {struct completion set_pm_mode_complete; }; +static inline struct ieee80211_vif *wvif_to_vif (struct wfx_vif *wvif) +{ + return container_of((void *)wvif, struct ieee80211_vif, drv_priv); +} +static inline struct wfx_vif *wdev_to_wvif (struct wfx_dev *wdev,int vif_id) {if (vif_id >=ARRAY_SIZE (wdev->vif)) {drivers/net/wireless/silabs/wfx/data_rx.c +0
-0
Quoted 8 lines
drivers/net/wireless/silabs/wfx/data_rx.c line 19
Quoted 5 lines
drivers/net/wireless/silabs/wfx/data_rx.c +1
-0@@ -16,6 +16,7 @@static void wfx_rx_handle_ba (struct wfx_vif *wvif,struct ieee80211_mgmt *mgmt) {int params, tid; +struct ieee80211_vif *vif =wvif_to_vif (wvif);When you can, try to place the longest declaration first ("reverse Christmas tree order").
Thanks Jerome, I have a new version of the patch I'm going to send today with this edit.
Quoted 36 lines
[...]
Quoted 4 lines
drivers/net/wireless/silabs/wfx/sta.c +0
-0[...]
Quoted 16 lines
drivers/net/wireless/silabs/wfx/sta.c +4
-6@@ -152,19 +153,28 @@ static int wfx_get_ps_timeout(struct wfx_vif *wvif, bool *enable_ps) {struct ieee80211_channel *chan0 =NULL , *chan1 =NULL ;struct ieee80211_conf *conf = &wvif->wdev->hw->conf; +struct ieee80211_vif *vif =wvif_to_vif (wvif); -WARN (!wvif->vif->bss_conf.assoc && enable_ps, +WARN (!vif->bss_conf.assoc && enable_ps,"enable_ps is reliable only if associated" ); -if (wdev_to_wvif (wvif->wdev,0 )) - chan0 =wdev_to_wvif (wvif->wdev,0 )->vif->bss_conf.chandef.chan; -if (wdev_to_wvif (wvif->wdev,1 )) - chan1 =wdev_to_wvif (wvif->wdev,1 )->vif->bss_conf.chandef.chan; -if (chan0 && chan1 && wvif->vif->type !=NL80211_IFTYPE_AP ) { +if (wdev_to_wvif (wvif->wdev,0 )) { +struct wfx_vif *wvif_ch0 =wdev_to_wvif (wvif->wdev,0 );drivers/net/wireless/silabs/wfx/sta.c static int wfx_get_ps_timeout(struct wfx_vif *wvif, bool *enable_ps) · line 171
Quoted 10 lines
drivers/net/wireless/silabs/wfx/sta.c +10
-0+struct ieee80211_vif *vif_ch0 =wvif_to_vif (wvif_ch0); + + chan0 = vif_ch0->bss_conf.chandef.chan; + } +if (wdev_to_wvif (wvif->wdev,1 )) { +struct wfx_vif *wvif_ch1 =wdev_to_wvif (wvif->wdev,1 ); +struct ieee80211_vif *vif_ch1 =wvif_to_vif (wvif_ch1); + + chan1 = vif_ch1->bss_conf.chandef.chan; + }I think this code could be simplified into:
Quoted 6 lines
if (wvif->wdev->vif[1]) chan1 = wvif->wdev->vif[1]->bss_conf.chandef.chan;(If you choose this way, I suggest to place this change in a separate patch)
Ok I'll send your suggested edit in a separate patch after this patch gets through.
Quoted 6 lines
[...]
Signature · 1 line
Jérôme Pouiller
Quoted 13 lines · Jaehee Park
Currently, upon virtual interface creation,
wfx_add_interface()stores a reference to the corresponding structieee80211_vifin private data, for later usage. This is not needed when using thecontainer_ofconstruct. This construct already has all the info it needs to retrieve the reference to the corresponding struct from the offset that is already available, inherent incontainer_of(), between its type and member inputs (structieee80211_vifanddrv_priv, respectively). Remove vif (which was previously storing the reference to the structieee80211_vif) from the structwfx_vif, define a functionwvif_to_vif(wvif)forcontainer_of(), and replace allwvif->vifwith the newly definedcontainer_ofconstruct.Signed-off-by Jaehee Park <[email protected]>
[...]
drivers/net/wireless/silabs/wfx/wfx.h struct wfx_vif { · line 96
Quoted 4 lines
drivers/net/wireless/silabs/wfx/wfx.h +4
-0+static inline struct ieee80211_vif *wvif_to_vif (struct wfx_vif *wvif) +{ + return container_of((void *)wvif, struct ieee80211_vif, drv_priv); +}
Why the void pointer cast? Avoid casts as much possible.
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
Quoted 14 lines · On mercoledì 20 aprile 2022 13:57:57 CEST Kalle Valo wrote:
Quoted 12 lines · Jaehee Park
Currently, upon virtual interface creation,
wfx_add_interface()stores a reference to the corresponding structieee80211_vifin private data, for later usage. This is not needed when using thecontainer_ofconstruct. This construct already has all the info it needs to retrieve the reference to the corresponding struct from the offset that is already available, inherent incontainer_of(), between its type and member inputs (structieee80211_vifanddrv_priv, respectively). Remove vif (which was previously storing the reference to the structieee80211_vif) from the structwfx_vif, define a functionwvif_to_vif(wvif)forcontainer_of(), and replace allwvif->vifwith the newly definedcontainer_ofconstruct.
Quoted 7 lines
Quoted 1 line
Signed-off-by Jaehee Park <[email protected]>[...]
drivers/net/wireless/silabs/wfx/wfx.h struct wfx_vif {
Quoted 3 lines
drivers/net/wireless/silabs/wfx/wfx.h +3
-0+static inline struct ieee80211_vif *wvif_to_vif (struct wfx_vif *wvif) +{ + return container_of((void *)wvif, struct ieee80211_vif,
drv_priv);
Quoted 3 lines
Quoted 1 line
+}
Why the void pointer cast? Avoid casts as much possible.
In a previous email Jaehee wrote that she could compile her changes only by using that "(void *)" cast.
I replied that probably this is a hint that something is broken, although my argument is not necessarily a "proof". Might very well be that this cast was needed in this particular situation but I cannot see why.
@Jaehee, please try to explain why this "(void *)" cast is actually necessary and why your changes cannot avoid it.
Thanks,
Fabio M. De Francesco
Quoted 17 lines · Kalle Valo
Quoted 12 lines · Jaehee Park
Currently, upon virtual interface creation,
wfx_add_interface()stores a reference to the corresponding structieee80211_vifin private data, for later usage. This is not needed when using thecontainer_ofconstruct. This construct already has all the info it needs to retrieve the reference to the corresponding struct from the offset that is already available, inherent incontainer_of(), between its type and member inputs (structieee80211_vifanddrv_priv, respectively). Remove vif (which was previously storing the reference to the structieee80211_vif) from the structwfx_vif, define a functionwvif_to_vif(wvif)forcontainer_of(), and replace allwvif->vifwith the newly definedcontainer_ofconstruct.Quoted 1 line
Signed-off-by Jaehee Park <[email protected]>
Quoted 9 lines
[...]
drivers/net/wireless/silabs/wfx/wfx.h struct wfx_vif { · line 96
Quoted 4 lines
drivers/net/wireless/silabs/wfx/wfx.h +4
-0+static inline struct ieee80211_vif *wvif_to_vif (struct wfx_vif *wvif) +{ + return container_of((void *)wvif, struct ieee80211_vif, drv_priv); +}Why the void pointer cast? Avoid casts as much possible.
Hi Kalle,
Sorry for the delay in getting back to you about why the void pointer cast was used.
In essence, I'm taking private data with a driver-specific pointer and that needs to be resolved back to a generic pointer.
The private data (drv_priv) is declared as a generic u8 array in struct ieee80211_vif, but wvif is a more specific type.
I wanted to also point to existing, reasonable examples such as:
static void iwl_mvm_tcm_uapsd_nonagg_detected_wk(struct work_struct *wk)
{
struct iwl_mvm *mvm;
struct iwl_mvm_vif *mvmvif;
struct ieee80211_vif *vif;
mvmvif = container_of(wk, struct iwl_mvm_vif,
uapsd_nonagg_detected_wk.work);
vif = container_of((void *)mvmvif, struct ieee80211_vif, drv_priv);in drivers/net/wireless$ less intel/iwlwifi/mvm/utils.c, which does the same thing.
There are fifteen of them throughout:
wireless-next/drivers/net/wireless$ grep -rn "container_of(.* ieee80211_vif" intel/iwlwifi/mvm/utils.c:794: vif = container_of((void *)mvmvif, struct ieee80211_vif, drv_priv);intel/iwlwifi/mvm/mac80211.c:1347: vif = container_of((void
*)mvmvif, struct ieee80211_vif, drv_priv);mediatek/mt76/mt76x02_mmio.c:415: vif =container_of(priv, struct ieee80211_vif, drv_priv); mediatek/mt76/mt7615/mac.c:275: vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);mediatek/mt76/mt7915/mac.c:416: vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);mediatek/mt76/mt7915/mac.c:2327: vif =container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);mediatek/mt76/mt7915/debugfs.c:1026: vif = container_of((void
*)msta->vif, struct ieee80211_vif, drv_priv); mediatek/mt76/mt7921/mac.c:425: vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);ti/wlcore/wlcore_i.h:502: return container_of((void *)wlvif,
struct ieee80211_vif, drv_priv);realtek/rtl818x/rtl8187/dev.c:1068: container_of((void
*)vif_priv, struct ieee80211_vif, drv_priv);realtek/rtl818x/rtl8180/dev.c:1293: container_of((void
*)vif_priv, struct ieee80211_vif, drv_priv);realtek/rtw88/main.h:2075: return container_of(p, structieee80211_vif, drv_priv);realtek/rtw89/core.h:3440: return container_of(p, structieee80211_vif, drv_priv);ath/carl9170/carl9170.h:641: return container_of((void *)priv,
struct ieee80211_vif, drv_priv);ath/wcn36xx/wcn36xx.h:329: return container_of((void *) vif_priv,
struct ieee80211_vif, drv_priv);
Thanks,
Jaehee
Quoted 77 lines · Jaehee
Quoted 17 lines · Kalle Valo
Quoted 12 lines · Jaehee Park
Currently, upon virtual interface creation,
wfx_add_interface()stores a reference to the corresponding structieee80211_vifin private data, for later usage. This is not needed when using thecontainer_ofconstruct. This construct already has all the info it needs to retrieve the reference to the corresponding struct from the offset that is already available, inherent incontainer_of(), between its type and member inputs (structieee80211_vifanddrv_priv, respectively). Remove vif (which was previously storing the reference to the structieee80211_vif) from the structwfx_vif, define a functionwvif_to_vif(wvif)forcontainer_of(), and replace allwvif->vifwith the newly definedcontainer_ofconstruct.Quoted 1 line
Signed-off-by Jaehee Park <[email protected]>Quoted 9 lines
[...]
drivers/net/wireless/silabs/wfx/wfx.h struct wfx_vif { · line 96
Quoted 4 lines
drivers/net/wireless/silabs/wfx/wfx.h +4
-0+static inline struct ieee80211_vif *wvif_to_vif (struct wfx_vif *wvif) +{ + return container_of((void *)wvif, struct ieee80211_vif, drv_priv); +}Why the void pointer cast? Avoid casts as much possible.
Hi Kalle,
Sorry for the delay in getting back to you about why the void pointer cast was used.
In essence, I'm taking private data with a driver-specific pointer and that needs to be resolved back to a generic pointer.
The private data (
drv_priv) is declared as a generic u8 array in structieee80211_vif, but wvif is a more specific type.I wanted to also point to existing, reasonable examples such as:
static voidiwl_mvm_tcm_uapsd_nonagg_detected_wk(struct work_struct *wk){ struct iwl_mvm *mvm; struct iwl_mvm_vif *mvmvif; struct ieee80211_vif *vif; mvmvif = container_of(wk, struct iwl_mvm_vif, uapsd_nonagg_detected_wk.work); vif = container_of((void *)mvmvif, struct ieee80211_vif, drv_priv);in
drivers/net/wireless$lessintel/iwlwifi/mvm/utils.c, which does the same thing.There are fifteen of them throughout:
wireless-next/drivers/net/wireless$ grep -rn "container_of(.*ieee80211_vif"intel/iwlwifi/mvm/utils.c:794: vif =container_of((void *)mvmvif, struct ieee80211_vif, drv_priv);intel/iwlwifi/mvm/mac80211.c:1347: vif = container_of((void
*)mvmvif, structieee80211_vif,drv_priv);mediatek/mt76/mt76x02_mmio.c:415: vif =container_of(priv, struct ieee80211_vif, drv_priv);mediatek/mt76/mt7615/mac.c:275: vif =container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);mediatek/mt76/mt7915/mac.c:416: vif =container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);mediatek/mt76/mt7915/mac.c:2327: vif =container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);mediatek/mt76/mt7915/debugfs.c:1026: vif = container_of((void
*)msta->vif, structieee80211_vif,drv_priv);mediatek/mt76/mt7921/mac.c:425: vif =container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);ti/wlcore/wlcore_i.h:502: return container_of((void *)wlvif,
structieee80211_vif,drv_priv);realtek/rtl818x/rtl8187/dev.c:1068: container_of((void
*)vif_priv, structieee80211_vif,drv_priv);realtek/rtl818x/rtl8180/dev.c:1293: container_of((void
*)vif_priv, structieee80211_vif,drv_priv);
Quoted 9 lines
realtek/rtw88/main.h:2075: return container_of(p, structieee80211_vif,drv_priv);realtek/rtw89/core.h:3440: return container_of(p, structieee80211_vif,drv_priv);ath/carl9170/carl9170.h:641: return container_of((void *)priv,
structieee80211_vif,drv_priv);ath/wcn36xx/wcn36xx.h:329: return container_of((void *)vif_priv,
structieee80211_vif,drv_priv);
Sorry -- here's the last portion of the email without wrapping.
wireless-next/drivers/net/wireless$ grep -rn "container_of(.* ieee80211_vif" intel/iwlwifi/mvm/utils.c:794: vif = container_of((void *)mvmvif, struct ieee80211_vif, drv_priv);intel/iwlwifi/mvm/mac80211.c:1347: vif = container_of((void *)mvmvif, struct ieee80211_vif, drv_priv);mediatek/mt76/mt76x02_mmio.c:415: vif = container_of(priv, struct ieee80211_vif, drv_priv);mediatek/mt76/mt7615/mac.c:275: vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv); mediatek/mt76/mt7915/mac.c:416: vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);mediatek/mt76/mt7915/mac.c:2327: vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);mediatek/mt76/mt7915/debugfs.c:1026: vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);mediatek/mt76/mt7921/mac.c:425: vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);ti/wlcore/wlcore_i.h:502: return container_of((void *)wlvif, struct ieee80211_vif, drv_priv);realtek/rtl818x/rtl8187/dev.c:1068: container_of((void *)vif_priv, struct ieee80211_vif, drv_priv);realtek/rtl818x/rtl8180/dev.c:1293: container_of((void *)vif_priv, struct ieee80211_vif, drv_priv);
realtek/rtw88/main.h:2075: return container_of(p, struct ieee80211_vif, drv_priv); realtek/rtw89/core.h:3440: return container_of(p, struct ieee80211_vif, drv_priv); ath/carl9170/carl9170.h:641: return container_of((void *)priv, struct ieee80211_vif, drv_priv); ath/wcn36xx/wcn36xx.h:329: return container_of((void *) vif_priv, struct ieee80211_vif, drv_priv);
Quoted 8 lines
Thanks,
Jaehee
Quoted 50 lines · Jaehee
Quoted 17 lines · Kalle Valo
Quoted 12 lines · Jaehee Park
Currently, upon virtual interface creation,
wfx_add_interface()stores a reference to the corresponding structieee80211_vifin private data, for later usage. This is not needed when using thecontainer_ofconstruct. This construct already has all the info it needs to retrieve the reference to the corresponding struct from the offset that is already available, inherent incontainer_of(), between its type and member inputs (structieee80211_vifanddrv_priv, respectively). Remove vif (which was previously storing the reference to the structieee80211_vif) from the structwfx_vif, define a functionwvif_to_vif(wvif)forcontainer_of(), and replace allwvif->vifwith the newly definedcontainer_ofconstruct.Quoted 1 line
Signed-off-by Jaehee Park <[email protected]>Quoted 9 lines
[...]
drivers/net/wireless/silabs/wfx/wfx.h struct wfx_vif { · line 96
Quoted 4 lines
drivers/net/wireless/silabs/wfx/wfx.h +4
-0+static inline struct ieee80211_vif *wvif_to_vif (struct wfx_vif *wvif) +{ + return container_of((void *)wvif, struct ieee80211_vif, drv_priv); +}Why the void pointer cast? Avoid casts as much possible.
Hi Kalle,
Sorry for the delay in getting back to you about why the void pointer cast was used.
In essence, I'm taking private data with a driver-specific pointer and that needs to be resolved back to a generic pointer.
The private data (
drv_priv) is declared as a generic u8 array in structieee80211_vif, but wvif is a more specific type.I wanted to also point to existing, reasonable examples such as:
static voidiwl_mvm_tcm_uapsd_nonagg_detected_wk(struct work_struct *wk){ struct iwl_mvm *mvm; struct iwl_mvm_vif *mvmvif; struct ieee80211_vif *vif; mvmvif = container_of(wk, struct iwl_mvm_vif, uapsd_nonagg_detected_wk.work); vif = container_of((void *)mvmvif, struct ieee80211_vif, drv_priv);
Quoted 4 lines
in
drivers/net/wireless$lessintel/iwlwifi/mvm/utils.c, which does the same thing.There are fifteen of them throughout:
The cast is fine, but this email is frustrating.
It sounds like you are saying that you copied it from other code and that's not a good answer... :/ It's easiest if you just copy and paste the build error and we can figure out why the cast is need for our selves...
drivers/net/wireless/silabs/wfx/data_rx.c: In function ‘wvif_to_vif’:./include/linux/build_bug.h:78:41: error: static assertion failed: "pointer type mismatch in container_of()"
78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
| ^~~~~~~~~~~~~~
./include/linux/build_bug.h:77:34: note: in expansion of macro ‘__static_assert’
77 | #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
| ^~~~~~~~~~~~~~~
./include/linux/container_of.h:19:9: note: in expansion of macro ‘static_assert’
19 | static_assert(__same_type(*(ptr), ((type *)0)->member) || \
| ^~~~~~~~~~~~~
drivers/net/wireless/silabs/wfx/data_rx.c:20:16: note: in expansion of macro ‘container_of’
20 | return container_of(wvif, struct ieee80211_vif, drv_priv);
| ^~~~~~~~~~~~regards,
dan carpenter
Hi Dan,
Quoted 54 lines · On Wed, 4 May 2022 12:33:48 +0300 Dan Carpenter <[email protected]>…
Quoted 53 lines · Jaehee
Quoted 17 lines · Kalle Valo
Quoted 12 lines · Jaehee Park
Currently, upon virtual interface creation,
wfx_add_interface()stores a reference to the corresponding structieee80211_vifin private data, for later usage. This is not needed when using thecontainer_ofconstruct. This construct already has all the info it needs to retrieve the reference to the corresponding struct from the offset that is already available, inherent incontainer_of(), between its type and member inputs (structieee80211_vifanddrv_priv, respectively). Remove vif (which was previously storing the reference to the structieee80211_vif) from the structwfx_vif, define a functionwvif_to_vif(wvif)forcontainer_of(), and replace allwvif->vifwith the newly definedcontainer_ofconstruct.Quoted 1 line
Signed-off-by Jaehee Park <[email protected]>Quoted 9 lines
[...]
drivers/net/wireless/silabs/wfx/wfx.h struct wfx_vif { · line 96
Quoted 4 lines
drivers/net/wireless/silabs/wfx/wfx.h +4
-0+static inline struct ieee80211_vif *wvif_to_vif (struct wfx_vif *wvif) +{ + return container_of((void *)wvif, struct ieee80211_vif, drv_priv); +}Why the void pointer cast? Avoid casts as much possible.
Hi Kalle,
Sorry for the delay in getting back to you about why the void pointer cast was used.
In essence, I'm taking private data with a driver-specific pointer and that needs to be resolved back to a generic pointer.
The private data (
drv_priv) is declared as a generic u8 array in structieee80211_vif, but wvif is a more specific type.I wanted to also point to existing, reasonable examples such as:
static voidiwl_mvm_tcm_uapsd_nonagg_detected_wk(struct work_struct *wk){ struct iwl_mvm *mvm; struct iwl_mvm_vif *mvmvif; struct ieee80211_vif *vif; mvmvif = container_of(wk, struct iwl_mvm_vif, uapsd_nonagg_detected_wk.work); vif = container_of((void *)mvmvif, struct ieee80211_vif, drv_priv);in
drivers/net/wireless$lessintel/iwlwifi/mvm/utils.c, which does the same thing.
Quoted 8 lines
Quoted 1 line
There are fifteen of them throughout:
The cast is fine, but this email is frustrating.
It sounds like you are saying that you copied it from other code and that's not a good answer... :/ It's easiest if you just copy and paste the build error and we can figure out why the cast is need for our selves...
...my bad, then.
I suggested to Jaehee she would *also* point out that there are already a pile of usages (which I grepped for myself, by the way).
And that it's *obvious* that container_of() would trigger warnings otherwise. Well, obvious just for me, it seems.
Signature · 1 line
Stefano
Quoted 2 lines · Stefano Brivio
And that it's *obvious* that
container_of()would trigger warnings otherwise. Well, obvious just for me, it seems.
:P
Apparently it wasn't obvious to Kalle and me. My guess is that you saw the build error. Either that or Kalle and I are geezers who haven't looked at container_of() since before the BUILD_BUG_ON() was added five years ago.
regards,
dan carpenter
Quoted 10 lines · Dan Carpenter
Quoted 2 lines · Stefano Brivio
And that it's *obvious* that
container_of()would trigger warnings otherwise. Well, obvious just for me, it seems.:P
Apparently it wasn't obvious to Kalle and me. My guess is that you saw the build error. Either that or Kalle and I are geezers who haven't looked at
container_of()since before theBUILD_BUG_ON()was added five years ago.
Exactly, I also had to duplicate the error myself before I was able to understand the issue. So I'm officially a geezer now :D
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
Quoted 8 lines · Kalle Valo
Quoted 6 lines · Dan Carpenter
Quoted 2 lines · Stefano Brivio
And that it's *obvious* that
container_of()would trigger warnings otherwise. Well, obvious just for me, it seems.:P
Quoted 8 lines
Quoted 4 lines
Apparently it wasn't obvious to Kalle and me. My guess is that you saw the build error. Either that or Kalle and I are geezers who haven't looked at
container_of()since before theBUILD_BUG_ON()was added five years ago.Exactly, I also had to duplicate the error myself before I was able to understand the issue. So I'm officially a geezer now :D
Hi Dan and Kalle, thanks for your messages!
Understood -- I'll copy the error for reference next time. Sorry you had to recreate the build error yourself!
Quoted 4 lines
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches