Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp153588iob; Mon, 2 May 2022 15:42:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygKTSTdQsSVcOEq+bGtAS3N6917Md/ywMntvMQXqs+LC8JXTnJuLNdnHlvb/UIybxPYEKV X-Received: by 2002:a19:ca0d:0:b0:472:1a4d:a67d with SMTP id a13-20020a19ca0d000000b004721a4da67dmr10072405lfg.222.1651531370689; Mon, 02 May 2022 15:42:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651531370; cv=none; d=google.com; s=arc-20160816; b=UbK/s7S8Lq4OfOIwa9KhynrlJ6NgQXX4jK/dwg6SLOE5GCRrwPL22l1KnTkmNrxtIc 7T7GSK4BI6XxLK3EMeQyuPUmIKsZB9qTQtwYvf2MXCDtfkdzVvWUQ0JzoWCuku9BZHCy jfOuESrDPKk31iB8njgHGF1TbbCB/+mUBNu1Oi6D8pkEEDH93QtpNM3NhAUaHJQ0We7E LFceKV+BHKY1vbk76QjejiVAu/lHRq+jCkmJXOmqoDtBuQy1vS/nrOTTVu/5KPt0tOwY JwH7T8zxDzWzkwF3yAVHAJJAwa7/77OxkWoyuM0UtprzSk+Vry55dO21jLyOs7YbF5OM 6hIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=cddP/Z13UXKTkYF9w5rF9NXnRnnOzjoeOmrL0f6HI08=; b=UvyZdWpL3nFmIhJESsR3562xyYoP9ze7hKOoD/y970KIAiMlcEkkeDv1h01Ab3bK/6 f0b3pvzQH50/V9DL4C5u6fGaI1rZLQHhFyIeaSIPzm3qIQgKtbY0RflhrvA6f6A7Q7h6 xLNLRvmiPR7uAyETfRGrD72aLsfmxyyCZAxZ/GdMmJDqXqbHGPsQmrWHaWMeJ9ArW6Ll ykfjoLR7mFydrm+47gkBnvfuggR0YcvQo9/Iqo437gdx/LNf6hdtQXbjAHaKA5M8pozI 5c3h6jq8QrgPeaytCSIfH53vCYABc4kj3sI1fL2KXuypRRWbxxApiWhJGFWTOmEULPcW NPiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=F4Ji6+33; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h2-20020a0565123c8200b004722dd11721si21145618lfv.30.2022.05.02.15.42.27; Mon, 02 May 2022 15:42:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=F4Ji6+33; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346502AbiEBSOD (ORCPT + 68 others); Mon, 2 May 2022 14:14:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352269AbiEBSNu (ORCPT ); Mon, 2 May 2022 14:13:50 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FC74DDC; Mon, 2 May 2022 11:10:20 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id g20so17484399edw.6; Mon, 02 May 2022 11:10:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=cddP/Z13UXKTkYF9w5rF9NXnRnnOzjoeOmrL0f6HI08=; b=F4Ji6+339Da2kNbJt5KKB7iw7+2g8p0PdFRFplhegL4px6LEkwgymj9L/pFn3CKBMV M+iTz/GM3qvVMi2QegU8yveV2OOFZmAxCvrCM4nLweuQEEpJ4fxxBuwW0XcnPU3rjJ9v fcCIx4zoHjmKrJCBrSvCJw8DNNIJoMWbJlEjobxiZpJEGTuUESzb+Vpc9FAb8FFSQ79e TaNbZ9/pe0G86boa4lsXTrbTzX9iP/riBvjaCj5pi1N75VT11wl30atdIppi2ABltn2c +eMnaENwkKjFugo19M5yBot9eE3DFetuaurpWhQZ0JdK6VTc9D9pkL2NlLAeoooATGgA MZzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=cddP/Z13UXKTkYF9w5rF9NXnRnnOzjoeOmrL0f6HI08=; b=fQUEWfbe6OynlSN9aGgkfIqMhpg+UZnyo9ssnYCk/VXKmXt4nWwesw34A4jQhrcsDS ce3JZMQwwldktFrNP77gshpsEYJT684nzAXuGYJpZiYF6QCynYDd6tG4u9vcVRTCKLkI I1xF5VzP7EylIKmjADWBI+4RZGEifk0aVzdNNSJnyFZrx4A90uKRQJ3kdjRR1Cu18/Fo KpG8Y1ACH2mooQvQifgb6x10KLhQ1GD9x4kfF5Ap8sbrC0reG8sP0ehlT/yE0S7LvA07 iHMH9FCWTyL5UGsF/VEt2GSpKx+SEV28PXFx+L7DKAR+OCLb4ZCkTb5lDEImHAzruo3H UugA== X-Gm-Message-State: AOAM533GA0coyLo8T5QORr0gNK4uClSc3ic5abZf92rcXOUmffiaUPaj owWnXl2YQP7JyKW7AXMufvDRjnso+Y5KrV0Syzw= X-Received: by 2002:a05:6402:484:b0:415:d931:cb2f with SMTP id k4-20020a056402048400b00415d931cb2fmr14666889edv.287.1651515019042; Mon, 02 May 2022 11:10:19 -0700 (PDT) MIME-Version: 1.0 References: <20220418035110.GA937332@jaehee-ThinkPad-X1-Extreme> <87y200nf0a.fsf@kernel.org> In-Reply-To: <87y200nf0a.fsf@kernel.org> From: Jaehee Date: Mon, 2 May 2022 14:10:07 -0400 Message-ID: Subject: Re: [PATCH] wfx: use container_of() to get vif To: Kalle Valo Cc: =?UTF-8?B?SsOpcsO0bWUgUG91aWxsZXI=?= , "David S. Miller" , Jakub Kicinski , Paolo Abeni , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-staging@lists.linux.dev, Outreachy Linux Kernel , Stefano Brivio Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On Wed, Apr 20, 2022 at 7:58 AM Kalle Valo wrote: > > Jaehee Park 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 > > [...] > > > +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