From: Jonathan Cameron <jic23@kernel.org>
To: Shreeya Patel <shreeya.patel@collabora.com>
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
Date: Sat, 7 May 2022 17:47:45 +0100 [thread overview]
Message-ID: <20220507174745.70666eeb@jic23-huawei> (raw)
In-Reply-To: <8916313f-0974-0d2d-091b-17e5765c0304@collabora.com>
On Tue, 3 May 2022 22:37:49 +0530
Shreeya Patel <shreeya.patel@collabora.com> 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 <Zhigang.Shi@liteon.com>
> >
> > Add initial support for ltrf216a ambient light sensor.
> >
> > Datasheet: gitlab.steamos.cloud/shreeya/iio/-/blob/main/LTRF216A.pdf
> > Co-developed-by: Shreeya Patel <shreeya.patel@collabora.com>
> > Signed-off-by: Shreeya Patel <shreeya.patel@collabora.com>
> > Signed-off-by: Zhigang Shi <Zhigang.Shi@liteon.com>
> > ---
> >
...
> > +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
next prev parent reply other threads:[~2022-05-07 16:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-03 14:43 [PATCH v3 0/3] Add LTRF216A Driver Shreeya Patel
2022-05-03 14:43 ` [PATCH v3 1/3] dt-bindings: vendor-prefixes: Add 'ltr' as deprecated vendor prefix Shreeya Patel
2022-05-03 14:43 ` [PATCH v3 2/3] dt-bindings: Document ltrf216a light sensor bindings Shreeya Patel
2022-05-03 14:43 ` [PATCH v3 3/3] iio: light: Add support for ltrf216a sensor Shreeya Patel
2022-05-03 17:07 ` Shreeya Patel
2022-05-07 16:47 ` Jonathan Cameron [this message]
2022-05-07 16:59 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220507174745.70666eeb@jic23-huawei \
--to=jic23@kernel.org \
--cc=Zhigang.Shi@liteon.com \
--cc=alvaro.soliverez@collabora.com \
--cc=devicetree@vger.kernel.org \
--cc=kernel@collabora.com \
--cc=krisman@collabora.com \
--cc=krzk@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh+dt@kernel.org \
--cc=shreeya.patel@collabora.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox