rapidio: add check for rio_add_net() in rio_scan_alloc_net()

commit e842f9a1edf306bf36fe2a4d847a0b0d458770de upstream.

The return value of rio_add_net() should be checked.  If it fails,
put_device() should be called to free the memory and give up the reference
initialized in rio_add_net().

Link: https://lkml.kernel.org/r/[email protected]
Fixes: e6b585ca6e ("rapidio: move net allocation into core code")
Signed-off-by: Yang Yingliang <[email protected]>
Signed-off-by: Haoxiang Li <[email protected]>
Cc: Alexandre Bounine <[email protected]>
Cc: Matt Porter <[email protected]>
Cc: Dan Carpenter <[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 12:11:31 +08:00 • committed by Greg Kroah-Hartman
commit 6d22953c4a

View file

@ -873,7 +873,10 @@ static struct rio_net *rio_scan_alloc_net(struct rio_mport *mport,
dev_set_name(&net->dev, "rnet_%d", net->id);
net->dev.parent = &mport->dev;
net->dev.release = rio_scan_release_dev;
rio_add_net(net);
if (rio_add_net(net)) {
put_device(&net->dev);
net = NULL;
}
}
return net;