All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Breno Leitao <leitao@debian.org>
Cc: kvalo@kernel.org, linux-wireless@vger.kernel.org,
	Felix Fietkau <nbd@nbd.name>,
	Lorenzo Bianconi <lorenzo@kernel.org>,
	Ryder Lee <ryder.lee@mediatek.com>,
	Shayne Chen <shayne.chen@mediatek.com>,
	Sean Wang <sean.wang@mediatek.com>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	netdev@vger.kernel.org, kees@kernel.org, kuba@kernel.org,
	Bo Jiao <Bo.Jiao@mediatek.com>,
	Daniel Golle <daniel@makrotopia.org>,
	Alexander Couzens <lynxis@fe80.eu>,
	Deren Wu <deren.wu@mediatek.com>,
	Ming Yen Hsieh <mingyen.hsieh@mediatek.com>,
	Leon Yen <leon.yen@mediatek.com>,
	Quan Zhou <quan.zhou@mediatek.com>, Ingo Rohloff <lundril@gmx.de>,
	Sujuan Chen <sujuan.chen@mediatek.com>,
	StanleyYP Wang <StanleyYP.Wang@mediatek.com>,
	Benjamin Lin <benjamin-jw.lin@mediatek.com>,
	Peter Chiu <chui-hao.chiu@mediatek.com>,
	"open list:ARM/Mediatek SoC support"
	<linux-kernel@vger.kernel.org>,
	"moderated list:ARM/Mediatek SoC support"
	<linux-arm-kernel@lists.infradead.org>,
	"moderated list:ARM/Mediatek SoC support"
	<linux-mediatek@lists.infradead.org>
Subject: Re: [PATCH] wifi: mt76: un-embedd netdev from mt76_dev
Date: Sun, 16 Jun 2024 09:35:29 +0100	[thread overview]
Message-ID: <20240616083529.GH8447@kernel.org> (raw)
In-Reply-To: <20240614115317.657700-1-leitao@debian.org>

On Fri, Jun 14, 2024 at 04:52:42AM -0700, Breno Leitao wrote:
> Embedding net_device into structures prohibits the usage of flexible
> arrays in the net_device structure. For more details, see the discussion
> at [1].
> 
> Un-embed the net_devices from struct mt76_dev by converting them
> into pointers, and allocating them dynamically. Use the leverage
> alloc_netdev_dummy() to allocate the net_device object at
> mt76_dma_init().
> 
> The free of the device occurs at mt76_dma_cleanup().
> 
> Link: https://lore.kernel.org/all/20240229225910.79e224cf@kernel.org/ [1]
> Signed-off-by: Breno Leitao <leitao@debian.org>
> ---
> 
> PS: Due to the lack of hardware, this patch was not tested on a real
> hardware, unfortunately.
> 
> PS2: this is the last driver that is still using embedded netdevices.

...

> diff --git a/drivers/net/wireless/mediatek/mt76/dma.h b/drivers/net/wireless/mediatek/mt76/dma.h
> index 1de5a2b20f74..6454a5eca13e 100644
> --- a/drivers/net/wireless/mediatek/mt76/dma.h
> +++ b/drivers/net/wireless/mediatek/mt76/dma.h
> @@ -116,4 +116,9 @@ mt76_dma_should_drop_buf(bool *drop, u32 ctrl, u32 buf1, u32 info)
>  	}
>  }
>  
> +static inline struct mt76_dev *mt76_from_netdev(struct net_device *dev)
> +{
> +	return *(struct mt76_dev **)netdev_priv(dev);
> +}
> +
>  #endif

Hi Breno,

I agree that the above is correct, but I wonder if somehow it
is nicer to avoid explicit casts and instead take advantage of
implicit casting too and from void *.

Maybe something like this:

static inline struct mt76_dev *mt76_from_netdev(struct net_device *dev)
{
        struct mt76_dev **priv;

        priv = netdev_priv(dev);

        return *priv;
}

Further, some of the callers of mt76_from_netdev() cast the return value to
(struct mt7615_dev *). Which seems a bit awkward seeing as it was very
recently a void * (i.e. netdev_priv() returns void *).

I wonder if something like this makes sense, which I believe would avoid
the need for any callers to cast.

static inline void *mt76_priv(struct net_device *dev)
{
        struct mt76_dev **priv;

        priv = netdev_priv(dev);

        return *priv;
}

Ideas above compile tested only.

Other than the above, which is clearly more about style than substance,
this patch looks good to me.

Reviewed-by: Simon Horman <horms@kernel.org>



  reply	other threads:[~2024-06-16  8:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-14 11:52 [PATCH] wifi: mt76: un-embedd netdev from mt76_dev Breno Leitao
2024-06-16  8:35 ` Simon Horman [this message]
2024-06-17  9:03 ` Kalle Valo
2024-06-17  9:22   ` Breno Leitao
2024-06-17  9:29     ` Kalle Valo

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=20240616083529.GH8447@kernel.org \
    --to=horms@kernel.org \
    --cc=Bo.Jiao@mediatek.com \
    --cc=StanleyYP.Wang@mediatek.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=benjamin-jw.lin@mediatek.com \
    --cc=chui-hao.chiu@mediatek.com \
    --cc=daniel@makrotopia.org \
    --cc=deren.wu@mediatek.com \
    --cc=kees@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kvalo@kernel.org \
    --cc=leitao@debian.org \
    --cc=leon.yen@mediatek.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=lundril@gmx.de \
    --cc=lynxis@fe80.eu \
    --cc=matthias.bgg@gmail.com \
    --cc=mingyen.hsieh@mediatek.com \
    --cc=nbd@nbd.name \
    --cc=netdev@vger.kernel.org \
    --cc=quan.zhou@mediatek.com \
    --cc=ryder.lee@mediatek.com \
    --cc=sean.wang@mediatek.com \
    --cc=shayne.chen@mediatek.com \
    --cc=sujuan.chen@mediatek.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.