rapidio: fix an API misues when rio_add_net() fails

commit b2ef51c74b0171fde7eb69b6152d3d2f743ef269 upstream.

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.

Link: https://lkml.kernel.org/r/[email protected]
Fixes: e8de370188 ("rapidio: add mport char device driver")
Signed-off-by: Haoxiang Li <[email protected]>
Reviewed-by: Dan Carpenter <[email protected]>
Cc: Alexandre Bounine <[email protected]>
Cc: Matt Porter <[email protected]>
Cc: Yang Yingliang <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
This commit is contained in:
Haoxiang Li 2025-02-27 15:34:09 +08:00 • committed by Greg Kroah-Hartman
commit d4ec862ce8

View file

@ -1743,7 +1743,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;
}
}