If device_register() fails in fpga_bridge_register(), the bridge allocated by kzalloc() and the id allocated by ida_alloc() also need be freed otherwise will cause memory leak. Fixes: 0d70af3c2530 ("fpga: bridge: Use standard dev_release for class driver") Signed-off-by: Jinjie Ruan <ruanjinjie@xxxxxxxxxx> --- drivers/fpga/fpga-bridge.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/fpga/fpga-bridge.c b/drivers/fpga/fpga-bridge.c index a024be2b84e2..4a298656ce77 100644 --- a/drivers/fpga/fpga-bridge.c +++ b/drivers/fpga/fpga-bridge.c @@ -370,15 +370,15 @@ fpga_bridge_register(struct device *parent, const char *name, goto error_device; ret = device_register(&bridge->dev); - if (ret) { - put_device(&bridge->dev); - return ERR_PTR(ret); - } + if (ret) + goto error_put_device; of_platform_populate(bridge->dev.of_node, NULL, NULL, &bridge->dev); return bridge; +error_put_device: + put_device(&bridge->dev); error_device: ida_free(&fpga_bridge_ida, id); error_kfree: -- 2.34.1