mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-04-04 11:15:39 -04:00
media: tegra-video: Fix memory leak in __tegra_channel_try_format()
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:56f64b8235("media: tegra-video: Use zero crop settings if subdev has no get_selection") Fixes:1ebaeb0983("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>
This commit is contained in:
@@ -438,7 +438,7 @@ static int __tegra_channel_try_format(struct tegra_vi_channel *chan,
|
||||
.target = V4L2_SEL_TGT_CROP_BOUNDS,
|
||||
};
|
||||
struct v4l2_rect *try_crop;
|
||||
int ret;
|
||||
int ret = 0;
|
||||
|
||||
subdev = tegra_channel_get_remote_source_subdev(chan);
|
||||
if (!subdev)
|
||||
@@ -482,8 +482,10 @@ static int __tegra_channel_try_format(struct tegra_vi_channel *chan,
|
||||
} else {
|
||||
ret = v4l2_subdev_call(subdev, pad, get_selection,
|
||||
NULL, &sdsel);
|
||||
if (ret)
|
||||
return -EINVAL;
|
||||
if (ret) {
|
||||
ret = -EINVAL;
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
try_crop->width = sdsel.r.width;
|
||||
try_crop->height = sdsel.r.height;
|
||||
@@ -495,14 +497,15 @@ static int __tegra_channel_try_format(struct tegra_vi_channel *chan,
|
||||
|
||||
ret = v4l2_subdev_call(subdev, pad, set_fmt, sd_state, &fmt);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
goto out_free;
|
||||
|
||||
v4l2_fill_pix_format(pix, &fmt.format);
|
||||
chan->vi->ops->vi_fmt_align(pix, fmtinfo->bpp);
|
||||
|
||||
out_free:
|
||||
__v4l2_subdev_state_free(sd_state);
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int tegra_channel_try_format(struct file *file, void *fh,
|
||||
|
||||
Reference in New Issue
Block a user