From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15C43C433F5 for ; Wed, 4 May 2022 11:51:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348991AbiEDLys (ORCPT ); Wed, 4 May 2022 07:54:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242743AbiEDLyp (ORCPT ); Wed, 4 May 2022 07:54:45 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C487B2CC91 for ; Wed, 4 May 2022 04:51:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651665067; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tavZwp8BQxfV8UeYb9Xzxs1vfyyi2W9B0pF5sD/TmHM=; b=WI5pX6tG4lNc7dxOy93ZoXp5L7SbxxBiHZTdWQ7MpkZ7AVZDNgiBAGXnOzNLJig3OzuJsv vYreRLanyHBZijceZxPN3ixLSrVDkK2ZBqPvePrO+9xf/S1FrYaE9EAdPP7tnmPq9aLKjs q7fXdz0qdMlw6d19gDNG1i61E+ET5j8= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-502-BxHj2Dx6M5On6y-X0LgeIw-1; Wed, 04 May 2022 07:51:06 -0400 X-MC-Unique: BxHj2Dx6M5On6y-X0LgeIw-1 Received: by mail-ej1-f71.google.com with SMTP id l20-20020a170906795400b006f3f30daf18so682221ejo.22 for ; Wed, 04 May 2022 04:51:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:organization:mime-version:content-transfer-encoding; bh=tavZwp8BQxfV8UeYb9Xzxs1vfyyi2W9B0pF5sD/TmHM=; b=q4DCzi1yURlzJT5kxNdQ8aZVCb/ewTfdNVw0rYwYNsfN5ZQ+rFkLaVbaqWPrVH0qQN qqEYxexv4hC64faKf+b88OrCX/ZvoQn4DcGYCwF9fU+WNMRVuw5pXQM5TbtkPEitlTBe KhVRpwK2hbuSz1lwOXw4mAPZ0C7l2wVLCTgTsPRc9KoaZ6ChvrdxRnP2EebGWIfNQx00 9HHGCwQP3Is8F/klgUsbydhzM/I0VFgmLrHph8GY90dmrQkN1s5+DEjRvYovRhuehN0h CdE3LZ5r/+ZqC5DN4zYFm7tDv05UiCOkRrUznUMBCxxCpm+xFNR5iLXmkctvtDWjBI5T nvpg== X-Gm-Message-State: AOAM533I1MIZ5rXv3Vr1ZpXJvo4kIyHEv0cIBh3uqG580mXlnTJpGiDl 6wLZQtec6Wq1lJV8/p5ZQDO9IoZZ/neoqgZBAlgVn29eFNnXGR1UQaTeIG//OwGhnj4o0pnh76d e360rVDGaojpPxo2aV1lctV2A X-Received: by 2002:a17:906:3fd1:b0:6ef:606f:e5c5 with SMTP id k17-20020a1709063fd100b006ef606fe5c5mr19216834ejj.441.1651665065700; Wed, 04 May 2022 04:51:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfylvO+VKVVbzY5ASXCx0ehCojnDyP/xtWqHiM66c5/brxEnt1fwNb2R3LeYpLzPIIxvzLhQ== X-Received: by 2002:a17:906:3fd1:b0:6ef:606f:e5c5 with SMTP id k17-20020a1709063fd100b006ef606fe5c5mr19216817ejj.441.1651665065489; Wed, 04 May 2022 04:51:05 -0700 (PDT) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [2a02:2770:5:0:21a:4aff:fe98:d313]) by smtp.gmail.com with ESMTPSA id el8-20020a170907284800b006f3ef214e12sm5674426ejc.120.2022.05.04.04.51.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 May 2022 04:51:04 -0700 (PDT) Date: Wed, 4 May 2022 13:50:59 +0200 From: Stefano Brivio To: Dan Carpenter Cc: Jaehee , Kalle Valo , =?UTF-8?B?SsOpcsO0bWU=?= Pouiller , "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 Subject: Re: [PATCH] wfx: use container_of() to get vif Message-ID: <20220504135059.7132b2b6@elisabeth> In-Reply-To: <20220504093347.GB4009@kadam> References: <20220418035110.GA937332@jaehee-ThinkPad-X1-Extreme> <87y200nf0a.fsf@kernel.org> <20220504093347.GB4009@kadam> Organization: Red Hat X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Dan, On Wed, 4 May 2022 12:33:48 +0300 Dan Carpenter wrote: > On Mon, May 02, 2022 at 02:10:07PM -0400, Jaehee wrote: > > 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: > > 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. -- Stefano