mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nikhil Gautam <nikhilgtr@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: "David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Stefan Windfeldt-Prytz" <stefan.windfeldt-prytz@axis.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 1/4] iio: light: opt4001: Fix read-modify-write of wrong register in power down
Date: Mon, 13 Jul 2026 09:03:29 +0530	[thread overview]
Message-ID: <6d7e489d-5438-4a76-829f-45796f1a4117@gmail.com> (raw)
In-Reply-To: <20260713014214.74a12af9@jic23-huawei>



On 13-07-2026 06:12 am, Jonathan Cameron wrote:
> On Mon, 13 Jul 2026 01:54:48 +0530
> Nikhil Gautam <nikhilgtr@gmail.com> wrote:
>
>> opt4001_power_down() intends to clear the operating mode bits in the
>> CTRL register but reads OPT4001_DEVICE_ID instead of OPT4001_CTRL.
>> The device ID value with the mode bits masked out is then written to
>> CTRL, corrupting the conversion time and fault count configuration.
>>
>> Read the CTRL register instead so only the operating mode bits are
>> cleared and the rest of the configuration is preserved.
>>
>> Signed-off-by: Nikhil Gautam <nikhilgtr@gmail.com>
> Fixes tag please (you asked in the cover letter and yes it is appropriate
> even though these go all the way back).
>
> Looks correct but I think we can take this opportunity to simplify
> the code whilst fixing the issue.
Sure, will add Fixes tags.
>> ---
>>   drivers/iio/light/opt4001.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/iio/light/opt4001.c b/drivers/iio/light/opt4001.c
>> index ba4eb82d9bc2..f2cf496cc243 100644
>> --- a/drivers/iio/light/opt4001.c
>> +++ b/drivers/iio/light/opt4001.c
>> @@ -228,7 +228,7 @@ static int opt4001_power_down(struct opt4001_chip *chip)
>>   	int ret;
>>   	unsigned int reg;
>>   
>> -	ret = regmap_read(chip->regmap, OPT4001_DEVICE_ID, &reg);
>> +	ret = regmap_read(chip->regmap, OPT4001_CTRL, &reg);
> Let us jump directly to a regmap_clear_bits()
>
> It will fix this issue and generally improve the code readabilty.
>
> Given this is only called in one place and the code will be nearly a one liner
> after that change, lets also just  move it directly into opt3001_chip_power_off_action().
>
> I my opinion all that is just about fine in a single fix patch, rather than a
> separate fix + code cleanup to follow, but if you would rather split it up into
> fix first then refactor I don't mind.  I may well decide to mere this whole series
> for the next merge window anyway just to ensure it all makes it reasonably quickly
> (at expensive of the fixes making it in a little faster and possibly delaying any
> cleanup).
>
> Thanks,
>
> Jonathan
>
Agreed, that is much cleaner. I will move the regmap_clear_bits() call
directly into the devm action and drop opt4001_power_down() as a single
fix patch in v2, with the Fixes tag added.

Thanks,
Nikhil

  reply	other threads:[~2026-07-13  3:33 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-12 20:24 [PATCH 0/4] iio: light: opt4001: Fixes from code review Nikhil Gautam
2026-07-12 20:24 ` [PATCH v1 1/4] iio: light: opt4001: Fix read-modify-write of wrong register in power down Nikhil Gautam
2026-07-13  0:42   ` Jonathan Cameron
2026-07-13  3:33     ` Nikhil Gautam [this message]
2026-07-12 20:24 ` [PATCH v1 2/4] iio: light: opt4001: Fix incompatible pointer type passed to div_u64_rem() Nikhil Gautam
2026-07-13  0:43   ` Jonathan Cameron
2026-07-13  3:31     ` Nikhil Gautam
2026-07-12 20:24 ` [PATCH v1 3/4] iio: light: opt4001: Reject integration times with a non-zero seconds part Nikhil Gautam
2026-07-13  0:44   ` Jonathan Cameron
2026-07-12 20:24 ` [PATCH v1 4/4] iio: light: opt4001: Fix reversed GENMASK() arguments in fault count mask Nikhil Gautam
2026-07-13  0:45   ` Jonathan Cameron
2026-07-13 11:25   ` Andy Shevchenko

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=6d7e489d-5438-4a76-829f-45796f1a4117@gmail.com \
    --to=nikhilgtr@gmail.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=stefan.windfeldt-prytz@axis.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

Powered by JetHome