Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1559447pxf; Fri, 19 Mar 2021 09:46:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJlB6GkJUaUZpx4b4QXZhNiXlTM+FXO5JmJlD+nclSWvWzYhf+40JSYd9OFFKMhLCqqRQH X-Received: by 2002:a17:906:33da:: with SMTP id w26mr5423112eja.302.1616172366340; Fri, 19 Mar 2021 09:46:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616172366; cv=none; d=google.com; s=arc-20160816; b=PXSx3AE06TaUy2NF6aKPxjTeGO4igDyq65yrT4qcfDo9zT4oHbclkLl7TIs06eL0DF bkX4+0vlInjCUIPyL/PfV7+m3OfitFC0GQfNikoIKFfT5P5kEBQgyxjga5ABYdDRB9q5 D6vnjXWIaD8HBirXAIs7x5gRAzY9lGWqZfWRoxhXGhYfb/fNvVp47c0f8kJYjXahLMvX obu0mt9rvbi2V6jZ2K6mL3XCNStex5FfKGqkKWMiNmb9bIwVbr/Kg3fPGlzg/S9XHXfF fOn5gBU9xLReRfXPwvQfkMXv8kCuO50cfn+HZmPgTorQXlPyfJrjrHFubdTvZTFqh3+7 JcDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=SHf136OuGEyjPxFaa9EYuNO7YatVxoe3Qij/d0soW+w=; b=eUmNpFDzyqCMFvQ+Ehe2P5rD2VIgBxeRsJJGE3ztheIEEqSbsx3E5q9LVH2Eppc8E2 yYLSspu83KeMLp+LlyQgTMovfr0MfIeA07fY9j23+46gQKMQTl15ndNmDDn4P9frOrh+ jtX5VQxruCeSEwdBCbxxERfopfUbMSkhZqlAVWF5b9dWzs1tevV6RK0ZPpRRxtz3NcIU urD561r6Ftm5jE5RTXWFc/WVuiDIvpAPiRWLe3p59nK/mbF3eAjoFeCLn+1j84XPSDJY 1r6nIN0u82qt2olNCwqlaek8dUrcVImMujeBWQSBENPqU75CiWfrxm9Kdmi9TS5aW18W T13g== ARC-Authentication-Results: i=1; mx.google.com; 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 d10si4703776edp.256.2021.03.19.09.45.42; Fri, 19 Mar 2021 09:46:06 -0700 (PDT) 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; 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 S230435AbhCSQmy (ORCPT + 99 others); Fri, 19 Mar 2021 12:42:54 -0400 Received: from relay6-d.mail.gandi.net ([217.70.183.198]:41879 "EHLO relay6-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230391AbhCSQm0 (ORCPT ); Fri, 19 Mar 2021 12:42:26 -0400 X-Originating-IP: 5.92.35.220 Received: from uno.localdomain (mob-5-92-35-220.net.vodafone.it [5.92.35.220]) (Authenticated sender: jacopo@jmondi.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 7C98EC0007; Fri, 19 Mar 2021 16:42:19 +0000 (UTC) From: Jacopo Mondi To: kieran.bingham+renesas@ideasonboard.com, laurent.pinchart+renesas@ideasonboard.com, niklas.soderlund+renesas@ragnatech.se, geert@linux-m68k.org Cc: Jacopo Mondi , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Laurent Pinchart Subject: [PATCH v3 16/19] media: i2c: rdacm20: Replace goto with a loop Date: Fri, 19 Mar 2021 17:41:45 +0100 Message-Id: <20210319164148.199192-17-jacopo+renesas@jmondi.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210319164148.199192-1-jacopo+renesas@jmondi.org> References: <20210319164148.199192-1-jacopo+renesas@jmondi.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- drivers/media/i2c/rdacm20.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/drivers/media/i2c/rdacm20.c b/drivers/media/i2c/rdacm20.c index 7bdcfafa6c10..760705dd2918 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; @@ -438,7 +440,7 @@ static int rdacm20_get_fmt(struct v4l2_subdev *sd, static int rdacm20_init(struct v4l2_subdev *sd, unsigned int val) { struct rdacm20_device *dev = sd_to_rdacm20(sd); - unsigned int retry = 3; + unsigned int i; int ret; /* @@ -478,23 +480,18 @@ static int rdacm20_init(struct v4l2_subdev *sd, unsigned int val) return ret; usleep_range(10000, 15000); -again: - ret = ov10635_read16(dev, OV10635_PID); - if (ret < 0) { - if (retry--) - goto again; + for (i = 0; i < OV10635_PID_TIMEOUT; ++i) { + ret = ov10635_read16(dev, OV10635_PID); + if (ret == OV10635_VERSION) + break; + else if (ret >= 0) + /* Sometimes we get a successful read but a wrong ID. */ + dev_dbg(dev->dev, "OV10635 ID mismatch (%d)\n", ret); - dev_err(dev->dev, "OV10635 ID read failed (%d)\n", - ret); - return -ENXIO; + 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; } -- 2.30.0