From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (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 717B12E5B21 for ; Wed, 17 Jun 2026 02:19:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781662773; cv=none; b=sNm0RbpzkH7f7uXRv/qFzu54xy7r5PbWNRlxNuA0Xuz3ZaPISbS/7wXfcleORu46KduFkymk6o0xvTUinwqUq+ldjUf/dE9BNWdWw6wbvrrqipGqQXlfqHkhQ78Bf0t+SZAm5ygOCY5nSVHvpJ4v4NbVm0bwbwCmqz9wx1EFIAQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781662773; c=relaxed/simple; bh=TDjWMRcNp0N3jKm74dUEUCjAdZEK3lc7vjrsqpVkBMY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BvkMd2UKDDbSDprjXa0azFPkOPpTyNx8ATUw4seSLCeRNP/0JPBdF5v0GAoC34BBmDSHxVBudj9tBlxTQD1bDCBDWZwRinQdpIjGz6bq/tT47ZaEItN19X2USER11YJtBPb+Qg8QY/2iHejC5cGkKZxt95d1UhvnWBvxq1wV8Pc= 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=rmLEyY3v; arc=none smtp.client-ip=209.85.222.174 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="rmLEyY3v" Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-915aa0a9293so50392985a.1 for ; Tue, 16 Jun 2026 19:19:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781662771; x=1782267571; 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=d5adCbZjNc85uY/9brOf3vfwrOByakFrcAqPyeusAfU=; b=rmLEyY3vm2XjO+tfaPr46R4JpnazRI//NMaM4/BNyihHtPA/2laa8N7+8sOvTJ5+C8 FLMyGMPbhYqgpYwT19sTVcgSeaoUKZu5YQ2S10WkhsxMAXT3xhRsIkD8k0JbXJ7AfSsf hBTD0snkVTNDT9gMcc415rFuUuOpJnbNlXVy971bHVbqxrr2MlSQHPe+xgBl0dnhu9Xx b1p49o0g6FPqXaoRD2T8wdsfsB3BOdM4DSCW35YyGJ+nMvAPBZDCH9ofn2Z0un38u49Y GZH0V9aX00nhmDYe9hfzpA/tosbcdp44I+uT7mmHBWYp4oIyS1kPrFUKnqoNyYOKbabK GjoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781662771; x=1782267571; 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=d5adCbZjNc85uY/9brOf3vfwrOByakFrcAqPyeusAfU=; b=bHqRHx6McYlTtsyz9ffpAKX6glotqjSfIFAdh3qagF4V4qBGNqRh4C8dFCQsJ7wUjl sWJ0C76ZkKtcLlSs40l9WCxkhl5f3TU/+9jdKlc6NBza9/gVreid+u+6wP0bCsjWihd/ 2wRZcAbVIrY44j+sXQXz+ZeMbf2BZVlM8lShv1zaOyI94vMufTU0QjCi9Ku4wDb1FptM ez8Rq3p/bjz4Bv8EafgrMcL3ZRE/u/nC6T3wpMc9MI48u4ulNplhFv9hwZl+gYbZ8NcW oIjwGZCWk6nlSstVOf7XzFM/U5Htyx8D/mVt3/jzXJtl9LP8qG54gwTjJ7Xc2oXw8ypT qV3g== X-Forwarded-Encrypted: i=1; AFNElJ8BSA2ol++boaGnDk0OqvAn9QRpp539L0sAdHJC1S5+Ws3RkpfA4kzvkeqk21PufnnMUVnuCPZMfIweUjY=@vger.kernel.org X-Gm-Message-State: AOJu0Yw9/ga1ipf13d7DNcsHbFvGWdAjmaKZF/HQw6adhGce0L/ECfM8 C7M7kdywyz+NJ0/eYji2CNC9W1EqgyK81xpF+dBDF5x3NT3lKFfk219r X-Gm-Gg: Acq92OEfzHJff8oRinMa32n0JDUOVfkdeNbO5c8IthTWGNGUBHxrZ3g5WNZSBlMwaaU lJkeIlKpCFISXw61XZpxp1FwZv/U2Gr+UIeSOA5qnb5saklwqeGip3fR7WJ59PpbePm5tU/YfW2 ZSsSJmVBRgDCaUSDH3CvoF9fUleqZaMlnt4mTEdA01jrjz0AOOv2dJKCijUtnb+heahkl7iHR41 lEMhRF59M1BjibPbls3BdX3drYY/ZBjSYbM1pKwk4hfYrABnfTG1sb4m7tsxne8sezwR7JuKKWd PPivZfkl0eJiFRMgLJADM/9/INCAa2z6AHzdfZDALRseCSXtHf4onx3pjI95ChjkPSC1BVxOG+5 aXPDY7WQ3ExXxtTbtvIX5rqXyjMb9+rribrBW1qtlfhU4YlzAw5gB12zqG/Lb/JywNT85BasyrB bkZBADQkro+qF0w6KEYgfjxwDACbpJ/DOzuEfUaFh79HZMFYtq60nAF45c55d/yvC255uvrig+7 ukD8lepXrcXX5RUbAu3qigujYevvqwG X-Received: by 2002:a05:620a:1a0e:b0:916:5f5:de22 with SMTP id af79cd13be357-91dcabb0438mr183153085a.12.1781662771344; Tue, 16 Jun 2026 19:19:31 -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 af79cd13be357-9161a006e35sm1657646285a.28.2026.06.16.19.19.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jun 2026 19:19:30 -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 v3 3/9] media: hevc: add bounded tile-count helpers Date: Tue, 16 Jun 2026 22:19:00 -0400 Message-ID: <20260617021906.2746743-4-michael.bommarito@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260617021906.2746743-1-michael.bommarito@gmail.com> References: <20260617021906.2746743-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 The stateless HEVC decoders compute the number of tile columns and rows from num_tile_columns_minus1 / num_tile_rows_minus1 and clamp it to the column_width_minus1[] / row_height_minus1[] capacity before using it as a loop bound. Add shared helpers in a new so the rkvdec and hantro drivers do not each open-code the min_t() clamp. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Michael Bommarito --- include/media/v4l2-hevc.h | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 include/media/v4l2-hevc.h diff --git a/include/media/v4l2-hevc.h b/include/media/v4l2-hevc.h new file mode 100644 index 0000000000000..973c96be16be4 --- /dev/null +++ b/include/media/v4l2-hevc.h @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Helper functions for HEVC stateless codecs. + */ + +#ifndef _MEDIA_V4L2_HEVC_H +#define _MEDIA_V4L2_HEVC_H + +#include +#include + +/** + * v4l2_hevc_pps_num_tile_columns - number of HEVC tile columns, bounded + * @pps: the V4L2 HEVC PPS control + * + * Return the number of tile columns (num_tile_columns_minus1 + 1) clamped to + * the capacity of column_width_minus1[]. The control validation already + * rejects out-of-range counts; this keeps the consuming drivers bounded too. + */ +static inline unsigned int +v4l2_hevc_pps_num_tile_columns(const struct v4l2_ctrl_hevc_pps *pps) +{ + return min_t(unsigned int, pps->num_tile_columns_minus1 + 1, + ARRAY_SIZE(pps->column_width_minus1)); +} + +/** + * v4l2_hevc_pps_num_tile_rows - number of HEVC tile rows, bounded + * @pps: the V4L2 HEVC PPS control + * + * Return the number of tile rows (num_tile_rows_minus1 + 1) clamped to the + * capacity of row_height_minus1[]. + */ +static inline unsigned int +v4l2_hevc_pps_num_tile_rows(const struct v4l2_ctrl_hevc_pps *pps) +{ + return min_t(unsigned int, pps->num_tile_rows_minus1 + 1, + ARRAY_SIZE(pps->row_height_minus1)); +} + +#endif /* _MEDIA_V4L2_HEVC_H */ -- 2.53.0