Re: [PATCH] rapidio: fix a resource leak when rio_add_device() fails

From: Greg KH

Date: Sun Dec 21 2025 - 07:20:10 EST


On Sun, Dec 21, 2025 at 08:05:38PM +0800, Haoxiang Li wrote:
> If rio_add_device() fails, call rio_free_net() to unregister
> the net device registered by rio_add_net().
>
> Fixes: e8de370188d0 ("rapidio: add mport char device driver")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Haoxiang Li <lihaoxiang@xxxxxxxxxxxxxxxx>
> ---
> drivers/rapidio/devices/rio_mport_cdev.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/rapidio/devices/rio_mport_cdev.c b/drivers/rapidio/devices/rio_mport_cdev.c
> index 995cfeca972b..4a804b4ad6f7 100644
> --- a/drivers/rapidio/devices/rio_mport_cdev.c
> +++ b/drivers/rapidio/devices/rio_mport_cdev.c
> @@ -1789,6 +1789,7 @@ static int rio_mport_add_riodev(struct mport_cdev_priv *priv,
> err = rio_add_device(rdev);
> if (err) {
> put_device(&rdev->dev);
> + rio_free_net(net);
> return err;

Are you sure this is right? You aren't checking that rio_add_net() was
actually called. How was this tested? How was this found? What tool
was used to find it?

thanks,

greg k-h