From patchwork Fri Oct 13 11:00:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tretter X-Patchwork-Id: 13420691 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBA49CDB482 for ; Fri, 13 Oct 2023 11:01:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229947AbjJMLBR (ORCPT ); Fri, 13 Oct 2023 07:01:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229688AbjJMLBP (ORCPT ); Fri, 13 Oct 2023 07:01:15 -0400 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [IPv6:2a0a:edc0:2:b01:1d::104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D103BBD for ; Fri, 13 Oct 2023 04:01:13 -0700 (PDT) Received: from dude05.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::54]) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1qrFuU-0006xJ-AV; Fri, 13 Oct 2023 13:00:50 +0200 From: Michael Tretter Date: Fri, 13 Oct 2023 13:00:28 +0200 Subject: [PATCH v2 07/13] media: rockchip: rga: use clamp() to clamp size to limits MIME-Version: 1.0 Message-Id: <20230914-rockchip-rga-multiplanar-v2-7-bbfa6abf8bbf@pengutronix.de> References: <20230914-rockchip-rga-multiplanar-v2-0-bbfa6abf8bbf@pengutronix.de> In-Reply-To: <20230914-rockchip-rga-multiplanar-v2-0-bbfa6abf8bbf@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Shengyu Qu , Nicolas Frattaroli , Robin Murphy , Diederik de Haas , Hans Verkuil Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, kernel@pengutronix.de, Michael Tretter X-Mailer: b4 0.12.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:1101:1d::54 X-SA-Exim-Mail-From: m.tretter@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-media@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The try_fmt should limit the width and height to the know limits of the RGA. Use the clamp() helper instead of open coding the clamping. Signed-off-by: Michael Tretter --- Changes in v2: None --- drivers/media/platform/rockchip/rga/rga.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/platform/rockchip/rga/rga.c index ea566c11734a..792084918798 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -482,15 +482,10 @@ static int vidioc_try_fmt(struct file *file, void *prv, struct v4l2_format *f) f->fmt.pix.field = V4L2_FIELD_NONE; - if (f->fmt.pix.width > MAX_WIDTH) - f->fmt.pix.width = MAX_WIDTH; - if (f->fmt.pix.height > MAX_HEIGHT) - f->fmt.pix.height = MAX_HEIGHT; - - if (f->fmt.pix.width < MIN_WIDTH) - f->fmt.pix.width = MIN_WIDTH; - if (f->fmt.pix.height < MIN_HEIGHT) - f->fmt.pix.height = MIN_HEIGHT; + f->fmt.pix.width = clamp(f->fmt.pix.width, + (u32)MIN_WIDTH, (u32)MAX_WIDTH); + f->fmt.pix.height = clamp(f->fmt.pix.height, + (u32)MIN_HEIGHT, (u32)MAX_HEIGHT); if (fmt->hw_format >= RGA_COLOR_FMT_YUV422SP) f->fmt.pix.bytesperline = f->fmt.pix.width;