Re: [PATCH] staging: wfx: use container_of() to get vif

From: Julia Lawall
Date: Sat Apr 09 2022 - 11:37:52 EST




On Sat, 9 Apr 2022, Jérôme Pouiller wrote:

> On Saturday 9 April 2022 00:21:02 CEST Jaehee Park wrote:
> > On Fri, Apr 08, 2022 at 11:49:49AM +0200, Julia Lawall wrote:
> > > On Thu, 7 Apr 2022, Jaehee Park wrote:
> > >
> > > > Use container_of() to get vif. This improves the code in two ways:
> > > > [1] it speeds up the compilation because container_of() saves steps to
> > > > retrieve vif (the representation of ieee80211_vif), and
> > >
> > > I don't understand this part.
> > >
> > > julia
> > >
> >
> > Thank you for your message. I revised the commit message (below)--
> > I hope it makes it clearer. I'm open to suggestions as well!
> >
> > 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 macro
> > wvif_to_vif(wvif) for container_of(), and replace all wvif->vif with
> > the newly defined container_of construct.
> >
> > Sorry if I'm putting out more information than was asked for:
> > Diagram is worth a thousand words; this one is made by Stefano when
> > he was explaining the container_of() construct:
> >
> > .-----------------------------------.
> > | .------------------------------. |
> > '->| struct ieee80211_vif | |
> > |------------------------------| |
> > | 1 | |
> > | 2 | |
> > | .--------------------------.| |
> > | 3| struct wfx_vif drv_priv | |
> > | |---------------------------| |
> > | | ... | |
> > | | | |
> > | | struct ieee80211_vif *vif---'
> > '------------------------------'
> > In this example, the offset is 3.
> > What I want to convey here is the compiler already knows the offset
> > of drv_priv within struct ieee80211_vif by using the container_of()
> > construct. So, it doesn't need to do extra work.
>
> Wow, nice ascii art :)
>
> I think that Julia has not understand why you said it "speeds up the
> compilation". I think you meant "speeds up the execution", don't you?

Yes, that was my concern.

julia