public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Angel Iglesias <ang.iglesiasg@gmail.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jonathan Cameron <jic23@kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>
Subject: Re: [PATCH 1/2] iio: pressure: bmp280: Allow multiple chips id per family of devices
Date: Fri, 18 Aug 2023 17:52:07 +0200	[thread overview]
Message-ID: <b209214a80c98f92db57be30883ec78dfc116ab0.camel@gmail.com> (raw)
In-Reply-To: <ZN9TyGjr/pqLQUpT@smile.fi.intel.com>

On Fri, 2023-08-18 at 14:19 +0300, Andy Shevchenko wrote:
> On Thu, Aug 17, 2023 at 11:05:21PM +0200, Angel Iglesias wrote:
> > Improve device detection in certain chip families known to have various
> > chip ids.
> 
> ...
> 
> > +       ret = -EINVAL;
> 
> Why do you need this...
> 
> > +       for (i = 0; i < data->chip_info->num_chip_id; i++) {
> > +               if (chip_id == data->chip_info->chip_id[i]) {
> 
> > +                       ret = 0;
> 
> ..and this...
> 
> > +                       break;
> > +               }
> > +       }
> 
> > +       if (ret) {
> 
> ...and this?
> 
> You can simply do
> 
>         for (i = 0; i < data->chip_info->num_chip_id; i++) {
>                 if (chip_id == data->chip_info->chip_id[i])
>                         break;
>         }
>         if (i < data->chip_info->num_chip_id) {
> 

Got it, much cleaner also.

> ...
> 
> > +               // 0x<id>, so four chars per number plus one space + ENDL
> > +               size_t nbuf = 5*data->chip_info->num_chip_id*sizeof(char);
> 
> Besides lack of spaces...
> 
> > +               char *buf = kmalloc(nbuf, GFP_KERNEL);
> 
> ...this at least should be kmalloc_array() and on top maybe something from
> overflow.h will be needed.

Sure, I'll give a look. I didn't want to do string manipulations on a kernel
driver but couldn't found a way to log the error meaningfully in one entry.

> > +               if (!buf)
> > +                       return ret;
> > +
> > +               for (i = 0; i < data->chip_info->num_chip_id; i++)
> > +                       snprintf(&buf[i*5], nbuf, "0x%x ", data->chip_info-
> > >chip_id[i]);
> > +               buf[nbuf-1] = '\0';
> > +
> > +               dev_err(dev, "bad chip id: expected [ %s ] got 0x%x\n", buf,
> > chip_id);
> > +               kfree(buf);
> > +               return ret;
> >         }
> 
> ...
> 
> > -       const unsigned int chip_id;
> 
> Yeah, this const makes a little sense...
> 
> > +       const unsigned int *chip_id;
> 
> ...but not this :-)

Isn't the same case as "const struct iio_chan_spec *channels" or "const int
*oversampling_temp_avail". I thoght that this meant a pointer to a constant
integer. On bmp280-core I declare the arrays with the modifiers static const.

> What I'm wondering is why it's int and not u8 / u16
> (as it seems only a byte value there).

Yeah, can be u8, as the reg width is 1 byte and this IDs are stored on one reg.
I just carried over the int type from previous versions, but it's just wasting
space :/

> 
> > +       int num_chip_id;
> 
> unsigned.
> 
Thanks for your time!

Kind regards,
Angel

  reply	other threads:[~2023-08-18 15:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-17 21:05 [PATCH 0/2] iio: pressure: bmp280: Add support for BMP390 Angel Iglesias
2023-08-17 21:05 ` [PATCH 1/2] iio: pressure: bmp280: Allow multiple chips id per family of devices Angel Iglesias
2023-08-18 11:19   ` Andy Shevchenko
2023-08-18 15:52     ` Angel Iglesias [this message]
2023-08-18 15:57       ` Andy Shevchenko
2023-08-18 16:41         ` Angel Iglesias
2023-08-28 14:28   ` Jonathan Cameron
2023-08-17 21:05 ` [PATCH 2/2] iio: pressure: bmp280: Add support for BMP390 Angel Iglesias
2023-08-18 11:21   ` 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=b209214a80c98f92db57be30883ec78dfc116ab0.camel@gmail.com \
    --to=ang.iglesiasg@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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