lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 2 May 2022 14:10:07 -0400
From:   Jaehee <jhpark1013@...il.com>
To:     Kalle Valo <kvalo@...nel.org>
Cc:     Jérôme Pouiller <jerome.pouiller@...abs.com>,
        "David S. Miller" <davem@...emloft.net>,
        Jakub Kicinski <kuba@...nel.org>,
        Paolo Abeni <pabeni@...hat.com>,
        linux-wireless@...r.kernel.org, netdev@...r.kernel.org,
        linux-kernel@...r.kernel.org, linux-staging@...ts.linux.dev,
        Outreachy Linux Kernel <outreachy@...ts.linux.dev>,
        Stefano Brivio <sbrivio@...hat.com>
Subject: Re: [PATCH] wfx: use container_of() to get vif

On Wed, Apr 20, 2022 at 7:58 AM Kalle Valo <kvalo@...nel.org> wrote:
>
> Jaehee Park <jhpark1013@...il.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@...il.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);

Thanks,
Jaehee


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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ