Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
To: gyeyoung <gye976@gmail.com>
Cc: Jonathan Cameron <jic23@kernel.org>, <linux-iio@vger.kernel.org>,
	<devicetree@vger.kernel.org>, <lars@metafoo.de>,
	<gustavograzs@gmail.com>, <javier.carrasco.cruz@gmail.com>,
	<robh@kernel.org>, <krzk+dt@kernel.org>, <conor+dt@kernel.org>
Subject: Re: [PATCH 1/3] iio: chemical: add support for winsen MHZ19B CO2 sensor
Date: Fri, 4 Apr 2025 12:39:00 +0100	[thread overview]
Message-ID: <20250404123900.00003147@huawei.com> (raw)
In-Reply-To: <CAKbEznv9hRhto2tF5zwrGJ=7zfT=VKq2POdWKCRgY1UjgP6pUg@mail.gmail.com>

On Mon, 31 Mar 2025 23:36:17 +0900
gyeyoung <gye976@gmail.com> wrote:

> Hello Jonathan, thank you for the review.
> Sorry for the late response.
> 
> > > +
> > > +             /* at least 1000ppm */
> > > +             if (ppm < 1000 || ppm > 5000) {
> > > +                     dev_dbg(&indio_dev->dev, "span point ppm should be 1000~5000");
> > > +                     return -EINVAL;
> > > +             }
> > > +
> > > +             cmd_buf[3] = ppm / 256;
> > > +             cmd_buf[4] = ppm % 256;  
> >
> > That's an elaborate way of doing
> >                 unaligned_put_be16()
> > so use that instead as it's also clearly documenting what is going on.  
> 
> Since I couldn't find a function like 'unaligned_put_be16',
> but I found a function like 'be16_to_cpu', so I will use that.

You can't. An array of u8 is not guaranteed to be aligned so in
some cases be16_to_cpu() will fail.

I was half asleep :(
put_unaligned_be16() is what you are looking for.
https://elixir.bootlin.com/linux/v6.13.7/source/include/linux/unaligned.h#L61


> > > +static void mhz19b_write_wakeup(struct serdev_device *serdev)
> > > +{
> > > +     struct iio_dev *indio_dev;
> > > +
> > > +     indio_dev = dev_get_drvdata(&serdev->dev);
> > > +
> > > +     dev_dbg(&indio_dev->dev, "mhz19b_write_wakeup");  
> >
> > This doesn't do anything which makes me suspicious. Would
> > using serdev_device_write_wakeup() as the callback make
> > sense?  I'm not that familiar with serial drivers but I can
> > see that a number of other drivers do that.
> >  
> 
> 'serdev_device_write_wakeup' member function is mandatory.
> If this function is not set and remains NULL, the
> 'serdev_device_write' function will just return -EINVAL.
> 
> The following is a part of serdev_device_write().
> ------------
> ssize_t serdev_device_write(struct serdev_device *serdev, const u8 *buf,
>    size_t count, long timeout)
> {
> struct serdev_controller *ctrl = serdev->ctrl;
> size_t written = 0;
> ssize_t ret;
> 
> if (!ctrl || !ctrl->ops->write_buf || !serdev->ops->write_wakeup)
> return -EINVAL;
> .
> .
> .
> ------------

Ok. So why not serdev_device_write_wakeup()?

> 
> > > +}
> > > +
> > > +static const struct serdev_device_ops mhz19b_ops = {
> > > +     .receive_buf = mhz19b_receive_buf,
> > > +     .write_wakeup = mhz19b_write_wakeup,
> > > +};  
>
> > > +static int mhz19b_probe(struct serdev_device *serdev)
> > > +{
> > > +     int ret;
> > > +
> > > +     struct device *dev;
> > > +
> > > +     dev = &serdev->dev;
> > > +     serdev_device_set_client_ops(serdev, &mhz19b_ops);
> > > +
> > > +     ret = devm_serdev_device_open(dev, serdev);
> > > +     if (ret)
> > > +             return ret;
> > > +
> > > +     serdev_device_set_baudrate(serdev, 9600);
> > > +     serdev_device_set_flow_control(serdev, false);
> > > +     ret = serdev_device_set_parity(serdev, SERDEV_PARITY_NONE);
> > > +     if (ret < 0)
> > > +             return ret;  
> >
> > Why check return value from this call but not the previous two?
> > I'm not immediately able to see a reason this is more likely to fail.  
> 
> 'serdev_device_set_flow_control' is a void function.
> and as far as I know, 'serdev_device_set_baudrate' does not return an error.
> but I'll check again.

Ah I missed that. No problem not checking it.

Jonathan

> 
> I'll revise it considering your overall coding style guide.
> 
> Thanks,
> Gyeyoung Baek
> 
> 


  reply	other threads:[~2025-04-04 11:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-29 16:49 [PATCH 0/3] add support for winsen MHZ19B CO2 sensor Gyeyoung Baek
2025-03-29 16:49 ` [PATCH 1/3] iio: chemical: " Gyeyoung Baek
2025-03-30 14:04   ` Jonathan Cameron
2025-03-31 14:36     ` gyeyoung
2025-04-04 11:39       ` Jonathan Cameron [this message]
2025-03-29 16:49 ` [PATCH 2/3] dt-bindings: add device tree " Gyeyoung Baek
2025-03-30  9:39   ` Krzysztof Kozlowski
2025-03-31  1:11     ` gyeyoung
2025-03-30 12:50   ` Jonathan Cameron
2025-03-31  1:32     ` gyeyoung
2025-03-29 16:49 ` [PATCH 3/3] dt-bindings: add winsen to the vendor prefixes Gyeyoung Baek
2025-03-30  9:37   ` Krzysztof Kozlowski
2025-03-31  0:13     ` gyeyoung

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=20250404123900.00003147@huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=gustavograzs@gmail.com \
    --cc=gye976@gmail.com \
    --cc=javier.carrasco.cruz@gmail.com \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=robh@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