From: Jie Liu <[email protected]>

sxe2_classes_driver_remove() calls cdrv->remove(cdev) without
checking whether cdrv or cdrv->remove is NULL. If the class driver
was never probed, cdev->cdrv remains NULL, and the unconditional
call dereferences a NULL pointer, crashing during device removal.

Add NULL checks for cdrv and cdrv->remove, returning 0 when either
is NULL.

Fixes: 83866f8d76 ("common/sxe2: add base driver skeleton")
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Jie Liu <[email protected]>
---
 drivers/common/sxe2/sxe2_common.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/common/sxe2/sxe2_common.c 
b/drivers/common/sxe2/sxe2_common.c
index 5c5db85f29..6e387a8a73 100644
--- a/drivers/common/sxe2/sxe2_common.c
+++ b/drivers/common/sxe2/sxe2_common.c
@@ -465,8 +465,12 @@ static int32_t sxe2_classes_driver_probe(struct 
sxe2_common_device *cdev,
 static int32_t sxe2_classes_driver_remove(struct sxe2_common_device *cdev)
 {
        struct sxe2_class_driver *cdrv = cdev->cdrv;
+       int32_t ret = 0;
+
+       if (cdrv != NULL && cdrv->remove != NULL)
+               ret = cdrv->remove(cdev);
 
-       return cdrv->remove(cdev);
+       return ret;
 }
 
 static int32_t sxe2_kvargs_validate(struct sxe2_dev_kvargs_info *kv_info)
-- 
2.52.0

Reply via email to