From: David Marchand <david.marchand@redhat.com>
To: dev@dpdk.org
Cc: thomas@monjalon.net, stephen@networkplumber.org,
bruce.richardson@intel.com, Parav Pandit <parav@nvidia.com>,
Xueming Li <xuemingl@nvidia.com>, Chenbo Xia <chenbox@nvidia.com>,
Nipun Gupta <nipun.gupta@amd.com>,
Tomasz Duszynski <tduszynski@marvell.com>
Subject: [PATCH v2 03/23] bus: remove device and driver checks in DMA map/unmap
Date: Wed, 6 May 2026 17:51:35 +0200 [thread overview]
Message-ID: <20260506155201.2709810-4-david.marchand@redhat.com> (raw)
In-Reply-To: <20260506155201.2709810-1-david.marchand@redhat.com>
Add rte_dev_is_probed() check in rte_dev_dma_map() and
rte_dev_dma_unmap() before calling bus-specific implementations.
The device parameter passed to bus DMA map/unmap operations cannot be
NULL as the caller already dereferenced the bus structure to invoke
these operations.
The driver reference in the bus-specific device cannot be NULL since
calling the .dma_map is done after dereferencing this pointer.
Remove redundant checks on probed device, and NULL checks on the
device/driver parameter and derived device/driver pointers.
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
drivers/bus/auxiliary/auxiliary_common.c | 8 --------
drivers/bus/pci/pci_common.c | 12 ++----------
drivers/bus/platform/platform.c | 16 ++--------------
drivers/bus/vdev/vdev.c | 24 ++----------------------
lib/eal/common/eal_common_dev.c | 8 ++++++++
5 files changed, 14 insertions(+), 54 deletions(-)
diff --git a/drivers/bus/auxiliary/auxiliary_common.c b/drivers/bus/auxiliary/auxiliary_common.c
index 8f3e90eaf0..9690687600 100644
--- a/drivers/bus/auxiliary/auxiliary_common.c
+++ b/drivers/bus/auxiliary/auxiliary_common.c
@@ -356,10 +356,6 @@ auxiliary_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
{
struct rte_auxiliary_device *aux_dev = RTE_DEV_TO_AUXILIARY(dev);
- if (dev == NULL || aux_dev->driver == NULL) {
- rte_errno = EINVAL;
- return -1;
- }
if (aux_dev->driver->dma_map == NULL) {
rte_errno = ENOTSUP;
return -1;
@@ -373,10 +369,6 @@ auxiliary_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova,
{
struct rte_auxiliary_device *aux_dev = RTE_DEV_TO_AUXILIARY(dev);
- if (dev == NULL || aux_dev->driver == NULL) {
- rte_errno = EINVAL;
- return -1;
- }
if (aux_dev->driver->dma_unmap == NULL) {
rte_errno = ENOTSUP;
return -1;
diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c
index 51fd8c80e4..d7f028e365 100644
--- a/drivers/bus/pci/pci_common.c
+++ b/drivers/bus/pci/pci_common.c
@@ -672,11 +672,7 @@ pci_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
{
struct rte_pci_device *pdev = RTE_DEV_TO_PCI(dev);
- if (!pdev || !pdev->driver) {
- rte_errno = EINVAL;
- return -1;
- }
- if (pdev->driver->dma_map)
+ if (pdev->driver->dma_map != NULL)
return pdev->driver->dma_map(pdev, addr, iova, len);
/**
* In case driver don't provides any specific mapping
@@ -695,11 +691,7 @@ pci_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
{
struct rte_pci_device *pdev = RTE_DEV_TO_PCI(dev);
- if (!pdev || !pdev->driver) {
- rte_errno = EINVAL;
- return -1;
- }
- if (pdev->driver->dma_unmap)
+ if (pdev->driver->dma_unmap != NULL)
return pdev->driver->dma_unmap(pdev, addr, iova, len);
/**
* In case driver don't provides any specific mapping
diff --git a/drivers/bus/platform/platform.c b/drivers/bus/platform/platform.c
index e54098d04f..8a89a3cad8 100644
--- a/drivers/bus/platform/platform.c
+++ b/drivers/bus/platform/platform.c
@@ -530,13 +530,7 @@ platform_bus_parse(const char *name, void *addr)
static int
platform_bus_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
{
- struct rte_platform_device *pdev;
-
- pdev = RTE_DEV_TO_PLATFORM_DEV(dev);
- if (pdev == NULL || pdev->driver == NULL) {
- rte_errno = EINVAL;
- return -1;
- }
+ struct rte_platform_device *pdev = RTE_DEV_TO_PLATFORM_DEV(dev);
if (pdev->driver->dma_map != NULL)
return pdev->driver->dma_map(pdev, addr, iova, len);
@@ -547,13 +541,7 @@ platform_bus_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t l
static int
platform_bus_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
{
- struct rte_platform_device *pdev;
-
- pdev = RTE_DEV_TO_PLATFORM_DEV(dev);
- if (pdev == NULL || pdev->driver == NULL) {
- rte_errno = EINVAL;
- return -1;
- }
+ struct rte_platform_device *pdev = RTE_DEV_TO_PLATFORM_DEV(dev);
if (pdev->driver->dma_unmap != NULL)
return pdev->driver->dma_unmap(pdev, addr, iova, len);
diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c
index eb1de0186e..a200a67847 100644
--- a/drivers/bus/vdev/vdev.c
+++ b/drivers/bus/vdev/vdev.c
@@ -144,20 +144,10 @@ vdev_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
struct rte_vdev_device *vdev = RTE_DEV_TO_VDEV(dev);
const struct rte_vdev_driver *driver;
- if (!vdev) {
- rte_errno = EINVAL;
- return -1;
- }
-
- if (!vdev->device.driver) {
- VDEV_LOG(DEBUG, "no driver attach to device %s", dev->name);
- return 1;
- }
-
driver = container_of(vdev->device.driver, const struct rte_vdev_driver,
driver);
- if (driver->dma_map)
+ if (driver->dma_map != NULL)
return driver->dma_map(vdev, addr, iova, len);
return 0;
@@ -169,20 +159,10 @@ vdev_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
struct rte_vdev_device *vdev = RTE_DEV_TO_VDEV(dev);
const struct rte_vdev_driver *driver;
- if (!vdev) {
- rte_errno = EINVAL;
- return -1;
- }
-
- if (!vdev->device.driver) {
- VDEV_LOG(DEBUG, "no driver attach to device %s", dev->name);
- return 1;
- }
-
driver = container_of(vdev->device.driver, const struct rte_vdev_driver,
driver);
- if (driver->dma_unmap)
+ if (driver->dma_unmap != NULL)
return driver->dma_unmap(vdev, addr, iova, len);
return 0;
diff --git a/lib/eal/common/eal_common_dev.c b/lib/eal/common/eal_common_dev.c
index 7185de0cb9..fceca75223 100644
--- a/lib/eal/common/eal_common_dev.c
+++ b/lib/eal/common/eal_common_dev.c
@@ -829,6 +829,10 @@ int
rte_dev_dma_map(struct rte_device *dev, void *addr, uint64_t iova,
size_t len)
{
+ if (!rte_dev_is_probed(dev)) {
+ rte_errno = EINVAL;
+ return -1;
+ }
if (dev->bus->dma_map == NULL || len == 0) {
rte_errno = ENOTSUP;
return -1;
@@ -847,6 +851,10 @@ int
rte_dev_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova,
size_t len)
{
+ if (!rte_dev_is_probed(dev)) {
+ rte_errno = EINVAL;
+ return -1;
+ }
if (dev->bus->dma_unmap == NULL || len == 0) {
rte_errno = ENOTSUP;
return -1;
--
2.53.0
next prev parent reply other threads:[~2026-05-06 15:52 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-29 11:44 [PATCH 00/23] Consolidate bus driver infrastructure David Marchand
2026-04-29 11:44 ` [PATCH 01/23] bus/ifpga: remove unused AFU lookup helper David Marchand
2026-04-29 11:44 ` [PATCH 02/23] crypto/octeontx: remove check on driver in remove David Marchand
2026-04-29 11:59 ` [EXTERNAL] " Anoob Joseph
2026-04-29 11:44 ` [PATCH 03/23] bus: remove device and driver checks in DMA map/unmap David Marchand
2026-04-29 11:44 ` [PATCH 04/23] drivers/bus: remove device and driver checks in unplug David Marchand
2026-04-29 11:44 ` [PATCH 05/23] drivers/bus: remove device and driver checks in plug David Marchand
2026-04-29 11:44 ` [PATCH 06/23] bus: add bus conversion macros David Marchand
2026-04-29 11:44 ` [PATCH 07/23] bus: factorize driver list David Marchand
2026-04-29 11:44 ` [PATCH 08/23] bus: factorize device list David Marchand
2026-04-29 11:44 ` [PATCH 09/23] bus: consolidate device lookup David Marchand
2026-04-29 11:44 ` [PATCH 10/23] bus: consolidate device iteration David Marchand
2026-04-29 11:44 ` [PATCH 11/23] bus: factorize driver lookup David Marchand
2026-04-29 11:44 ` [PATCH 12/23] bus: refactor device probe David Marchand
2026-04-29 11:44 ` [PATCH 13/23] bus: support multiple probe David Marchand
2026-04-29 11:44 ` [PATCH 14/23] drivers/bus: initialize NXP bus specifics in scan David Marchand
2026-04-29 11:44 ` [PATCH 15/23] bus: implement probe in EAL David Marchand
2026-04-29 11:44 ` [PATCH 16/23] bus: factorize driver reference David Marchand
2026-04-29 11:44 ` [PATCH 17/23] drivers: rely on generic driver David Marchand
2026-04-29 11:44 ` [PATCH 18/23] drivers/bus: remove bus-specific driver references David Marchand
2026-04-29 11:44 ` [PATCH 19/23] dma/idxd: remove specific bus type David Marchand
2026-04-29 11:44 ` [PATCH 20/23] drivers/bus: separate specific bus metadata for NXP drivers David Marchand
2026-04-29 11:44 ` [PATCH 21/23] drivers/bus: remove specific bus types David Marchand
2026-04-29 11:44 ` [PATCH 22/23] eventdev: rename dev field to device David Marchand
2026-04-29 11:44 ` [PATCH 23/23] bus: add class device conversion macro David Marchand
2026-05-06 15:51 ` [PATCH v2 00/23] Consolidate bus driver infrastructure David Marchand
2026-05-06 15:51 ` [PATCH v2 01/23] bus/ifpga: remove unused AFU lookup helper David Marchand
2026-05-06 15:51 ` [PATCH v2 02/23] crypto/octeontx: remove check on driver in remove David Marchand
2026-05-06 15:51 ` David Marchand [this message]
2026-05-06 15:51 ` [PATCH v2 04/23] drivers/bus: remove device and driver checks in unplug David Marchand
2026-05-06 15:51 ` [PATCH v2 05/23] drivers/bus: remove device and driver checks in plug David Marchand
2026-05-06 15:51 ` [PATCH v2 06/23] bus: add bus conversion macros David Marchand
2026-05-06 15:51 ` [PATCH v2 07/23] bus: factorize driver list David Marchand
2026-05-06 15:51 ` [PATCH v2 08/23] bus: factorize device list David Marchand
2026-05-06 15:51 ` [PATCH v2 09/23] bus: consolidate device lookup David Marchand
2026-05-06 15:51 ` [PATCH v2 10/23] bus: consolidate device iteration David Marchand
2026-05-06 15:51 ` [PATCH v2 11/23] bus: factorize driver lookup David Marchand
2026-05-06 15:51 ` [PATCH v2 12/23] bus: refactor device probe David Marchand
2026-05-06 15:51 ` [PATCH v2 13/23] bus: support multiple probe David Marchand
2026-05-06 15:51 ` [PATCH v2 14/23] drivers/bus: initialize NXP bus specifics in scan David Marchand
2026-05-06 15:51 ` [PATCH v2 15/23] bus: implement probe in EAL David Marchand
2026-05-06 15:51 ` [PATCH v2 16/23] bus: factorize driver reference David Marchand
2026-05-06 15:51 ` [PATCH v2 17/23] drivers: rely on generic driver David Marchand
2026-05-06 15:51 ` [PATCH v2 18/23] drivers/bus: remove bus-specific driver references David Marchand
2026-05-06 15:51 ` [PATCH v2 19/23] dma/idxd: remove specific bus type David Marchand
2026-05-06 15:51 ` [PATCH v2 20/23] drivers/bus: separate specific bus metadata for NXP drivers David Marchand
2026-05-06 15:51 ` [PATCH v2 21/23] drivers/bus: remove specific bus types David Marchand
2026-05-06 15:51 ` [PATCH v2 22/23] eventdev: rename dev field to device David Marchand
2026-05-06 15:51 ` [PATCH v2 23/23] bus: add class device conversion macro David Marchand
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=20260506155201.2709810-4-david.marchand@redhat.com \
--to=david.marchand@redhat.com \
--cc=bruce.richardson@intel.com \
--cc=chenbox@nvidia.com \
--cc=dev@dpdk.org \
--cc=nipun.gupta@amd.com \
--cc=parav@nvidia.com \
--cc=stephen@networkplumber.org \
--cc=tduszynski@marvell.com \
--cc=thomas@monjalon.net \
--cc=xuemingl@nvidia.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