public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Jaehee Park <jhpark1013@gmail.com>
To: Kalle Valo <kvalo@kernel.org>
Cc: "Jérôme Pouiller" <jerome.pouiller@silabs.com>,
	"David S. Miller" <davem@davemloft.net>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	linux-wireless@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-staging@lists.linux.dev,
	"Outreachy Linux Kernel" <outreachy@lists.linux.dev>,
	"Stefano Brivio" <sbrivio@redhat.com>
Subject: Re: [PATCH] wfx: use container_of() to get vif
Date: Mon, 2 May 2022 14:34:03 -0400	[thread overview]
Message-ID: <20220502183403.GA812540@jaehee-ThinkPad-X1-Extreme> (raw)
In-Reply-To: <CAA1TwFCOEEwnayexnJin8T=Fc2HEgHC9jyfj5HxfiWybjUi9GA@mail.gmail.com>

On Mon, May 02, 2022 at 02:10:07PM -0400, Jaehee wrote:
> On Wed, Apr 20, 2022 at 7:58 AM Kalle Valo <kvalo@kernel.org> wrote:
> >
> > Jaehee Park <jhpark1013@gmail.com> writes:
> >
> > > 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.
> > >
> > > Signed-off-by: Jaehee Park <jhpark1013@gmail.com>
> >
> > [...]
> >
> > > +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, 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);
> 

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);

> Thanks,
> Jaehee
> 
> 
> > --
> > https://patchwork.kernel.org/project/linux-wireless/list/
> >
> > https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

  reply	other threads:[~2022-05-02 18:34 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-18  3:51 [PATCH] wfx: use container_of() to get vif Jaehee Park
2022-04-19 13:39 ` Jérôme Pouiller
2022-05-03 18:18   ` Jaehee Park
2022-04-20 11:57 ` Kalle Valo
2022-04-20 16:53   ` Fabio M. De Francesco
2022-05-02 18:10   ` Jaehee
2022-05-02 18:34     ` Jaehee Park [this message]
2022-05-04  9:33     ` Dan Carpenter
2022-05-04 11:50       ` Stefano Brivio
2022-05-04 13:25         ` Dan Carpenter
2022-05-04 16:05           ` Kalle Valo
2022-05-04 17:07             ` Jaehee Park

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220502183403.GA812540@jaehee-ThinkPad-X1-Extreme \
    --to=jhpark1013@gmail.com \
    --cc=davem@davemloft.net \
    --cc=jerome.pouiller@silabs.com \
    --cc=kuba@kernel.org \
    --cc=kvalo@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=linux-wireless@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=outreachy@lists.linux.dev \
    --cc=pabeni@redhat.com \
    --cc=sbrivio@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox