Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4419675iob; Sun, 8 May 2022 12:07:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyq/hvMw7z8bRyOQ9yJRSGa7WMSMosUgy6HQHzAvTrkdT25zZTwISEt/YmcpNEwurtBrvx/ X-Received: by 2002:a17:906:7304:b0:6e0:6918:ef6f with SMTP id di4-20020a170906730400b006e06918ef6fmr11648196ejc.370.1652036823414; Sun, 08 May 2022 12:07:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652036823; cv=none; d=google.com; s=arc-20160816; b=ZIXKMb6KL6BqpbsGus2i6YuJ8043XQuqx/LDhi7eo9nE5g6Kxf/Kquh4bjqoZrxwNV 4FBYQipqKJrv3qikl29JfJ4ejK4HPPYn0Uug4Ae515J45MQ8o2fdZ9WSqddZdLPG/QKr YxKx1AL16pihhgJL0BEJD971CrdFhw6+m7xCm/TikBnrkT0+yj/XXCQFkd41Ip3Czbi0 +DZea5+BtsckE0o4KfU2aIKgvZKddmBudsvE0v1/AvhngM8IJEjy616XmmdSgwfJWI8t mS102coOcNipYJ6h2I0BFRGHblR2xqzwHMmnbyG0+D+PcdQOfrUtIjMcb7NIgS1j/Doy JNTg== 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:subject:cc:to:from:date :dkim-signature; bh=EG7TFqwYjLdYdP0FIuOuzDLWCBNca7p0qFyoWeNoY0k=; b=gjzQ2SNF7ugB0kbyxctzNNoHDRPR5LOtBqrlDfHKxrWdrc1MTEG306KVDMsq2gDV+2 avPX5j9lsPZZRfX0b3u3pdfmyna1T8wayEEVAUCAPWohpqUBf8LBfi9JSujDoHbBE9B+ 78QBjyzzbWxLrpnk62GULmAzbUn8J9JV3e8ff5r8wN6SOY/TdnjjZLDqPh5ovwwDs0sx 1kDFyEiYvGo7AQs3os9YhYvyaUAgzjMLNdjz2CoEEH8Y4TfiwKHMXo5AXUcyT8YYw52p yhGpWALbHlsTxSXizrvKZXNgCXWlcwaPvtI30UiSGpmoaT97jHFFHInb5uoPbTHt9Nmx 9m4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kmkA2u3h; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ov5-20020a170906fc0500b006f0b9f92e54si9806371ejb.810.2022.05.08.12.06.39; Sun, 08 May 2022 12:07:03 -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=@kernel.org header.s=k20201202 header.b=kmkA2u3h; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386310AbiEGQnK (ORCPT + 99 others); Sat, 7 May 2022 12:43:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241566AbiEGQnJ (ORCPT ); Sat, 7 May 2022 12:43:09 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7CCFDFB2; Sat, 7 May 2022 09:39:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 9C1C2B80AE4; Sat, 7 May 2022 16:39:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7670C385A5; Sat, 7 May 2022 16:39:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651941559; bh=FJdOwT69X41GLePtbzqNFP3tJgjdvaLGZc3c8OeOsuE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=kmkA2u3hRqXbr4cJjFfCqMV1zYOd/Ll83YNcSA1pMSa9qQuhXnHldLmUrznXgN91H /pc5ZtMqgSB0N9gM+KXeKWmj5xwVhlN7G+BARXg8cV9PHR9t3SFwuuyqEsCwC8k3wT gHZcl7X56815UqVonYA1YSilK5bWDNP7B036DrPxh55GATVHNRmF5XJAniFIljTwpN DPrCqvD0jV8TPo+BjxUXI5keQmnfg7VaZMXKJhEVhqgEGN6yhiuhN/LlnGrXjBjnRc r/fHkMSEehgG2x1Mtxzt8aTZEhJUhLvTGHoJK7D7MolGfiWzaWH1Sad9YNNsR0Okx5 diU1oOIRRXsnQ== Date: Sat, 7 May 2022 17:47:45 +0100 From: Jonathan Cameron To: Shreeya Patel Cc: lars@metafoo.de, robh+dt@kernel.org, Zhigang.Shi@liteon.com, krzk@kernel.org, krisman@collabora.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, alvaro.soliverez@collabora.com Subject: Re: [PATCH v3 3/3] iio: light: Add support for ltrf216a sensor Message-ID: <20220507174745.70666eeb@jic23-huawei> In-Reply-To: <8916313f-0974-0d2d-091b-17e5765c0304@collabora.com> References: <20220503144354.75438-1-shreeya.patel@collabora.com> <20220503144354.75438-4-shreeya.patel@collabora.com> <8916313f-0974-0d2d-091b-17e5765c0304@collabora.com> X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 On Tue, 3 May 2022 22:37:49 +0530 Shreeya Patel wrote: > Hi Jonathan, > Hi Shreeya, > > Just one comment inline related to your previous review. > > On 03/05/22 20:13, Shreeya Patel wrote: > > From: Zhigang Shi > > > > Add initial support for ltrf216a ambient light sensor. > > > > Datasheet: gitlab.steamos.cloud/shreeya/iio/-/blob/main/LTRF216A.pdf > > Co-developed-by: Shreeya Patel > > Signed-off-by: Shreeya Patel > > Signed-off-by: Zhigang Shi > > --- > > ... > > +struct ltrf216a_data { > > + struct i2c_client *client; > > + u32 int_time; > > + u16 int_time_fac; > > + u8 als_gain_fac; > > + struct mutex mutex; /* Protect read and write operations */ > > I wasn't really sure about your comment related to the lock description > here. > I see we are using these locks in read_raw and write_raw functions only and > hence I've added the above comment. A lock should always ensure consistency of data (either in software or in hardware registers) so that we don't end up with odd results due to race conditions between multiple writers / readers. The comment for a lock should call out what 'data' is being protected. In this particular case I'm not sure what that is. Take the *_get_lux() call in read_raw() That performs a pair of calls to _read_data(). The _read_data() calls just check for valid data and then read the channels. The i2c accesses will be protected by the underlying bus locks and I can't otherwise see anything in those calls that needs protecting with locks (all the data is local). Finally we have some maths done with data->als_gain_fac and data->int_time_fac als_gain_fac is currently a constant in the driver (it's set only in probe I think). int_time_fac is more interesting. That is set alongside a register write in _set_int_time(). So I 'think' the entire purpose of the lock is to ensure that the value of integration time doesn't not change whilst a reading is progress (so we can do the right maths). Hence the comment should be something along the lines of /* * Ensure cached value of integration time is consistent with hardware setting * and remains constant during a measurement of Lux. */ This extra detail makes it easy to tell where the lock must be taken which is very useful for anyone modifying the driver in the future. If they expand the scope of the lock, then they should also update the documentation to match. > > > > Thanks, > Shreeya Patel