If device_register() fails in fpga_region_register_full(), the region allocated by kzalloc() and the id allocated by ida_alloc() also need be freed otherwise will cause memory leak. Fixes: 8886a579744f ("fpga: region: Use standard dev_release for class driver") Signed-off-by: Jinjie Ruan <ruanjinjie@xxxxxxxxxx> --- drivers/fpga/fpga-region.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/fpga/fpga-region.c b/drivers/fpga/fpga-region.c index b364a929425c..9dc6314976ef 100644 --- a/drivers/fpga/fpga-region.c +++ b/drivers/fpga/fpga-region.c @@ -228,12 +228,13 @@ fpga_region_register_full(struct device *parent, const struct fpga_region_info * ret = device_register(®ion->dev); if (ret) { - put_device(®ion->dev); - return ERR_PTR(ret); + goto err_put_device; } return region; +err_put_device: + put_device(®ion->dev); err_remove: ida_free(&fpga_region_ida, id); err_free: -- 2.34.1