From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 293222F90C9 for ; Sun, 12 Apr 2026 08:49:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775983779; cv=none; b=Iago+gWcoOA1i3taDQZocM0BYRsnF7jPXrjqB/zO1OCrbaC/dYZwaRNsHr38Xy+AeyyfuwHxxOdx55yhTyHu7IMqOQxx/L+hUfvFeai4Lmn7qVsY2dJWSZPJiY9Kc1Q0ZAemoGSmvKRsHexZUeZE0e8qNFSD29gjHEV1m6loBig= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775983779; c=relaxed/simple; bh=Zh1gMWcDLON+NjfzXUS2eYcY2NU/RrfJ8BIhx6gE90w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BkIioPtVHgH+lP0cpZuH4CwLBj3I7CkgvTBOYl2OHw1htacFTLR/eKSL5dHmEBmassq5H2G9gTr+xcRLVbqmZkfknfL4fhGEDe34mOs3QkwUQ/HKzS3FRN4Eb0kbLZBUvuGM3Qs13AVAUiF+QOfs+NuECEl/ufik4En17cKFRyA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=iBxb5y51; arc=none smtp.client-ip=209.85.208.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iBxb5y51" Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-6717e00c68fso11519a12.2 for ; Sun, 12 Apr 2026 01:49:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775983775; x=1776588575; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=U+KERGfJ0lgKno7VzsagW4vKndlmZyVJae2CPohMXXU=; b=iBxb5y51wrQK1NV3WgNsk50NxLIsFxZuC9xecAUt6PmH6MHEfTRDIUdfmo8P2zTo9k 1taWXM19afs8cuyi9nmsObviYpMz0mG1uiqaSdKVLa6SDB31R8nOr427MhPRR8yDgOik TyLI56tJLGBmcDR+NMwLOaEKTmVk7B2zhSKs2uFB8clO6ub49OCNsqIQGvjnU73W/jq6 OZRhhgskzq/e1DbglsVby+/k+m522EyOXtuJgej0fQshxxdQqVAm7d4CAFCWCc0RZ51U 2RXT0a1Lopwl4ohyZH6lQP6t0PfnLV0N6aE/HEmPlbJ/nW07YJAEPfJMnDg89qir6WAU 5W2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775983775; x=1776588575; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=U+KERGfJ0lgKno7VzsagW4vKndlmZyVJae2CPohMXXU=; b=LxczSIByBy7pGXzAYGjyAOx5lGPBeOPs65jzxvJhVVzi0b086Hr2RK7+cYllCgY0ag EvEXw3sKvuRfMIoLWkbymUnwcdg+AT8LdlxWO6IOvY4LNDewUT0l0v7m+r2u/N/juEUv BxLxP1EQA54/6HZTUfPV10MfusslzlsTUBpfQxHJN9G25ym6klfdcxJiYV6B4sa8C/zf i7wTeMQFa+hypEoBMAR9lrqjXL63Ttr26b2sK5iYN/a1nDfJ0gcqeJgZyYwt7NvBbE1a zRvbdHJRNK5ycN7oXFGCsA3jVwVG1W5RPdy6l3MEV9ilY6d4Ed0unFnVjMf+Ou1HlLR2 vSfQ== X-Forwarded-Encrypted: i=1; AJvYcCX03tByOjHdumt5lspDfYvheCOPbJ1MpaVhh364gywvugR6KlM6Rrzg6TbcUPvqU1g4LAipgVQ9516HWAU=@vger.kernel.org X-Gm-Message-State: AOJu0YwqBqZS2mbhgBTjyAt8miVw3qwp501tFYuY8WvjLCKt++4AWmd7 AD1SvjRSYe2isXr1kGvwtBxjmYlbkAMaNaOvj7D52Fe7UKxA9Mr/6PzP X-Gm-Gg: AeBDieu9SC4NU8BoDSNLJfot+CFBT37P+BeXL9J+GWoRjsCdVeEKq2h/RtgFYI1y/Bp dEYLc/847DUNnKe9s7oI0jtyX8COxIG8DlExxd6JESVgaELqkqPA5mXaSTyHi42fGp0tU9gVijM a27tOs6TeCjYFebY9R3kiWAbL4GGz8/nVUrrUlHmLdzkp+Nz4nOoh0yGNxkZo5UBaPeaNrWRmgJ eVz5Akw8chWkCPKYIKXz+L01AQg8LIkOfJMnHZWZ/bx3LR7uNa5RjTqeQtnAclPDY/j+0/bA9yo IODHA2pu3jMeem0/8ghu3oz0u449l4IyV1xJRP2Q4CDUufAx8uJ9MxYkKa2wAFPw8v4QammIsKU TtKa60P3be/ncY0pjTLCB2V8UKQpGfs1gnkWZS+cmlay+r8ddYQebh93KZVGQNVTYi3/Omsjyvy 8RyixDQFAFLsT3Ny2A9a4nGRDIApsqTTsMImJYZ/85bPNNFbbMzbcAiRsxEEVl3rnAuR6zGdi9q 3lAKg2t1v+H/Us2C1jxWzfBxjOvZVIUgZ362GBYIhthtpTioardQxQlttaUaCAUkVQKvkUDzYVh M/WyOw== X-Received: by 2002:a17:907:3f87:b0:b9d:df73:f0b8 with SMTP id a640c23a62f3a-b9ddf7429e8mr7795766b.32.1775983775119; Sun, 12 Apr 2026 01:49:35 -0700 (PDT) Received: from ahossu.residents.sin.openfiber.nl ([88.202.160.248]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b9d6dfd89a9sm226253366b.25.2026.04.12.01.49.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Apr 2026 01:49:34 -0700 (PDT) From: Alexandru Hossu To: Greg Kroah-Hartman , Thierry Reding , Sowjanya Komatineni Cc: Jonathan Hunter , Luca Ceresoli , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-tegra@vger.kernel.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Alexandru Hossu Subject: [PATCH 2/2] staging: media: tegra-video: add missing error checks in vi_tpg_fmts_bitmap_init() Date: Sun, 12 Apr 2026 10:48:08 +0200 Message-ID: <20260412084808.232010-1-hossu.alexandru@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260412045245.GA2019381@kroah.com> References: <20260412045245.GA2019381@kroah.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit tegra_get_format_idx_by_code() returns -1 when the requested format is not found in the SoC format table. vi_tpg_fmts_bitmap_init() does not check this return value before passing it to bitmap_set(). A negative index converted to unsigned would result in an out-of-bounds memory access, corrupting adjacent kernel memory. Add WARN_ON() guards so that any future SoC addition or Kconfig change that exposes this path fails loudly rather than silently corrupting memory. Signed-off-by: Alexandru Hossu --- drivers/staging/media/tegra-video/vi.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/staging/media/tegra-video/vi.c b/drivers/staging/media/tegra-video/vi.c index afc7327ef318..d1d934e361f7 100644 --- a/drivers/staging/media/tegra-video/vi.c +++ b/drivers/staging/media/tegra-video/vi.c @@ -1017,7 +1017,7 @@ static int tegra_channel_setup_ctrl_handler(struct tegra_vi_channel *chan) } /* VI only support 2 formats in TPG mode */ -static void vi_tpg_fmts_bitmap_init(struct tegra_vi_channel *chan) +static int vi_tpg_fmts_bitmap_init(struct tegra_vi_channel *chan) { int index; @@ -1025,12 +1025,22 @@ static void vi_tpg_fmts_bitmap_init(struct tegra_vi_channel *chan) index = tegra_get_format_idx_by_code(chan->vi, MEDIA_BUS_FMT_SRGGB10_1X10, 0); + if (index < 0) { + dev_err(chan->vi->dev, "format SRGGB10_1X10 not found\n"); + return -EINVAL; + } bitmap_set(chan->tpg_fmts_bitmap, index, 1); index = tegra_get_format_idx_by_code(chan->vi, MEDIA_BUS_FMT_RGB888_1X32_PADHI, 0); + if (index < 0) { + dev_err(chan->vi->dev, "format RGB888_1X32_PADHI not found\n"); + return -EINVAL; + } bitmap_set(chan->tpg_fmts_bitmap, index, 1); + + return 0; } static int vi_fmts_bitmap_init(struct tegra_vi_channel *chan) @@ -1410,7 +1420,9 @@ int tegra_v4l2_nodes_setup_tpg(struct tegra_video_device *vid) goto cleanup; v4l2_set_subdev_hostdata(&csi_chan->subdev, vi_chan); - vi_tpg_fmts_bitmap_init(vi_chan); + ret = vi_tpg_fmts_bitmap_init(vi_chan); + if (ret < 0) + goto cleanup; csi_chan = list_next_entry(csi_chan, list); } -- 2.53.0