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 295F4317142; Thu, 12 Mar 2026 20:16:28 +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=1773346589; cv=none; b=HHxtEb++CFtGmKD2K90au5AEc5+pWVz7lpF/yhp+xhu5vT84vYURS1yWlL16W4jIi3jtwqvziA2o3E43BCVCD0hwJt+kOty8oHAdZV1J6nJV808VsMl/KD3/mGL7iQIwfB1b4/527TeLDvvJFGxRqzHX0FwdkcVxeTdcaslrQaw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773346589; c=relaxed/simple; bh=5cP0N/Lh0rm8HmjjnVyr4gt+EW4AsB8rM6sDiP14YKA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LQCdfnQGwlh4j0KcACbrILjrnytMscj5HXKUWQ/r6Loy3EnyEQ7D/CSI4eL5AdC0hrnMVVTk4pfBdJ8W3Toj23pDVMrqMFc/QyHuPjdPNZjxZPwkruWZxnAuMm82SiTCLlssLFyxcjPPPz475KIkN7/vcTNMeNmGNryeiM7xljA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=RIztHAod; 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="RIztHAod" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CD50C4CEF7; Thu, 12 Mar 2026 20:16:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1773346588; bh=5cP0N/Lh0rm8HmjjnVyr4gt+EW4AsB8rM6sDiP14YKA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RIztHAodufJx/lKHVIZVJHPgjyWeKKI6D5SVt+rYL8sOghOztXtuJhTCSfvX8XEl5 yAuOdfxgPPR/yRP+dOI7K/8VysHluAmyOmo9lH0qPt+7ZUhoYB923W7cubwH9ggFRx EO/NSGeW3DdwzXpLDuSJZSyE9t8GssHY7glQuVnE= 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.12 050/265] media: tegra-video: Fix memory leak in __tegra_channel_try_format() Date: Thu, 12 Mar 2026 21:07:17 +0100 Message-ID: <20260312201020.012448311@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260312201018.128816016@linuxfoundation.org> References: <20260312201018.128816016@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.12-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 57a856a21e901..463410349d07e 100644 --- a/drivers/staging/media/tegra-video/vi.c +++ b/drivers/staging/media/tegra-video/vi.c @@ -440,7 +440,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) @@ -484,8 +484,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; @@ -497,14 +499,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, -- 2.51.0