Message ID | 20231220124023.2801417-6-tomm.merciai@gmail.com (mailing list archive) |
---|---|
State | Accepted |
Delegated to: | Sakari Ailus |
Headers |
Received: from sv.mirrors.kernel.org ([139.178.88.99]) by www.linuxtv.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from <linux-media+bounces-2803-patchwork=linuxtv.org@vger.kernel.org>) id 1rFvu5-00HIKK-Tm for patchwork@linuxtv.org; Wed, 20 Dec 2023 12:42:26 +0000 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 3B1FC2882C1 for <patchwork@linuxtv.org>; Wed, 20 Dec 2023 12:42:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9E6A839869; Wed, 20 Dec 2023 12:40:36 +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-media@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-Google-Smtp-Source: AGHT+IEddufbwv0CffqXBbRkP0gjGsls1zIkKQt72ukCuasMEuDugArS5PCYwMpWd6ZKRUv64IooIw== 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 <tomm.merciai@gmail.com> 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 <mchehab@kernel.org>, 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-media@vger.kernel.org List-Id: <linux-media.vger.kernel.org> List-Subscribe: <mailto:linux-media+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-media+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-LSpam-Score: -4.8 (----) X-LSpam-Report: No, score=-4.8 required=5.0 tests=BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,FREEMAIL_FORGED_FROMDOMAIN=0.001,FREEMAIL_FROM=0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_MED=-2.3 autolearn=ham autolearn_force=no |
Series |
media: i2c: alvium: store frame interval in subdev
|
|
Commit Message
Tommaso Merciai
Dec. 20, 2023, 12:40 p.m. UTC
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 <tomm.merciai@gmail.com>
---
drivers/media/i2c/alvium-csi2.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
Comments
Hi Tommaso, Thank you for the patch. On Wed, Dec 20, 2023 at 01:40:23PM +0100, Tommaso Merciai wrote: > 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. The commit message should have explained why clamping is better than picking a default value, as that's a functional change. If you propose an updated commit message in a reply, I think Sakari can update the patch when applying the series to his tree, there's no need for a v4. > Signed-off-by: Tommaso Merciai <tomm.merciai@gmail.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > --- > 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); >
Hi Laurent, On Wed, Dec 20, 2023 at 03:02:36PM +0200, Laurent Pinchart wrote: > Hi Tommaso, > > Thank you for the patch. > > On Wed, Dec 20, 2023 at 01:40:23PM +0100, Tommaso Merciai wrote: > > 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. > > The commit message should have explained why clamping is better than > picking a default value, as that's a functional change. If you propose > an updated commit message in a reply, I think Sakari can update the > patch when applying the series to his tree, there's no need for a v4. What about: 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. Clamp function make sure that if the setted value exceeds the limits is replaced with min_fr/max_fr instead of setting the value readed back from the hw. What do you think? Thanks & Regards, Tommaso > > > Signed-off-by: Tommaso Merciai <tomm.merciai@gmail.com> > > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > > > --- > > 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); > > > > -- > Regards, > > Laurent Pinchart
Hi Tommaso, On Wed, Dec 20, 2023 at 02:52:53PM +0100, Tommaso Merciai wrote: > Hi Laurent, > > On Wed, Dec 20, 2023 at 03:02:36PM +0200, Laurent Pinchart wrote: > > Hi Tommaso, > > > > Thank you for the patch. > > > > On Wed, Dec 20, 2023 at 01:40:23PM +0100, Tommaso Merciai wrote: > > > 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. > > > > The commit message should have explained why clamping is better than > > picking a default value, as that's a functional change. If you propose > > an updated commit message in a reply, I think Sakari can update the > > patch when applying the series to his tree, there's no need for a v4. > > What about: > > 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. > > Clamp function make sure that if the setted value exceeds the limits is > replaced with min_fr/max_fr instead of setting the value readed back > from the hw. > > What do you think? I used this, hopefully it's ok: media: i2c: alvium: fix req_fr check in alvium_s_frame_interval() req_fr check in alvium_s_frame_interval() is incorrect. In particular req_fr can't be >=max and <= min at the same time. Ensure the requested frame rate remains within the supported range between min_fr and max_fr by clamping it. Also remove the unused dft_fr argument of alvium_get_frame_interval().
Hi Sakari, Sorry for delay. On Wed, Feb 14, 2024 at 11:14:35AM +0000, Sakari Ailus wrote: > Hi Tommaso, > > On Wed, Dec 20, 2023 at 02:52:53PM +0100, Tommaso Merciai wrote: > > Hi Laurent, > > > > On Wed, Dec 20, 2023 at 03:02:36PM +0200, Laurent Pinchart wrote: > > > Hi Tommaso, > > > > > > Thank you for the patch. > > > > > > On Wed, Dec 20, 2023 at 01:40:23PM +0100, Tommaso Merciai wrote: > > > > 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. > > > > > > The commit message should have explained why clamping is better than > > > picking a default value, as that's a functional change. If you propose > > > an updated commit message in a reply, I think Sakari can update the > > > patch when applying the series to his tree, there's no need for a v4. > > > > What about: > > > > 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. > > > > Clamp function make sure that if the setted value exceeds the limits is > > replaced with min_fr/max_fr instead of setting the value readed back > > from the hw. > > > > What do you think? > > I used this, hopefully it's ok: > > media: i2c: alvium: fix req_fr check in alvium_s_frame_interval() > > req_fr check in alvium_s_frame_interval() is incorrect. In particular > req_fr can't be >=max and <= min at the same time. Ensure the requested > frame rate remains within the supported range between min_fr and max_fr by > clamping it. > > Also remove the unused dft_fr argument of alvium_get_frame_interval(). Looks good to me! :) Thanks for this. Regards, Tommaso > > -- > Kind regards, > > Sakari Ailus
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);