netdevsim: dev: Fix memory leak in nsim_dev_take_snapshot_write

In case memory resources for dummy_data were allocated, release them
before return.

Addresses-Coverity-ID: 1491997 ("Resource leak")
Fixes: 7ef19d3b1d ("devlink: report error once U32_MAX snapshot ids have been used")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Reviewed-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Gustavo A. R. Silva 2020-03-30 18:27:02 -05:00 committed by David S. Miller
parent 1a795da798
commit 3902baf9ab

View File

@ -75,6 +75,7 @@ static ssize_t nsim_dev_take_snapshot_write(struct file *file,
err = devlink_region_snapshot_id_get(devlink, &id); err = devlink_region_snapshot_id_get(devlink, &id);
if (err) { if (err) {
pr_err("Failed to get snapshot id\n"); pr_err("Failed to get snapshot id\n");
kfree(dummy_data);
return err; return err;
} }
err = devlink_region_snapshot_create(nsim_dev->dummy_region, err = devlink_region_snapshot_create(nsim_dev->dummy_region,