Skip to content

Commit

Permalink
misc: ocxl: fix possible name leak in ocxl_file_register_afu()
Browse files Browse the repository at this point in the history
[ Upstream commit a4cb100 ]

If device_register() returns error in ocxl_file_register_afu(),
the name allocated by dev_set_name() need be freed. As comment
of device_register() says, it should use put_device() to give
up the reference in the error path. So fix this by calling
put_device(), then the name can be freed in kobject_cleanup(),
and info is freed in info_release().

Fixes: 75ca758 ("ocxl: Create a clear delineation between ocxl backend & frontend")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Acked-by: Andrew Donnellan <ajd@linux.ibm.com>
Acked-by: Frederic Barrat <fbarrat@linux.ibm.com>
Link: https://lore.kernel.org/r/20221111145929.2429271-1-yangyingliang@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Yang Yingliang authored and gregkh committed Dec 31, 2022
1 parent 357379d commit 3299983
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions drivers/misc/ocxl/file.c
Expand Up @@ -543,8 +543,11 @@ int ocxl_file_register_afu(struct ocxl_afu *afu)
goto err_put;

rc = device_register(&info->dev);
if (rc)
goto err_put;
if (rc) {
free_minor(info);
put_device(&info->dev);
return rc;
}

rc = ocxl_sysfs_register_afu(info);
if (rc)
Expand Down

0 comments on commit 3299983

Please sign in to comment.