[PATCH v2] rapidio: fix an API misues when rio_add_net() fails
From: Haoxiang Li
Date: Thu Feb 27 2025 - 02:34:44 EST
rio_add_net() calls device_register() and fails when device_register()
fails. Thus, put_device() should be used rather than kfree().
Add "mport->net = NULL;" to avoid a use after free issue.
Fixes: e8de370188d0 ("rapidio: add mport char device driver")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Haoxiang Li <haoxiang_li2024@xxxxxxx>
---
Changes in v2:
- Add "mport->net = NULL;" to avoid a use after free issue. Thanks, Dan!
---
drivers/rapidio/devices/rio_mport_cdev.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/rapidio/devices/rio_mport_cdev.c b/drivers/rapidio/devices/rio_mport_cdev.c
index 27afbb9d544b..cbf531d0ba68 100644
--- a/drivers/rapidio/devices/rio_mport_cdev.c
+++ b/drivers/rapidio/devices/rio_mport_cdev.c
@@ -1742,7 +1742,8 @@ static int rio_mport_add_riodev(struct mport_cdev_priv *priv,
err = rio_add_net(net);
if (err) {
rmcd_debug(RDEV, "failed to register net, err=%d", err);
- kfree(net);
+ put_device(&net->dev);
+ mport->net = NULL;
goto cleanup;
}
}
--
2.25.1