coresight: syscfg: Fix memleak on registration failure in cscfg_create_device

commit cfa5dbcdd7 upstream.

device_register() calls device_initialize(),
according to doc of device_initialize:

    Use put_device() to give up your reference instead of freeing
    * @dev directly once you have called this function.

To prevent potential memleak, use put_device() for error handling.

Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
Fixes: 85e2414c51 ("coresight: syscfg: Initial coresight system configuration")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20220124124121.8888-1-linmq006@gmail.com
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Miaoqian Lin 2022-01-24 12:41:21 +00:00 коммит произвёл Greg Kroah-Hartman
Родитель ba81399402
Коммит c61e2fc87f
1 изменённых файлов: 1 добавлений и 1 удалений

Просмотреть файл

@ -791,7 +791,7 @@ static int cscfg_create_device(void)
err = device_register(dev);
if (err)
cscfg_dev_release(dev);
put_device(dev);
create_dev_exit_unlock:
mutex_unlock(&cscfg_mutex);