From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B38324BBF4; Mon, 23 Mar 2026 15:24:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774279479; cv=none; b=khJAwELKYV/kmQlCDlU0G4jaOB4uxdBsguvEkenUaoMAjJ51xlMB5QMruiq9/aTV8nxqeofEnvv4UfD6wXELB79eeheHc1xP9+w2zLSL0US4eeHVVf+gGX1o4cO45hPdPX9D3XBsv1LTBuYLdV8nXOTVK48zpoaWJ9PkmQaSWvw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774279479; c=relaxed/simple; bh=Hgr6K8/2A446NBQA/BV8MwxchnXePXzxFUWt+dANxH4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YoLH8NYCKtuTjCG97XQLZeVrO3dzpxbSXO2Hd4B4+v7tA9lBjhGxBGp3NCw78nfyITYEGVAufL8pkUJavbO0K37Hgs0Xnb50LrSwk72r6wnf/zYtFrpZWOAvlcflwR/KbH0kENWHzc9p8oCK9v7sHMOMvp/y8MW4CWFRFyCp5qs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=WvDY10wT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="WvDY10wT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B7CDC2BC9E; Mon, 23 Mar 2026 15:24:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1774279479; bh=Hgr6K8/2A446NBQA/BV8MwxchnXePXzxFUWt+dANxH4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WvDY10wT7+Q22yBR7Qtu03EL66fhadQT2mQplmXrYlv+2pSgXi7gH76BXJNUK85K2 tMj7nlR9xLRWgLBo1EV/PxVEA6R3cGIx+AVGhYQ3pdtN7awwXWCYS6HBi8aWwgr/6p TeEkv6RtGTtBo4hABavoDo7QFnQbfjiI7CoeYg04= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zilin Guan , Hans Verkuil , Sasha Levin Subject: [PATCH 6.1 031/481] media: tegra-video: Fix memory leak in __tegra_channel_try_format() Date: Mon, 23 Mar 2026 14:40:13 +0100 Message-ID: <20260323134525.998304641@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260323134525.256603107@linuxfoundation.org> References: <20260323134525.256603107@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zilin Guan [ Upstream commit 43e5302d22334f1183dec3e0d5d8007eefe2817c ] 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: 56f64b82356b7 ("media: tegra-video: Use zero crop settings if subdev has no get_selection") Fixes: 1ebaeb09830f3 ("media: tegra-video: Add support for external sensor capture") Cc: stable@vger.kernel.org Signed-off-by: Zilin Guan Signed-off-by: Hans Verkuil Signed-off-by: Sasha Levin --- drivers/staging/media/tegra-video/vi.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/staging/media/tegra-video/vi.c b/drivers/staging/media/tegra-video/vi.c index e82ab9044ef3b..ea96fd67035c7 100644 --- a/drivers/staging/media/tegra-video/vi.c +++ b/drivers/staging/media/tegra-video/vi.c @@ -503,7 +503,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) @@ -548,8 +548,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; @@ -561,14 +563,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); tegra_channel_fmt_align(chan, 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, -- 2.51.0