Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] iommu/apple-dart: Properly check the error
@ 2026-11-30 11:04 Anton Protopopov
  0 siblings, 0 replies; only message in thread
From: Anton Protopopov @ 2026-11-30 11:04 UTC (permalink / raw)
  To: Sven Peter, Joerg Roedel, Will Deacon, Janne Grunau, Neal Gompa,
	Robin Murphy, iommu, asahi, linux-arm-kernel
  Cc: Anton Protopopov

The apple_dart_device_group() function expects pci_device_group()
(or generic_device_group() for a non-PCI device) to return NULL on
failure. However, both of them return an error pointer instead of
NULL. The error pointer then is immediately dereferenced by the
iommu_group_get_iommudata() function.

Check for an error pointer instead of NULL and return the error.
Small related change: the kmemdup() error path relied on res
holding ERR_PTR(-ENOMEM), so set it there explicitly, as the
function does in other places.

Fixes: f0b636804c7c ("iommu/dart: Clear sid2group entry when a group is freed")
Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
---

v1 -> v2:
- Return -ENOMEM again when kmemdup() fails; v1 returned the group
  after dropping its reference.

 drivers/iommu/apple-dart.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
index d8302128b465..779be265acbe 100644
--- a/drivers/iommu/apple-dart.c
+++ b/drivers/iommu/apple-dart.c
@@ -981,9 +981,10 @@ static struct iommu_group *apple_dart_device_group(struct device *dev)
 #endif
 		group = generic_device_group(dev);
 
-	res = ERR_PTR(-ENOMEM);
-	if (!group)
+	if (IS_ERR(group)) {
+		res = group;
 		goto out;
+	}
 
 	group_master_cfg = iommu_group_get_iommudata(group);
 	if (group_master_cfg) {
@@ -1001,6 +1002,7 @@ static struct iommu_group *apple_dart_device_group(struct device *dev)
 					   GFP_KERNEL);
 		if (!group_master_cfg) {
 			iommu_group_put(group);
+			res = ERR_PTR(-ENOMEM);
 			goto out;
 		}
 


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-30 10:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 11:04 [PATCH v2] iommu/apple-dart: Properly check the error Anton Protopopov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox