Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: Gustavo Pagnotta Faria <gustavo.pagnotta@ime.usp.br>,
	andy@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com,
	Eduardo Augusto <eduardoaugustoabc@ime.usp.br>,
	Christian Barry <christian.barry@ime.usp.br>,
	linux-iio@vger.kernel.org
Subject: Re: [PATCH v4 2/2] iio: adc: mcp320x: refactor driver to use bitfield API
Date: Fri, 24 Apr 2026 12:45:10 +0100	[thread overview]
Message-ID: <20260424124510.5e4f3cee@jic23-huawei> (raw)
In-Reply-To: <aeskXSpBCIvWghPu@ashevche-desk.local>

On Fri, 24 Apr 2026 11:05:49 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Wed, Apr 22, 2026 at 07:14:13PM -0300, Gustavo Pagnotta Faria wrote:
> > Update the mcp320x driver to use the standard Linux
> > bitfield API (<linux/bitfield.h>) instead of manual
> > bitwise shifts and masks.  
> 
> > This replaces the hardcoded shift operations in the TX
> > data preparation (mcp320x_channel_to_tx_data) with FIELD_PREP()
> > and replaces the manual masking in the RX data extraction
> > (mcp320x_adc_conversion) with FIELD_GET(). Explicit masks using
> > GENMASK() and BIT() were also introduced for both transmit
> > configurations and receive extractions.  
> 
> I believe somebody told to you (or to the similar patch *) that this paragraph
> is an unneeded detail.
> 
> *) I'm already too much lost in the flood of the patches to IIO this spring...
> I dunno what's going on, but from last few days when seeing something that does
> ring a bell, I suggest contributors to start actually reviewing others' patches
> in the mailing list for this (IIO) subsystem and read other reviews to learn
> from them. It will save a lot of time for everybody.

Lol. I just replied to patch 1 with the same message. I should have read on.

> 
> ...
> 
> > +	case mcp3301: {
> > +		u16 rx_val = get_unaligned_be16(adc->rx_buf);  
> 
> This is used in all cases (or almost all), can you make this assignment and
> conversion be done outside switch-case?

I asked for it to be moved in as it is invalid in a couple of cases and
I don't like having variables taking nonsensical values even if they
are then not used.

> 
> > +		u16 raw = FIELD_GET(MCP3301_DATA_MASK, rx_val);
> > +
> > +		*val = sign_extend32(raw, 12);

Can make it less painful though by doing the FIELD_GET inline or maybe
even using the proposed FIELD_GET_SIGNED().

https://lore.kernel.org/all/20260417173621.368914-1-ynorov@nvidia.com/

I guess we can't assume that will land that soon (though please keep
an eye out for it doing so) hence in meantime.

		*val = sign_extend32(FIELD_GET(MCGP3301_DATA_MASK, rx_val), 12);

Thanks,

Jonathan


		
> >  		return 0;
> > +		}  
> 


      reply	other threads:[~2026-04-24 11:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-22 22:14 [PATCH v4 0/2] iio: adc: mcp320x: bitfield refactoring Gustavo Pagnotta Faria
2026-04-22 22:14 ` [PATCH v4 1/2] iio: adc: mcp320x: sort headers alphabetically Gustavo Pagnotta Faria
2026-04-23 17:46   ` Andy Shevchenko
2026-04-23 20:45     ` Gustavo Pagnotta Faria
2026-04-24  8:01       ` Andy Shevchenko
2026-04-24 11:37         ` Jonathan Cameron
2026-04-22 22:14 ` [PATCH v4 2/2] iio: adc: mcp320x: refactor driver to use bitfield API Gustavo Pagnotta Faria
2026-04-24  8:05   ` Andy Shevchenko
2026-04-24 11:45     ` 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=20260424124510.5e4f3cee@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=christian.barry@ime.usp.br \
    --cc=dlechner@baylibre.com \
    --cc=eduardoaugustoabc@ime.usp.br \
    --cc=gustavo.pagnotta@ime.usp.br \
    --cc=linux-iio@vger.kernel.org \
    --cc=nuno.sa@analog.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