diff --git a/drivers/video/tegra/nvmap/nvmap_ioctl.c b/drivers/video/tegra/nvmap/nvmap_ioctl.c index 7a6db822..908157ea 100644 --- a/drivers/video/tegra/nvmap/nvmap_ioctl.c +++ b/drivers/video/tegra/nvmap/nvmap_ioctl.c @@ -1539,15 +1539,15 @@ int nvmap_ioctl_get_fd_from_list(struct file *filp, void __user *arg) for (i = 0; i < op.num_handles; i++) { hs[i] = nvmap_handle_get_from_id(client, hndls[i]); - tot_hs_size += hs[i]->size; if (IS_ERR_OR_NULL(hs[i])) { pr_err("invalid handle_ptr[%d] = %u\n", i, hndls[i]); - while (i--) + while (--i >= 0) nvmap_handle_put(hs[i]); err = -EINVAL; goto free_mem; } + tot_hs_size += hs[i]->size; } /* Add check for sizes of all the handles should be > offs and size */