Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp193424pxb; Thu, 14 Apr 2022 19:49:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz9zQmj2jpb8cubSdPGWjBxz2nOKQpZDyKdiWAViJDCPSceMn/ZhrmsQSwnoFN+TUiNtPSf X-Received: by 2002:a17:90a:6781:b0:1cb:11f0:9c51 with SMTP id o1-20020a17090a678100b001cb11f09c51mr1758423pjj.243.1649990986914; Thu, 14 Apr 2022 19:49:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1649990986; cv=pass; d=google.com; s=arc-20160816; b=lUqpjRHaNvTMmIRjyoI7t/eEiIxAYlJ3c/cMjYrjVLZR3YR6+4egqzPA1aUMHdR2CZ L4tA0JsUYA/4C+6HoP8rd6a979enOxgRyRa6Oo8gBzZmXx40sKUD5oEj6ssvph71p2bd xI4l3pHeWbn/AwiRYAK3q1EsgMIYX9PgozQUKA0suVhthbdWcd3nQ5SfYF2qeQYXs4xJ UKTP+qvcMeSiZJI56WveR5M0jZFqELEN+EGjLi4AftAzP2VrLaW5vlfENiendxCYKbSd Wpw1ovSCwjpokIRjVzF+wkgACl+vIdBhn5WxpEsRmIWEFCaB22GM64hKrdRNFPOoehZI K3TA== ARC-Message-Signature: i=2; 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=EYkKCNJTlijY39vvp5OIY+Ckmri6Ev74aKWsd1JHd/s=; b=QeAjssf7AKbajWGBkRzVRBTe3LDP5PoJ4nIJ2xwTcOJZLML2K4CAw+WQ+0fffYyGc3 vVdy3r0v4qyxg6mkHwSTzm10Zp7utTSI5yonow+He8Ug4ROnARTcW63bt/tartsCQbG3 i0NDlRN6KQyoa9BVoGfvwEBAalmVVedCwKKTfXOe1N0tqwTKlt1hE018Q58aAmsZnFZr 7PJ3urOo7lZxcx4LMV4Zd91hQMSNQ8VYdQDGAl/ZJp45UQIrGHhbjz2LDFQqJBJcl8YE orjrBuGpO9QeDsPqXCiVTLFuQ5H4Lvj7FGAx1p1cl7/CNbN6ysXGCYzWS6pWYBFQaYDS sSXg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@iki.fi header.s=lahtoruutu header.b=e+TfM2wa; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r3-20020a632043000000b003816043f052si328240pgm.583.2022.04.14.19.49.32; Thu, 14 Apr 2022 19:49:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@iki.fi header.s=lahtoruutu header.b=e+TfM2wa; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240321AbiDNIZN (ORCPT + 99 others); Thu, 14 Apr 2022 04:25:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230029AbiDNIZJ (ORCPT ); Thu, 14 Apr 2022 04:25:09 -0400 Received: from lahtoruutu.iki.fi (lahtoruutu.iki.fi [IPv6:2a0b:5c81:1c1::37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 002F45DA0C for ; Thu, 14 Apr 2022 01:22:45 -0700 (PDT) Received: from hillosipuli.retiisi.eu (89-27-103-169.bb.dnainternet.fi [89.27.103.169]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: sailus) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 07E191B002EF; Thu, 14 Apr 2022 11:22:40 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1649924560; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=EYkKCNJTlijY39vvp5OIY+Ckmri6Ev74aKWsd1JHd/s=; b=e+TfM2wal2N7qhp3PDhUDxeGg0o+fXMRmR0beBy4JOjors5QTXR88FLPCjZoxJ+9+wZ+5w /tCrBM5TAUikVPkgq196aH5/S0gLYZci9xLwNNJfphHlZfRi0DIjJJt00udKKHvJGdB6Q3 YKkvnbkTdmhGmJhnpxgS6dXHMraUHn0CEBWcUXsdSWhcLiCbvprZXNT0X5tKYSHSPd2MA6 AiaECi/UOcVyyT7y1iRwElUVTsMbOLNdthCJY8s9WAyeKiJ+pJcfqmrIgrDPjF2IQpyEoq UAS9YNY43QTcrpSe6PTPGamAHepyTjFUW9N4Xhclpt7nEgVoJlWR2mFHA9AbPg== Received: from valkosipuli.retiisi.eu (valkosipuli.localdomain [192.168.4.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by hillosipuli.retiisi.eu (Postfix) with ESMTPS id 97609634C91; Thu, 14 Apr 2022 11:22:39 +0300 (EEST) Date: Thu, 14 Apr 2022 11:22:39 +0300 From: Sakari Ailus To: Moses Christopher Bollavarapu Cc: mchehab@kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] media: ov7640: Use ARRAY_SIZE instead of manual checking Message-ID: References: <20220317144714.47442-1-mosescb.dev@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220317144714.47442-1-mosescb.dev@gmail.com> ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1649924560; a=rsa-sha256; cv=none; b=ZxGzYidSEx+F6jCtlIQ7jNuENqk9rJUjkASVBXmtKz3e982+bNFp+yMlQ6BxIFTsvCT3+x IjhW/IrECXUHF9aDjOwLP6yuC1/MPGiADGGLZ+kjVxaEIkngYP7Sf2O4PYwhSFlbtLWrER 6etULUE1maFR8fYf8IADt9hFc8zW1f2CqSYSE7H6Lfqo7sAAhTnf3iH1h1R+MNSuCJEOo8 BU5ERtoUGbTFyJdhhyIv1xp0Z+K58FGVH188vdi/its34H3b28vL6ITVCZDADKz/Qwgn8/ FY+r4GB0WubSLchRXNMGEIejL0o8JGsE01E2PG5o/bHBLaE9ZbU6BddIsOrj4w== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=sailus smtp.mailfrom=sakari.ailus@iki.fi ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1649924560; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=EYkKCNJTlijY39vvp5OIY+Ckmri6Ev74aKWsd1JHd/s=; b=Rq3z61ikFNeZ7rbL/vX2GFOe0Pb0wXm/dQTg7uZ2cb5oRZQ0A5IHMxgnT0cFPyEeDAEWvc /WUPsLo4fOJJqE3h7aHlQctq0Ly/FMVP5+21H2rkBmz3NaZMnU9cqEm0ZPhrwY1FT8m0Mn NUkGSb/bJq7zTn8Bf99m3QwdBrZh2JtvAKDgG4Ex2JBAf/p9sReVjsiS75hYID9EpD+W9h C5Fe1sJAmRVBHg2arMxhEU1eDkpvOtIneNyBTqjixsWPX+eps53IGxRtW7rXwDQ9I38RMw /WP7nyGcLVhY3UUiGPPgznh1V+saLBX2U/76tzNCUGNpkGSzjlbiVHlH/fEcVg== X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Moses, On Thu, Mar 17, 2022 at 03:47:14PM +0100, Moses Christopher Bollavarapu wrote: > Currently, the driver ends the reg-val list with a 0xFF as a check to stop > the loop. Instead an array of reg-vals can be used to avoid this check, > by using the ARRAY_SIZE(arr) macro to obtain the length of the array and > iterate over it. > > Signed-off-by: Moses Christopher Bollavarapu > --- > drivers/media/i2c/ov7640.c | 33 +++++++++++++++++++-------------- > 1 file changed, 19 insertions(+), 14 deletions(-) > > diff --git a/drivers/media/i2c/ov7640.c b/drivers/media/i2c/ov7640.c > index 010803d58ce8..977cd2d8ad33 100644 > --- a/drivers/media/i2c/ov7640.c > +++ b/drivers/media/i2c/ov7640.c > @@ -13,23 +13,28 @@ > MODULE_DESCRIPTION("OmniVision ov7640 sensor driver"); > MODULE_LICENSE("GPL v2"); > > -static const u8 initial_registers[] = { > - 0x12, 0x80, > - 0x12, 0x54, > - 0x14, 0x24, > - 0x15, 0x01, > - 0x28, 0x20, > - 0x75, 0x82, > - 0xFF, 0xFF, /* Terminator (reg 0xFF is unused) */ > +struct reg_val { > + u8 reg; > + u8 val; > }; > > -static int write_regs(struct i2c_client *client, const u8 *regs) > -{ > - int i; > +static const struct reg_val regval_init[] = { > + {0x12, 0x80}, > + {0x12, 0x54}, > + {0x14, 0x24}, > + {0x15, 0x01}, > + {0x28, 0x20}, > + {0x75, 0x82}, > +}; > > - for (i = 0; regs[i] != 0xFF; i += 2) > - if (i2c_smbus_write_byte_data(client, regs[i], regs[i + 1]) < 0) > +static int write_regs(struct i2c_client *client, > + const struct reg_val *rv, int len) Please align to opening parenthesis on the next time. Somehow checkpatch.pl doesn't seem to complain about this. I.e. ... func(arg1, ..., arg2); Applied. > +{ > + while (--len >= 0) { > + if (i2c_smbus_write_byte_data(client, rv->reg, rv->val) < 0) > return -1; > + rv++; > + } > return 0; > } > > @@ -56,7 +61,7 @@ static int ov7640_probe(struct i2c_client *client, > v4l_info(client, "chip found @ 0x%02x (%s)\n", > client->addr << 1, client->adapter->name); > > - if (write_regs(client, initial_registers) < 0) { > + if (write_regs(client, regval_init, ARRAY_SIZE(regval_init)) < 0) { > v4l_err(client, "error initializing OV7640\n"); > return -ENODEV; > } -- Regards, Sakari Ailus