From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) (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 27B223C8197 for ; Sun, 14 Jun 2026 15:56:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781452578; cv=none; b=DzLscfHNCFJ/j5Z20kLbYXubFMOuZa2kWFqSp/Ey4bRWJTbGwGS/rffmpCxCazdYiwSVV9msamAwT4uPmbVdT3Hk6idasrfBERURNBEebIASoTyimqy9+tO5nffNeuFlhCgW7Z82y03KB9NG5DXupWYfFT9KxggHPlETqYudC3E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781452578; c=relaxed/simple; bh=D6G0yKR2/rytcvr1WlW/71DhsLr0kJgYyxusnDEFlms=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z2lLQRT5YM/W/M/PBbEZMkRiurO8ROZN1AnFVui3Kxkyv+JaFDHRec1MRNVAmEOdqXZsM7OOveZ+ERGDIyPcsHCMc+lOhrvzQO43vKav5Hc1wujszYB+uN6p4HKNUINQQ7tOBI2z3mbRLQChHjLxC67QLDh8lbEZH/M6gPjPbzs= 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=QTDsAoEy; arc=none smtp.client-ip=209.85.219.44 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="QTDsAoEy" Received: by mail-qv1-f44.google.com with SMTP id 6a1803df08f44-8ce9df4732cso31197146d6.1 for ; Sun, 14 Jun 2026 08:56:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781452576; x=1782057376; 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=z35bHdhSh8a/Z8G1ETcqSJjtROGT6H3Pl9v+4lJ8nHY=; b=QTDsAoEy9IIZBVPiaev/b/AccdJKEDrmbUc4TdDA81kQbctZFTH3RXxuBg8aGqxs53 24Ra8tnAurET4J0w/5Up7EHRLQaE10iTW2mZYxhU7fPGSHPG1n/FoNEc57tyH8lm/TD8 r4U1X0qYdRhtCNNmcz4+h9eFOit3S4Gqs6kv8cAj82wf4bJvBQvLEa4hCspvvigqSAXQ x5fq25ildO4HptUi1/og5CPZsPCWSVE4tsKwh6EM1fNQepI6nAGQCj7iyn43fbgGQd0T 6G/j/6E+APu9uTfMfXvRNeWKihJ5Lm1yFCzaW5ymbYxf+RDbxK7es6VJvw6E9bF6eV9x 85Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781452576; x=1782057376; 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=z35bHdhSh8a/Z8G1ETcqSJjtROGT6H3Pl9v+4lJ8nHY=; b=PA8JZLzwE3rPF/v3GdtKKPKewDxZhwoUfspD6Kx0UKZ3RyX1/fTC2+8WJH6iAK+035 1o9wIRR6pCWLV8pifQj9h2CDZPO+16v1LQ38XudNdDm+o0wwo0VNGPOO5VJVq2298u3Y YyUb53KpGqJ6TV/KvdeeZ+1NpOoXZ3UU44qiqCYsyYOBagoILO19ybwLpa5UhfF4d+xZ zfQ168+RPdeaNpzuET96Fiq+7ScofkWeAJJIfMrQCTwwPAm/CaFQPT2gMjctW3OmNXhd YoOz70c7BAdrPJRyO+9gHXeDTdNMC7uy2xFGC+Ouc7NkqQp06TnQqO5T8BwqMPxnb9S1 is+Q== X-Forwarded-Encrypted: i=1; AFNElJ9k0LXGOnvnD9mHoVewUZbQNS/hJzB744KNbFxJ2Lcb4aqiZfIRX1TXh4CsSQhEhdEVEblx88PQvtU53Sw=@vger.kernel.org X-Gm-Message-State: AOJu0YyQ+v1J8m+mRzm+wx9cBMtGn7z5FTOCb3+78XPBdWmz4/WRifAb D+mamsf6DIknIuMVCiDbENWTJzUlN5gsgjd6fY3diOMXw4p2hOL0i4DG X-Gm-Gg: Acq92OF9Zdsii7TTnf00QuXM3rtwH1oa1P9ztVBnEgtTU8y/kCyAXM1u/5/pX55jX89 huJT1+lkXZLhzVH7ssibL85F2BcJyjdDgQC+XLAiDwOpRze33B2qtIhv+od3bo10QevJHnJh54a eoRZN+KMNiIsGoMgqRXvqOhoJXQ/zRdXhkTMJhXVpBTolUeWNdiWE/MO9BrTrs5Kg5FYYQRzK+N XInLNN/PWca1rfKl5GOrr525GQr4ah/duuZ1VjVt6AR9vuBgdcx0UBGmLFMDChEeS4HpMiKPTaC XrclhAd0zDbDqOOl7diOjyFOzmZYJguJxJrG4q/MnB5YR1pNeZobSqPjmdyqUJv6bOEo5VtysGn J7/tC7o0sN0a7fKNPbovqTiH79syC9Qd5KtAgV2bZSjg1QbH8O47Nz9k8G0DBzrEVT6xBDU5uwh 5TaiXu2wYY7EVd4F4B0xY9W3OTN3cF6mSyzB00oVNVYOBEocfyl5nXTpWVuLpCndMOvmenujGcs HeRwFE4qu721gfL+FhXCjU4NSMHbJZPSD9vQO2jLYc= X-Received: by 2002:ad4:596a:0:b0:8cc:e8f4:1630 with SMTP id 6a1803df08f44-8d32e50112cmr179007736d6.30.1781452576150; Sun, 14 Jun 2026 08:56:16 -0700 (PDT) Received: from server0.tail6e7dd.ts.net (c-68-48-65-54.hsd1.mi.comcast.net. [68.48.65.54]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8d30522cbeasm82008446d6.44.2026.06.14.08.56.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jun 2026 08:56:15 -0700 (PDT) From: Michael Bommarito To: Hans Verkuil , Mauro Carvalho Chehab , Sakari Ailus , Nicolas Dufresne Cc: Laurent Pinchart , Benjamin Gaignard , Detlev Casanova , Ezequiel Garcia , Yunfei Dong , Jonas Karlman , Heiko Stuebner , Kees Cook , linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/6] media: rkvdec: bound HEVC tile loops and PPS id to the array capacity Date: Sun, 14 Jun 2026 11:56:04 -0400 Message-ID: <20260614155609.3107600-3-michael.bommarito@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260614155609.3107600-1-michael.bommarito@gmail.com> References: <20260614155609.3107600-1-michael.bommarito@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7bit compute_tiles_uniform() / compute_tiles_non_uniform() and assemble_hw_pps() loop over num_tile_columns_minus1 / num_tile_rows_minus1 to write the per-tile column_width[] / row_height[] arrays, sized to the PPS uAPI arrays column_width_minus1[20] / row_height_minus1[22]; bound the loops to that capacity. assemble_hw_pps() also indexes the fixed param_set[] table by pic_parameter_set_id, a driver-interpreted index the core does not reject; bound it to the table size before the access. Fixes: 3595375c2301 ("media: rkvdec: Add HEVC backend") Fixes: c9a59dc2acc7 ("media: rkvdec: Add HEVC support for the VDPU381 variant") Signed-off-by: Michael Bommarito Assisted-by: Claude:claude-opus-4-8 --- .../rockchip/rkvdec/rkvdec-hevc-common.c | 22 +++++++++++++++---- .../platform/rockchip/rkvdec/rkvdec-hevc.c | 8 +++++-- .../rockchip/rkvdec/rkvdec-vdpu381-hevc.c | 2 ++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c b/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c index 3119f3bc9f98b..d0f26f736a763 100644 --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c @@ -37,15 +37,22 @@ void compute_tiles_uniform(struct rkvdec_hevc_run *run, u16 log2_min_cb_size, s32 pic_in_cts_height, u16 *column_width, u16 *row_height) { const struct v4l2_ctrl_hevc_pps *pps = run->pps; + unsigned int num_cols, num_rows; int i; - for (i = 0; i < pps->num_tile_columns_minus1 + 1; i++) + /* Bound the loops to the column_width[]/row_height[] capacity. */ + num_cols = min_t(unsigned int, pps->num_tile_columns_minus1 + 1, + ARRAY_SIZE(pps->column_width_minus1)); + num_rows = min_t(unsigned int, pps->num_tile_rows_minus1 + 1, + ARRAY_SIZE(pps->row_height_minus1)); + + for (i = 0; i < num_cols; i++) column_width[i] = ((i + 1) * pic_in_cts_width) / (pps->num_tile_columns_minus1 + 1) - (i * pic_in_cts_width) / (pps->num_tile_columns_minus1 + 1); - for (i = 0; i < pps->num_tile_rows_minus1 + 1; i++) + for (i = 0; i < num_rows; i++) row_height[i] = ((i + 1) * pic_in_cts_height) / (pps->num_tile_rows_minus1 + 1) - (i * pic_in_cts_height) / @@ -57,17 +64,24 @@ void compute_tiles_non_uniform(struct rkvdec_hevc_run *run, u16 log2_min_cb_size s32 pic_in_cts_height, u16 *column_width, u16 *row_height) { const struct v4l2_ctrl_hevc_pps *pps = run->pps; + unsigned int num_cols, num_rows; s32 sum = 0; int i; - for (i = 0; i < pps->num_tile_columns_minus1; i++) { + /* Leave one slot for the trailing last-tile entry written below. */ + num_cols = min_t(unsigned int, pps->num_tile_columns_minus1, + ARRAY_SIZE(pps->column_width_minus1) - 1); + num_rows = min_t(unsigned int, pps->num_tile_rows_minus1, + ARRAY_SIZE(pps->row_height_minus1) - 1); + + for (i = 0; i < num_cols; i++) { column_width[i] = pps->column_width_minus1[i] + 1; sum += column_width[i]; } column_width[i] = pic_in_cts_width - sum; sum = 0; - for (i = 0; i < pps->num_tile_rows_minus1; i++) { + for (i = 0; i < num_rows; i++) { row_height[i] = pps->row_height_minus1[i] + 1; sum += row_height[i]; } diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc.c b/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc.c index ac8b825d080a2..29b5adb509727 100644 --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-hevc.c @@ -156,6 +156,8 @@ static void assemble_hw_pps(struct rkvdec_ctx *ctx, * packet unit). so the driver copy SPS/PPS information to the exact PPS * packet unit for HW accessing. */ + if (pps->pic_parameter_set_id >= ARRAY_SIZE(priv_tbl->param_set)) + return; hw_ps = &priv_tbl->param_set[pps->pic_parameter_set_id]; memset(hw_ps, 0, sizeof(*hw_ps)); @@ -274,9 +276,11 @@ static void assemble_hw_pps(struct rkvdec_ctx *ctx, if (pps->flags & V4L2_HEVC_PPS_FLAG_TILES_ENABLED) { /* Userspace also provide column width and row height for uniform spacing */ - for (i = 0; i <= pps->num_tile_columns_minus1; i++) + for (i = 0; i <= pps->num_tile_columns_minus1 && + i < ARRAY_SIZE(pps->column_width_minus1); i++) WRITE_PPS(pps->column_width_minus1[i], COLUMN_WIDTH(i)); - for (i = 0; i <= pps->num_tile_rows_minus1; i++) + for (i = 0; i <= pps->num_tile_rows_minus1 && + i < ARRAY_SIZE(pps->row_height_minus1); i++) WRITE_PPS(pps->row_height_minus1[i], ROW_HEIGHT(i)); } else { WRITE_PPS(((sps->pic_width_in_luma_samples + ctb_size_y - 1) / ctb_size_y) - 1, diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c index fe6414a175510..6dafa1dd28507 100644 --- a/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c @@ -145,6 +145,8 @@ static void assemble_hw_pps(struct rkvdec_ctx *ctx, * packet unit). so the driver copy SPS/PPS information to the exact PPS * packet unit for HW accessing. */ + if (pps->pic_parameter_set_id >= ARRAY_SIZE(priv_tbl->param_set)) + return; hw_ps = &priv_tbl->param_set[pps->pic_parameter_set_id]; memset(hw_ps, 0, sizeof(*hw_ps)); -- 2.53.0