Received: by 2002:ac8:5349:0:b0:427:7d78:cd45 with SMTP id d9csp808776qto; Wed, 20 Dec 2023 04:42:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IFTAFRcpDMwctxjc5UlZpAT4Iyw1G9wohNj6JQJJ6qAiksUJX+MsMHGuNzYVTkiexZm28CP X-Received: by 2002:a17:906:dc:b0:a23:5d5d:783 with SMTP id 28-20020a17090600dc00b00a235d5d0783mr1762328eji.151.1703076149437; Wed, 20 Dec 2023 04:42:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703076149; cv=none; d=google.com; s=arc-20160816; b=UPNxvdc5GCU9CpJwRnrATBDd0sQVhRyyLcxVyH7B+wwiNTsA9ypBSChlL5xMsyvBLw V5745208RbVPxZKmmXsXGXBBojmuvpgKIqUlFGmpM3ld3kvee4zdXux6yMsICLMow74L FGU1RTUMFsHxyi06RMzfFfiradr/ghjoZVHzxIi6O2f3AhmG5j8QQ2HTUKWOXXqO8p9h Gq/JW1ooBu2uQ1X9u96YOdkKOcl3MMMwY6X3F50VSFyfmD6R/H0e8nOimjM8/suWRmlz c0C8HFEvKzX3Krdmp6l2xfQY/87NW64h+TewaxuGh5CO+BQgj4715c620x2NvVl/QVZH qXFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=d/8vsrFsmIdkN6wX+xgjZzrqJBCn9bwK4adiKoP4ah4=; fh=Di7l8feqr9yKAAJO9eq1aHGXvDNugNJ25/WDuv2vymc=; b=gbbqabUtR3oaNHEhxoxzD1Q67NBgpRno9XbkCZznq0C2wl7NLofHFOtt/AvSxAfGBd l5s5YSOx4aAfcnbq3nuG7tSMUlzYl6oBsX+vt/EqKGhWztwVrFE7DZHhwSvI7Hq6ESyq zX/Q+H+UoIuUBmonjiknWR8w0srHTuvs08CxTDRe6PcBO+tWam48gFylwDCXiHHKCWdh eoNT/TjyEwfqtmvYpwuH5pQfNyORiSPN9mts96NWswQG8iWUXgc66tSUJQXnxRiSBzy5 6QbAiJfBchrHXI2Qcs6yO6lKTyZ0PUc//N4gSPW0s04Y14GUpKAcirnhJK6r7h1EbCo/ Iifw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=CzQKicn2; spf=pass (google.com: domain of linux-kernel+bounces-6911-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6911-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id b21-20020a170906151500b00a1d70ce6276si11339369ejd.209.2023.12.20.04.42.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 04:42:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6911-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=CzQKicn2; spf=pass (google.com: domain of linux-kernel+bounces-6911-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6911-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 1AD6B1F2896F for ; Wed, 20 Dec 2023 12:42:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 16D8B3A26F; Wed, 20 Dec 2023 12:40:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CzQKicn2" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (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 CE33238DE9; Wed, 20 Dec 2023 12:40:34 +0000 (UTC) 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 Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-55372c1338bso3720585a12.2; Wed, 20 Dec 2023 04:40:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703076033; x=1703680833; 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=d/8vsrFsmIdkN6wX+xgjZzrqJBCn9bwK4adiKoP4ah4=; b=CzQKicn2MIokPQ0Qtpcr/iiB7dAvWxlQPI9p69Cwc9t4vVyR+Y9y2fj0qv2EHsTJ0b +SZwStExf2fhCJ1IW2LnY+1S9TcGGskBCQDfdL9ntaXFIqTSc0aW8GjqBTUtDNkvYnrl WXeJ2xH98+cQj77BMGqTbNe5fSboO8c23xO7qaQuNipzZANR/D60WJjzw/CIYf7yGh7B QISuFB0Ka8hCXMxf2QweVmK4GVXSefwAYCt5uypqNQ+G5PbY+A3ovFwBdaQmSKSKe/Jm 2OGbRdK7pY+BhuyXfhYYnJ8XgG8q4MXJnZWDSK5X4QBbZj3nyenzlAQzR759piZgS8oX nV5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703076033; x=1703680833; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=d/8vsrFsmIdkN6wX+xgjZzrqJBCn9bwK4adiKoP4ah4=; b=lTcqJf5OQoJKy7vEIvd8haz1iYg94+iRJrc0WnoGXQXLwZwgGjy+FpvniDOwGZTv1C slPE/qeK19uswI67SAYtZJy6HETdgsCGTHlKF4FDcq95nzliXz38TwwyyGuc/5d4xdfg gom4YwRW2Vwj1G6XjCpgeBTe/Rp35w9DITrnDJ+pvRxFkcJVPLZ7+PH7W1cnCd8PSmZC tJnzPmA50TEb1NoJULgUZGq5Vs/O2Px5P0UvNZXQuZYn64pW3b9zYT9z/BIp9SKbJRBs KyPKL/yS4/OLQ+17oI5CEEkZJM6b7N7hiJpit4AsGbXj66wEysLjwvDTHggQYP5eFrOE PHjQ== X-Gm-Message-State: AOJu0YxeoWD81w/kFiqYWVMQSd/mdVDJi4V0T7dwWLPlIiHwGPGc2eeK 7v0kds6PaC+nazfngLhfnss= X-Received: by 2002:a17:906:fa84:b0:a19:a19a:eac2 with SMTP id lt4-20020a170906fa8400b00a19a19aeac2mr8418440ejb.123.1703076033051; Wed, 20 Dec 2023 04:40:33 -0800 (PST) Received: from tom-HP-ZBook-Fury-15-G7-Mobile-Workstation.station (net-188-217-59-229.cust.vodafonedsl.it. [188.217.59.229]) by smtp.gmail.com with ESMTPSA id d22-20020a170906345600b00a269597d173sm604258ejb.135.2023.12.20.04.40.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 04:40:32 -0800 (PST) From: Tommaso Merciai To: Cc: linuxfancy@googlegroups.com, sakari.ailus@linux.intel.com, laurent.pinchart@ideasonboard.com, martin.hecht@avnet.eu, tomm.merciai@gmail.com, Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 5/5] media: i2c: alvium: fix req_fr check into alvium_s_frame_interval() Date: Wed, 20 Dec 2023 13:40:23 +0100 Message-Id: <20231220124023.2801417-6-tomm.merciai@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231220124023.2801417-1-tomm.merciai@gmail.com> References: <20231220124023.2801417-1-tomm.merciai@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: 8bit Actually req_fr check into alvium_s_frame_interval() is wrong. In particular req_fr can't be >=max and <= min at the same time. Fix this using clamp and remove dft_fr parameter from alvium_get_frame_interval() not more used. Signed-off-by: Tommaso Merciai --- drivers/media/i2c/alvium-csi2.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c index 240bf991105e..01111a00902d 100644 --- a/drivers/media/i2c/alvium-csi2.c +++ b/drivers/media/i2c/alvium-csi2.c @@ -1171,12 +1171,10 @@ static int alvium_set_bayer_pattern(struct alvium_dev *alvium, } static int alvium_get_frame_interval(struct alvium_dev *alvium, - u64 *dft_fr, u64 *min_fr, u64 *max_fr) + u64 *min_fr, u64 *max_fr) { int ret = 0; - alvium_read(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_RW, - dft_fr, &ret); alvium_read(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_MIN_R, min_fr, &ret); alvium_read(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_MAX_R, @@ -1647,7 +1645,7 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd, { struct alvium_dev *alvium = sd_to_alvium(sd); struct device *dev = &alvium->i2c_client->dev; - u64 req_fr, dft_fr, min_fr, max_fr; + u64 req_fr, min_fr, max_fr; struct v4l2_fract *interval; int ret; @@ -1657,7 +1655,7 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd, if (fi->interval.denominator == 0) return -EINVAL; - ret = alvium_get_frame_interval(alvium, &dft_fr, &min_fr, &max_fr); + ret = alvium_get_frame_interval(alvium, &min_fr, &max_fr); if (ret) { dev_err(dev, "Fail to get frame interval\n"); return ret; @@ -1670,9 +1668,7 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd, req_fr = (u64)((fi->interval.denominator * USEC_PER_SEC) / fi->interval.numerator); - - if (req_fr >= max_fr && req_fr <= min_fr) - req_fr = dft_fr; + req_fr = clamp(req_fr, min_fr, max_fr); interval = v4l2_subdev_state_get_interval(sd_state, 0); -- 2.34.1