From: Jakub Kicinski <kuba@kernel.org>
To: michael.dege@renesas.com
Cc: Jakub Kicinski <kuba@kernel.org>,
yoshihiro.shimoda.uh@renesas.com, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@google.com, pabeni@redhat.com,
niklas.soderlund@ragnatech.se, paul@pbarker.dev,
netdev@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v4 02/13] net: renesas: rswitch: use device instead of net_device
Date: Tue, 12 May 2026 18:35:49 -0700 [thread overview]
Message-ID: <20260513013549.1408370-1-kuba@kernel.org> (raw)
In-Reply-To: <20260511-rswitch_add_vlans-v4-2-a5a225f8faae@renesas.com>
This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
net: renesas: rswitch: use device instead of net_device
This commit updates the driver to use struct device instead of struct
net_device for queue allocation and freeing. This prepares the code for
upcoming VLAN support where the net_device might not always be available.
> diff --git a/drivers/net/ethernet/renesas/rswitch_main.c b/drivers/net/ethernet/renesas/rswitch_main.c
> --- a/drivers/net/ethernet/renesas/rswitch_main.c
> +++ b/drivers/net/ethernet/renesas/rswitch_main.c
> @@ -304,13 +304,13 @@ static int rswitch_gwca_queue_alloc_rx_buf(struct rswitch_gwca_queue *gq,
> return -ENOMEM;
> }
>
> -static void rswitch_gwca_queue_free(struct net_device *ndev,
> +static void rswitch_gwca_queue_free(struct device *dev,
> struct rswitch_gwca_queue *gq)
> {
> unsigned int i;
>
> if (!gq->dir_tx) {
> - dma_free_coherent(ndev->dev.parent,
> + dma_free_coherent(dev,
> sizeof(struct rswitch_ext_ts_desc) *
> (gq->ring_size + 1), gq->rx_ring, gq->ring_dma);
This wasn't introduced by this patch, but if rswitch_gwca_queue_alloc()
fails during or before the dma_alloc_coherent() step, gq->rx_ring will
remain NULL.
Since dma_free_coherent() is not guaranteed to handle NULL virtual
addresses safely across all architectures, could this pass a NULL pointer
and cause a crash? Does it make sense to conditionalize the frees here
and in the tx path?
> gq->rx_ring = NULL;
I notice another pre-existing issue in the unquoted context just below
this. When rswitch_gwca_queue_alloc() fails, gq->rx_bufs can contain NULL
pointers.
Since the loop calls skb_free_frag(gq->rx_bufs[i]), and skb_free_frag()
wraps page_frag_free() which does not check for NULL, would this result
in an out-of-bounds page struct dereference and a kernel panic?
Would it be safer to add a NULL check before calling skb_free_frag()?
[ ... ]
> @@ -508,7 +506,7 @@ static int rswitch_gwca_queue_ext_ts_fill(struct net_device *ndev,
> index = (i + start_index) % gq->ring_size;
> desc = &gq->rx_ring[index];
> dma_addr = rswitch_desc_get_dptr(&desc->desc);
> - dma_unmap_single(ndev->dev.parent, dma_addr,
> + dma_unmap_single(dev, dma_addr,
> RSWITCH_MAP_BUF_SIZE, DMA_FROM_DEVICE);
> }
> }
I noticed a concurrency issue in this pre-existing error path. Earlier in
this function, the driver transfers ownership of each descriptor to the
hardware by setting desc->desc.die_dt and executing a dma_wmb().
If a subsequent dma_map_single() fails, this error path unmaps the
previously mapped buffers but does not revoke hardware ownership by
clearing desc->desc.die_dt.
Because the hardware was already granted ownership, could it actively DMA
incoming packets into the unmapped memory before the device is finally
halted? Would it be safer to clear the ownership flag and issue a memory
barrier before unmapping the buffers?
--
pw-bot: cr
next prev parent reply other threads:[~2026-05-13 1:35 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-11 8:52 [net-next PATCH v4 00/13] net: renesas: rswitch: R-Car S4 add VLAN aware switching Michael Dege
2026-05-11 8:52 ` [PATCH net-next v4 01/13] net: renesas: rswitch: improve port change mode functions Michael Dege
2026-05-11 8:52 ` [PATCH net-next v4 02/13] net: renesas: rswitch: use device instead of net_device Michael Dege
2026-05-13 1:35 ` Jakub Kicinski [this message]
2026-05-11 8:52 ` [PATCH net-next v4 03/13] net: renesas: rswitch: fix FWPC2 register access macros Michael Dege
2026-05-11 8:52 ` [PATCH net-next v4 04/13] net: renesas: rswitch: add register definitions for vlan support Michael Dege
2026-05-11 8:52 ` [PATCH net-next v4 05/13] net: renesas: rswitch: add exception path for packets with unknown dst MAC Michael Dege
2026-05-13 1:35 ` Jakub Kicinski
2026-05-13 1:37 ` Jakub Kicinski
2026-05-11 8:52 ` [PATCH net-next v4 06/13] net: renesas: rswitch: add forwarding rules for gwca Michael Dege
2026-05-11 8:52 ` [PATCH net-next v4 07/13] net: renesas: rswitch: make helper functions available to whole driver Michael Dege
2026-05-13 1:35 ` Jakub Kicinski
2026-05-11 8:52 ` [PATCH net-next v4 08/13] net: renesas: rswitch: add basic vlan init to rswitch_fwd_init Michael Dege
2026-05-11 8:52 ` [PATCH net-next v4 09/13] net: renesas: rswitch: update port HW init Michael Dege
2026-05-13 1:35 ` Jakub Kicinski
2026-05-11 8:52 ` [PATCH net-next v4 10/13] net: renesas: rswitch: clean up is_rdev rswitch_device checking Michael Dege
2026-05-13 1:35 ` Jakub Kicinski
2026-05-11 8:52 ` [PATCH net-next v4 11/13] net: renesas: rswitch: add passing of rswitch_private into notifiers Michael Dege
2026-05-13 1:35 ` Jakub Kicinski
2026-05-11 8:52 ` [PATCH net-next v4 12/13] net: renesas: rswitch: add handler for FDB notification Michael Dege
2026-05-13 1:35 ` Jakub Kicinski
2026-05-11 8:52 ` [PATCH net-next v4 13/13] net: renesas: rswitch: add vlan aware switching Michael Dege
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=20260513013549.1408370-1-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=michael.dege@renesas.com \
--cc=netdev@vger.kernel.org \
--cc=niklas.soderlund@ragnatech.se \
--cc=pabeni@redhat.com \
--cc=paul@pbarker.dev \
--cc=yoshihiro.shimoda.uh@renesas.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox