Search Linux Wireless

Re: [PATCH] wifi: mt76: un-embedd netdev from mt76_dev

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx/ [1]
> Signed-off-by: Breno Leitao <leitao@xxxxxxxxxx>
> ---
> 
> 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@xxxxxxxxxx>





[Index of Archives]     [Linux Host AP]     [ATH6KL]     [Linux Wireless Personal Area Network]     [Linux Bluetooth]     [Wireless Regulations]     [Linux Netdev]     [Kernel Newbies]     [Linux Kernel]     [IDE]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite Hiking]     [MIPS Linux]     [ARM Linux]     [Linux RAID]

  Powered by Linux