Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3285128pxf; Mon, 15 Mar 2021 06:17:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfOR0B5nRsMg8SwQgh84rBuGRWF6uieZaEText0ClMo2YN7PxRYaihbn1nnnngE4+3bPSR X-Received: by 2002:a17:906:405b:: with SMTP id y27mr24067645ejj.332.1615814228753; Mon, 15 Mar 2021 06:17:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615814228; cv=none; d=google.com; s=arc-20160816; b=JvPh24Qa0LCHp7XwamA0LxvjapzUG1ga1nztCxHvK9brCD+5buRYTtr9itIO+x7wcO MeypX4idwUjwCptvC5V3o7ndQUgwOvd+owNd9MO4hDZNLdf4R1PM+nD3l19OM9PwpQnX lz7O7kEcAkLnRSru6OS2PfViL77FzSuL/KbMkq8zQlWgNt+E7O3jlvoY+R+K3ZLSC0uS EyQOfI4vs2V6rqF8Q8ttlPJU+nImIyoO6cC5u9lPJ8VQp8gMQ+sZHrg0yLqkmgmrqDvM AylYKbPEWa6DCwBRnIpwZmaiavfqN0tEefgxJZOgzbdPY+e+HS01FIK037GPZX3H+FHF F9Sw== 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=4WDBE3ATQCbwpl4JvcBDwoe3MohMzHXuF+71vOuhZhM=; b=TE9zeMjLPvxAs4gCIdiGpw7LlgzBm7V4CSNzisFYje7YIrchLBk2Nw6oy8TmDTtqSa 12iqq2DK3kHbK1wvjU2xV8B81xlt/wlZA6TlX5J+D+53gaNIWkT073Ylxj4g9jGNtJ6r e4DAvKCASRJE5QzEn/lM3LSd1QGVvXc2Oin+hR89KaC6KSGV0T8P+FRtMJ7idB7T5mA7 ltAI4SdfhpXVwYmB+sho1t4mAguKWbDZ4xUMG66tQ1sK9swTE8jcFwvjuRY4VV2Y3E8C vhkUkUfycFvGl78OcehZYr9p9GBsV9cvpxUAClnlNtPf+JHSoxlpbpw9u5kG15mBUc3H aWuQ== 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 u14si10849366edx.551.2021.03.15.06.16.45; Mon, 15 Mar 2021 06:17:08 -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 S230434AbhCONPg (ORCPT + 99 others); Mon, 15 Mar 2021 09:15:36 -0400 Received: from relay9-d.mail.gandi.net ([217.70.183.199]:58205 "EHLO relay9-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230133AbhCONPE (ORCPT ); Mon, 15 Mar 2021 09:15:04 -0400 X-Originating-IP: 79.22.58.175 Received: from uno.homenet.telecomitalia.it (host-79-22-58-175.retail.telecomitalia.it [79.22.58.175]) (Authenticated sender: jacopo@jmondi.org) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id D979DFF809; Mon, 15 Mar 2021 13:14:59 +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 v2 04/18] media: i2c: rdacm20: Replace goto with a loop Date: Mon, 15 Mar 2021 14:14:58 +0100 Message-Id: <20210315131512.133720-5-jacopo+renesas@jmondi.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210315131512.133720-1-jacopo+renesas@jmondi.org> References: <20210315131512.133720-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 4d9bac87cba8..e190fd2e611a 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,18 @@ 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; + 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