All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Koichiro Den" <den@valinux.co.jp>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH v3 3/5] PCI: endpoint: Add API to delegate EPC DMA channels to the host
Date: Sat, 20 Jun 2026 17:26:00 +0000	[thread overview]
Message-ID: <20260620172600.E8B5F1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260620170438.3756593-4-den@valinux.co.jp>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Error pointer dereference in `pci_epc_delegate_dma_chan` due to incorrect validation order.
--

commit b5fefb01d3a350b55650bc026830cacbecfcc978
Author: Koichiro Den <den@valinux.co.jp>

PCI: endpoint: Add API to delegate EPC DMA channels to the host

This commit adds pci_epc_delegate_dma_chan() and pci_epc_reclaim_dma_chan()
to allow generic endpoint functions to delegate integrated DMA channels to
the host. It introduces matching EPC operations and uses an opaque handle
for channel state management to avoid backend-specific dependencies.

> diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
> index 831b40458dcd8..0f71c4633ee54 100644
> --- a/drivers/pci/endpoint/pci-epc-core.c
> +++ b/drivers/pci/endpoint/pci-epc-core.c

[ ... ]

> @@ -236,6 +243,99 @@ int pci_epc_get_aux_resources(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
>  }
>  EXPORT_SYMBOL_GPL(pci_epc_get_aux_resources);
>  
> +/**
> + * pci_epc_delegate_dma_chan() - delegate an EPC-owned DMA channel to the host

[ ... ]

> +int pci_epc_delegate_dma_chan(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
> +			      enum pci_epc_aux_dma_dir dir, u16 hw_ch,
> +			      struct pci_epc_dma_chan **chan)
> +{
> +	struct pci_epc_dma_chan *epc_chan;
> +	void *data = NULL;
> +	int ret;
> +
> +	if (!chan)
> +		return -EINVAL;
> +	*chan = NULL;
> +
> +	if (!epc || !epc->ops)
> +		return -EINVAL;

[Severity: High]
If a caller passes an error pointer for epc, will the !epc->ops check
trigger a crash?

Functions like pci_epc_get() return ERR_PTR(-EINVAL) on failure rather
than NULL. If epc is an error pointer, the !epc check evaluates to false,
causing execution to proceed to the !epc->ops check. Dereferencing epc->ops
on an error pointer will trigger a kernel crash.

> +
> +	if (!pci_epc_function_is_valid(epc, func_no, vfunc_no))
> +		return -EINVAL;

The subsequent call to pci_epc_function_is_valid() internally uses
IS_ERR_OR_NULL(epc) to safely handle error pointers, but placing the ops
dereference before it circumvents this safety.

Would it be better to move the pci_epc_function_is_valid() check before
dereferencing epc->ops, or explicitly check IS_ERR_OR_NULL(epc) first?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260620170438.3756593-1-den@valinux.co.jp?part=3

  reply	other threads:[~2026-06-20 17:26 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-20 17:04 [PATCH v3 0/5] PCI: endpoint: Expose endpoint DMA resources (part 2/3) Koichiro Den
2026-06-20 17:04 ` [PATCH v3 1/5] PCI: endpoint: Define endpoint DMA BAR metadata format Koichiro Den
2026-06-20 17:10   ` sashiko-bot
2026-06-20 17:04 ` [PATCH v3 2/5] PCI: endpoint: Add DMA auxiliary resource metadata Koichiro Den
2026-06-20 17:09   ` sashiko-bot
2026-06-20 17:04 ` [PATCH v3 3/5] PCI: endpoint: Add API to delegate EPC DMA channels to the host Koichiro Den
2026-06-20 17:26   ` sashiko-bot [this message]
2026-06-20 17:04 ` [PATCH v3 4/5] PCI: dwc: Expose endpoint DMA resources Koichiro Den
2026-06-20 17:14   ` sashiko-bot
2026-06-20 17:04 ` [PATCH v3 5/5] PCI: dwc: Implement endpoint DMA channel delegation Koichiro Den
2026-06-20 17:16   ` sashiko-bot

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=20260620172600.E8B5F1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=den@valinux.co.jp \
    --cc=linux-pci@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.