Skip to content

Commit 95deee3

Browse files
Will McVickergregkh
authored andcommitted
platform: Fix race condition during DMA configure at IOMMU probe time
To avoid a race between the IOMMU probing thread and the device driver async probing thread during configuration of the platform DMA, update `platform_dma_configure()` to read `dev->driver` once and test if it's NULL before using it. This ensures that we don't de-reference an invalid platform driver pointer if the device driver is asynchronously bound while configuring the DMA. Fixes: bcb81ac ("iommu: Get DT/ACPI parsing into the proper probe path") Signed-off-by: Will McVicker <willmcvicker@google.com> Reviewed-by: Robin Murphy <robin.murphy@arm.com> Link: https://lore.kernel.org/r/20250424180420.3928523-1-willmcvicker@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b443265 commit 95deee3

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/base/platform.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,7 @@ static void platform_shutdown(struct device *_dev)
14401440

14411441
static int platform_dma_configure(struct device *dev)
14421442
{
1443-
struct platform_driver *drv = to_platform_driver(dev->driver);
1443+
struct device_driver *drv = READ_ONCE(dev->driver);
14441444
struct fwnode_handle *fwnode = dev_fwnode(dev);
14451445
enum dev_dma_attr attr;
14461446
int ret = 0;
@@ -1451,8 +1451,8 @@ static int platform_dma_configure(struct device *dev)
14511451
attr = acpi_get_dma_attr(to_acpi_device_node(fwnode));
14521452
ret = acpi_dma_configure(dev, attr);
14531453
}
1454-
/* @drv may not be valid when we're called from the IOMMU layer */
1455-
if (ret || !dev->driver || drv->driver_managed_dma)
1454+
/* @dev->driver may not be valid when we're called from the IOMMU layer */
1455+
if (ret || !drv || to_platform_driver(drv)->driver_managed_dma)
14561456
return ret;
14571457

14581458
ret = iommu_device_use_default_domain(dev);

0 commit comments

Comments
 (0)