From: Tomasz Duszynski <tomasz.duszynski@octakon.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Tomasz Duszynski <tomasz.duszynski@octakon.com>,
<linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<devicetree@vger.kernel.org>, <robh+dt@kernel.org>,
<andy.shevchenko@gmail.com>, <pmeerw@pmeerw.net>
Subject: Re: [PATCH v5 1/4] iio: chemical: scd30: add core driver
Date: Sun, 21 Jun 2020 17:40:37 +0200 [thread overview]
Message-ID: <20200621154037.GA13809@arch> (raw)
In-Reply-To: <20200620172502.0d532081@archlinux>
On Sat, Jun 20, 2020 at 05:25:02PM +0100, Jonathan Cameron wrote:
> On Sun, 7 Jun 2020 19:58:09 +0200
> Tomasz Duszynski <tomasz.duszynski@octakon.com> wrote:
>
> > Add Sensirion SCD30 carbon dioxide core driver.
> >
> > Signed-off-by: Tomasz Duszynski <tomasz.duszynski@octakon.com>
>
> A few things I'd missed showed up in warnings when I applied this and
> ran a sparse check. Please fix up and send a v6.
> Also sanity check the rest with sparse. Note if I'd missed this 0-day
> would have sent use these warnings.
>
Ah, forgot to add C=2 to prior building. Thanks for catching this.
> Thanks,
>
> Jonathan
>
> > +
> > +static int scd30_read_meas(struct scd30_state *state)
> > +{
> > + int i, ret;
> > +
> > + ret = state->command(state, CMD_READ_MEAS, 0, state->meas, sizeof(state->meas));
> > + if (ret)
> > + return ret;
> > +
> > + be32_to_cpu_array(state->meas, state->meas, ARRAY_SIZE(state->meas));
>
> The type of the input to the above has the wrong endian markings.
>
> CHECK drivers/iio/chemical/scd30_core.c
> drivers/iio/chemical/scd30_core.c:123:40: warning: incorrect type in argument 2 (different base types)
> drivers/iio/chemical/scd30_core.c:123:40: expected restricted __be32 const [usertype] *src
> drivers/iio/chemical/scd30_core.c:123:40: got int *
>
> Whilst you could use a cast, it would be tidier to use an array of __be32.
>
Here's the only place where it's a __be32. All other places assume
cpu endianess which means changing array type generates a few other warnings
here and there. So I'd prefer to be lazy here and use a cast :).
> > +
> > + for (i = 0; i < ARRAY_SIZE(state->meas); i++)
> > + state->meas[i] = scd30_float_to_fp(state->meas[i]);
> > +
> > + /*
> > + * co2 is left unprocessed while temperature and humidity are scaled
> > + * to milli deg C and milli percent respectively.
> > + */
> > + state->meas[SCD30_TEMP] *= 10;
> > + state->meas[SCD30_HR] *= 10;
> > +
> > + return 0;
> > +}
> > +
>
> ...
>
> > +
> > +static irqreturn_t scd30_trigger_handler(int irq, void *p)
> > +{
> > + struct iio_poll_func *pf = p;
> > + struct iio_dev *indio_dev = pf->indio_dev;
> > + struct scd30_state *state = iio_priv(indio_dev);
> > + struct {
> > + int data[SCD30_MEAS_COUNT];
> > + s64 ts __aligned(8);
> > + } scan = { 0, };
> should be scan = { {0, }, }; or something like that
> as first element happens to be an array.
>
> Actually there is padding in here you need to zero I think.
> So memset is a better bet.
>
Sure.
> > + int ret;
> > +
> > + mutex_lock(&state->lock);
> > + if (!iio_trigger_using_own(indio_dev))
> > + ret = scd30_read_poll(state);
> > + else
> > + ret = scd30_read_meas(state);
> > + memcpy(scan.data, state->meas, sizeof(state->meas));
> > + mutex_unlock(&state->lock);
> > + if (ret)
> > + goto out;
> > +
> > + iio_push_to_buffers_with_timestamp(indio_dev, &scan, iio_get_time_ns(indio_dev));
> > +out:
> > + iio_trigger_notify_done(indio_dev->trig);
> > + return IRQ_HANDLED;
> > +}
> > +
> ...
prev parent reply other threads:[~2020-06-21 15:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-07 17:58 [PATCH v5 1/4] iio: chemical: scd30: add core driver Tomasz Duszynski
2020-06-08 20:18 ` kernel test robot
2020-06-14 13:15 ` Jonathan Cameron
2020-06-20 16:25 ` Jonathan Cameron
2020-06-21 15:40 ` Tomasz Duszynski [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=20200621154037.GA13809@arch \
--to=tomasz.duszynski@octakon.com \
--cc=andy.shevchenko@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pmeerw@pmeerw.net \
--cc=robh+dt@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;
as well as URLs for NNTP newsgroup(s).