Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1229320pxb; Sun, 21 Feb 2021 17:09:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJxE18L/f486qbJ281jG8TMTIA73ErjVkMSj+liMvopgri6Te5ieChq2LADfVfyjg6y/loMS X-Received: by 2002:a17:906:3b53:: with SMTP id h19mr2593709ejf.145.1613956170125; Sun, 21 Feb 2021 17:09:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613956170; cv=none; d=google.com; s=arc-20160816; b=ARHthZhch4vYaPi5QVPeWUEW6zskjOtZWADaY7iMBkz8mxrtpJzO0B4lZVbHWzk8W4 4w11I+cqYGvwh1BVEV+mm96miTGLwUHmtnxNq/PcrCIQBBQ9JemMSdwApLEL6uug2Y5c KfALJmmzFBNB+Ubug7pK3l7ATck+e75nrCRjrhB3iM3te5VMkPBa0B5kU94JO/+kgFZW vGPkYwnYwqjOoOTM9guPMqxdbc1nqrh0/BfirMKI2zdSme7EdhqNR5D9kuCRwW9Kj7YY 0fa2ztPG2xeosvmQgvM822j5Rb0dq5obCGS7judjUoNRPyNMSHDxFLitspocHC2phwoi lvmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=xl5j6xIw7kw34gKY2nIyY5jt+sFEIMW0C6JU1N9Pe5w=; b=pWLQqOdm0Epod8scCVEKH2dwaAhhDjc11HS1IA/vWNx59LsmU2T/Htki25BhEBCTHI xxmEAzGAz6WbivMalgGVybvJzY2v8SlviqWmxvO0l2fpebCsf4IQpwU+26GMsnz9qaeE 2rjndmf8Yeehn3+B3WSBM7U441TbItJAp+xNBEaTtSwZhDXrE1MRjCIM8UViaDMHzKju PdBouCHI6zrvKfVywgcyet81SLA7sCnqttcWbFFLqEm02wRN+s2mZxBA0Y3iE78ggHcM 2Nszn9m4F0Hh5nvKq72LBoxOMtZDE7nHvbw3wBWNj/Yg2o7/Pt/gE6ziVcTaDlnYdC7n cL1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=EQ2QzsQJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a20si11584988ejg.257.2021.02.21.17.09.07; Sun, 21 Feb 2021 17:09:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=EQ2QzsQJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230128AbhBVBGN (ORCPT + 99 others); Sun, 21 Feb 2021 20:06:13 -0500 Received: from perceval.ideasonboard.com ([213.167.242.64]:54416 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230090AbhBVBGL (ORCPT ); Sun, 21 Feb 2021 20:06:11 -0500 Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7757D58E; Mon, 22 Feb 2021 02:05:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1613955929; bh=AD4yr/AoKlgw4K2SHvNO0bY6/vPA6ZTnOjAseSwj2nM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=EQ2QzsQJWUXfeGfgTh/jR0+on5jL6yJopFzoVq34FiGboe2ivwtMzZrKaWEa+KOFE BmCqjKpc4r9q9EukJOqOUXXo5rQFbTXssxTFOfQ5gQVXI/TCCt6Va33NGI1Z/35MIq OE5oAxuBYbFUab47n03uvK1BKZbCuPqI8KuIHW2Y= Date: Mon, 22 Feb 2021 03:05:03 +0200 From: Laurent Pinchart To: Jacopo Mondi Cc: Kieran Bingham , niklas.soderlund+renesas@ragnatech.se, geert@linux-m68k.org, Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 03/16] media: i2c: rdacm20: Replace goto with a loop Message-ID: References: <20210216174146.106639-1-jacopo+renesas@jmondi.org> <20210216174146.106639-4-jacopo+renesas@jmondi.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jacopo, Reviewed-by: Laurent Pinchart On Wed, Feb 17, 2021 at 01:01:26PM +0000, Kieran Bingham wrote: > On 16/02/2021 17:41, Jacopo Mondi wrote: > > During the camera module initialization the image sensor PID is read to > > verify it can correctly be identified. The current implementation is > > rather confused and uses a loop implemented with a label and a goto. > > > > Replace it with a more compact for() loop. > > > > No functional changes intended. > > I think there is a functional change in here, but I almost like it. > > Before, if the read was successful, it would check to see if the > OV10635_PID == OV10635_VERSION, and if not it would print that the read > was successful but a mismatch. > > Now - it will retry again instead, and if at the end of the retries it > still fails then it's a failure. > > This means we perhaps don't get told if the device id is not correct in > the same way, but it also means that if the VERSION was not correct > because of a read error (which I believe i've seen occur), it will retry. I was going to ask about that, whether we can have a successful I2C read operation that would return incorrect data. If we do, aren't we screwed ? If there's a non-negligible probability that reads will return incorrect data without any way to know about it (for other registers than the version register of course), then I would consider that writes could fail the same way, and that would mean an unusable device, wouldn't it ? If, on the other hand, read failures can always (or nearly always, ignoring space neutrinos and similar niceties) be detected, then I think we should avoid the functional change. > Because there is a functional change you might want to update the > commit, but I still think this is a good change overall. > > Reviewed-by: Kieran Bingham > > > Signed-off-by: Jacopo Mondi > > --- > > drivers/media/i2c/rdacm20.c | 27 ++++++++++----------------- > > 1 file changed, 10 insertions(+), 17 deletions(-) > > > > diff --git a/drivers/media/i2c/rdacm20.c b/drivers/media/i2c/rdacm20.c > > index 4d9bac87cba8..6504ed0bd3bc 100644 > > --- a/drivers/media/i2c/rdacm20.c > > +++ b/drivers/media/i2c/rdacm20.c > > @@ -59,6 +59,8 @@ > > */ > > #define OV10635_PIXEL_RATE (44000000) > > > > +#define OV10635_PID_TIMEOUT 3 > > + > > static const struct ov10635_reg { > > u16 reg; > > u8 val; > > @@ -452,7 +454,7 @@ static const struct v4l2_subdev_ops rdacm20_subdev_ops = { > > > > static int rdacm20_initialize(struct rdacm20_device *dev) > > { > > - unsigned int retry = 3; > > + unsigned int i; > > int ret; > > > > /* Verify communication with the MAX9271: ping to wakeup. */ > > @@ -501,23 +503,14 @@ static int rdacm20_initialize(struct rdacm20_device *dev) > > return ret; > > usleep_range(10000, 15000); > > > > -again: > > - ret = ov10635_read16(dev, OV10635_PID); > > - if (ret < 0) { > > - if (retry--) > > - goto again; > > - > > - dev_err(dev->dev, "OV10635 ID read failed (%d)\n", > > - ret); > > - return -ENXIO; > > + for (i = 0; i < OV10635_PID_TIMEOUT; ++i) { > > + ret = ov10635_read16(dev, OV10635_PID); > > + if (ret == OV10635_VERSION) > > + break; > > + usleep_range(1000, 2000); > > } > > - > > - if (ret != OV10635_VERSION) { > > - if (retry--) > > - goto again; > > - > > - dev_err(dev->dev, "OV10635 ID mismatch (0x%04x)\n", > > - ret); > > + if (i == OV10635_PID_TIMEOUT) { > > + dev_err(dev->dev, "OV10635 ID read failed (%d)\n", ret); > > return -ENXIO; > > } > > -- Regards, Laurent Pinchart