All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Tomas Melin <tomas.melin@vaisala.com>
Cc: LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn>,
	lars@metafoo.de, robh+dt@kernel.org, andy.shevchenko@gmail.com,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-iio@vger.kernel.org
Subject: Re: [PATCH V6 3/5] iio: accel: sca3300: modified to support multi chips
Date: Sun, 22 May 2022 11:44:33 +0100	[thread overview]
Message-ID: <20220522114433.6d3257e1@jic23-huawei> (raw)
In-Reply-To: <cd5864b3-c436-4a22-663b-703377bf8521@vaisala.com>

> >> +static int sca3300_set_frequency(struct sca3300_data *data, int val)
> >> +{
> >> +	const struct sca3300_chip_info *chip = data->chip;
> >> +	unsigned int index;
> >> +	unsigned int i;
> >> +
> >> +	if (sca3300_get_op_mode(data, &index))
> >> +		return -EINVAL;
> >> +
> >> +	for (i = 0; i < chip->num_avail_modes; i++) {
> >> +		if ((val == chip->freq_table[chip->freq_map[i]]) &&  
> > 
> > The conditions being checked here are far from obvious, so I think this would benefit
> > from an explanatory comment.
> > 
> > Something along the lines of,
> > "Find a mode in which the requested sampling frequency is available
> >  and the scaling currently set is retained".  
> 
> 
> In addition to a comment, how about small restructure of loop and giving
> local variables that tell the purpose, something like
> 
> 
> ...
> 
> unsigned int opmode_scale, new_scale;
> 
> opmode_scale = chip->accel_scale[chip->accel_scale_map[index]];
> 
> /*
> * Find a mode in which the requested sampling frequency is available
> * and the scaling currently set is retained
> */
> for (i = 0; i < chip->num_avail_modes; i++) {
>     if (val == chip->freq_table[chip->freq_map[i]]) {
>         new_scale = chip->accel_scale[chip->accel_scale_map[i]]);	
>         if (opmode_scale == new_scale)
>             break;
>     }
> }
> 
> 
> That way it's IMHO more clear what we are comparing.
LGTM.

Thanks,

Jonathan

> 
> Thanks,
> Tomas

  reply	other threads:[~2022-05-22 10:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-13 12:41 [PATCH V6 0/5] iio: accel: sca3300: add compatible for scl3300 LI Qingwu
2022-05-13 12:41 ` [PATCH V6 1/5] dt-bindings: iio: accel: sca3300: Document murata,scl3300 LI Qingwu
2022-05-13 12:41 ` [PATCH V6 2/5] iio: accel: sca3300: add define for temp channel for reuse LI Qingwu
2022-05-13 12:41 ` [PATCH V6 3/5] iio: accel: sca3300: modified to support multi chips LI Qingwu
2022-05-14 14:10   ` Jonathan Cameron
2022-05-16  6:07     ` Tomas Melin
2022-05-22 10:44       ` Jonathan Cameron [this message]
2022-05-13 12:41 ` [PATCH V6 4/5] iio: accel: sca3300: Add support for SCL3300 LI Qingwu
2022-05-13 12:41 ` [PATCH V6 5/5] iio: accel: sca3300: Add inclination channels LI Qingwu
2022-05-16  7:50   ` Tomas Melin

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=20220522114433.6d3257e1@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Qing-wu.Li@leica-geosystems.com.cn \
    --cc=andy.shevchenko@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=tomas.melin@vaisala.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.