Skip to content
/ linux Public

Commit 3ca2f09

Browse files
GoodLuck612gregkh
authored andcommitted
media: tegra-video: Fix memory leak in __tegra_channel_try_format()
[ Upstream commit 43e5302 ] The state object allocated by __v4l2_subdev_state_alloc() must be freed with __v4l2_subdev_state_free() when it is no longer needed. In __tegra_channel_try_format(), two error paths return directly after v4l2_subdev_call() fails, without freeing the allocated 'sd_state' object. This violates the requirement and causes a memory leak. Fix this by introducing a cleanup label and using goto statements in the error paths to ensure that __v4l2_subdev_state_free() is always called before the function returns. Fixes: 56f64b8 ("media: tegra-video: Use zero crop settings if subdev has no get_selection") Fixes: 1ebaeb0 ("media: tegra-video: Add support for external sensor capture") Cc: stable@vger.kernel.org Signed-off-by: Zilin Guan <zilin@seu.edu.cn> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent a29639a commit 3ca2f09

File tree

1 file changed

+8
-5
lines changed
  • drivers/staging/media/tegra-video

1 file changed

+8
-5
lines changed

drivers/staging/media/tegra-video/vi.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ static int __tegra_channel_try_format(struct tegra_vi_channel *chan,
440440
.target = V4L2_SEL_TGT_CROP_BOUNDS,
441441
};
442442
struct v4l2_rect *try_crop;
443-
int ret;
443+
int ret = 0;
444444

445445
subdev = tegra_channel_get_remote_source_subdev(chan);
446446
if (!subdev)
@@ -484,8 +484,10 @@ static int __tegra_channel_try_format(struct tegra_vi_channel *chan,
484484
} else {
485485
ret = v4l2_subdev_call(subdev, pad, get_selection,
486486
NULL, &sdsel);
487-
if (ret)
488-
return -EINVAL;
487+
if (ret) {
488+
ret = -EINVAL;
489+
goto out_free;
490+
}
489491

490492
try_crop->width = sdsel.r.width;
491493
try_crop->height = sdsel.r.height;
@@ -497,14 +499,15 @@ static int __tegra_channel_try_format(struct tegra_vi_channel *chan,
497499

498500
ret = v4l2_subdev_call(subdev, pad, set_fmt, sd_state, &fmt);
499501
if (ret < 0)
500-
return ret;
502+
goto out_free;
501503

502504
v4l2_fill_pix_format(pix, &fmt.format);
503505
chan->vi->ops->vi_fmt_align(pix, fmtinfo->bpp);
504506

507+
out_free:
505508
__v4l2_subdev_state_free(sd_state);
506509

507-
return 0;
510+
return ret;
508511
}
509512

510513
static int tegra_channel_try_format(struct file *file, void *fh,

0 commit comments

Comments
 (0)