public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: Marcelo Machado Lage <marcelomlage@usp.br>,
	andy@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com,
	Vinicius Lira <vinilira@usp.br>,
	linux-iio@vger.kernel.org
Subject: Re: [PATCH v3 2/2] iio: adc: mcp3422: write bit operations with bitfield.h macros
Date: Tue, 21 Apr 2026 15:52:16 +0100	[thread overview]
Message-ID: <20260421155216.7709e87f@jic23-huawei> (raw)
In-Reply-To: <aeaLk7Cmhp7faQYn@ashevche-desk.local>

On Mon, 20 Apr 2026 23:24:51 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Mon, Apr 20, 2026 at 04:14:55PM -0300, Marcelo Machado Lage wrote:
> > Replace manual bit manipulations with FIELD_GET(), FIELD_PREP() and
> > FIELD_MODIFY() calls. The resulting code is more readable and
> > maintainable, and 6 macros previously defined in the header are not
> > needed anymore.  
> 
> ...
> 
> >  	/* meaningful default configuration */
> >  	config = (MCP3422_CONT_SAMPLING
> > -		| MCP3422_CHANNEL_VALUE(0)
> > -		| MCP3422_PGA_VALUE(MCP3422_PGA_1)
> > -		| MCP3422_SAMPLE_RATE_VALUE(MCP3422_SRATE_240));
> > +		| FIELD_PREP(MCP3422_CHANNEL_MASK, 0)
> > +		| FIELD_PREP(MCP3422_PGA_MASK, MCP3422_PGA_1)
> > +		| FIELD_PREP(MCP3422_SRATE_MASK, MCP3422_SRATE_240));  
> 
> While at it, please fix the style by making the operator to be the last on
> the respective lines.
> 
> 	config = MCP3422_CONT_SAMPLING |
> 		 FIELD_PREP(MCP3422_CHANNEL_MASK, 0) |
> 		 FIELD_PREP(MCP3422_PGA_MASK, MCP3422_PGA_1) |
> 		 FIELD_PREP(MCP3422_SRATE_MASK, MCP3422_SRATE_240));
> 
> But, to me sounds better if you just resplit it it to
> 
> 	config = MCP3422_CONT_SAMPLING;
> 	FIELD_MODIFY(...);
> 	FIELD_MODIFY(...);
> 	FIELD_MODIFY(...);
> 
To me FIELD_MODIFY() kind of hints it might already be set but in this
case the whole value is being written.  So maybe just reorganize
as per Andy's first suggestion above.

      reply	other threads:[~2026-04-21 14:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-20 19:14 [PATCH v3 0/2] iio: adc: mcp3422: apply bit manipulation macros Marcelo Machado Lage
2026-04-20 19:14 ` [PATCH v3 1/2] iio: adc: mcp3422: rewrite mask macros using bits.h macros Marcelo Machado Lage
2026-04-21 15:54   ` Jonathan Cameron
2026-04-20 19:14 ` [PATCH v3 2/2] iio: adc: mcp3422: write bit operations with bitfield.h macros Marcelo Machado Lage
2026-04-20 20:24   ` Andy Shevchenko
2026-04-21 14:52     ` Jonathan Cameron [this message]

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=20260421155216.7709e87f@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=marcelomlage@usp.br \
    --cc=nuno.sa@analog.com \
    --cc=vinilira@usp.br \
    /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