lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CADFWO8E_yHdbnC7BtOXODYnKgmP9t-4sXANsveYOxw89N8V3Fw@mail.gmail.com>
Date: Thu, 4 Jul 2024 10:09:26 +0200
From: Petar Stoykov <pd.pstoykov@...il.com>
To: Jonathan Cameron <jic23@...nel.org>
Cc: Petar Stoykov via B4 Relay <devnull+pd.pstoykov.gmail.com@...nel.org>, linux-iio@...r.kernel.org, 
	Lars-Peter Clausen <lars@...afoo.de>, Rob Herring <robh+dt@...nel.org>, 
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>, Conor Dooley <conor+dt@...nel.org>, 
	Andy Shevchenko <andriy.shevchenko@...ux.intel.com>, devicetree@...r.kernel.org, 
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3 2/3] iio: pressure: Add driver for Sensirion SDP500

On Tue, Jul 2, 2024 at 10:16 PM Jonathan Cameron <jic23@...nel.org> wrote:
>
> On Tue, 02 Jul 2024 16:59:09 +0200
> Petar Stoykov via B4 Relay <devnull+pd.pstoykov.gmail.com@...nel.org> wrote:
>
> > From: Petar Stoykov <pd.pstoykov@...il.com>
> >
> > Sensirion SDP500 is a digital differential pressure sensor. The sensor is
> > accessed over I2C.
> >
> > Signed-off-by: Petar Stoykov <pd.pstoykov@...il.com>
> Hi Petar
>
> Given you are going to be doing a v4, a few comments inline on things
> to tidy up in here.
>
> Note that I've already tagged what may be the last pull request from me
> for the 6.11 merge window, so this is probably 6.12 material now anyway.
> Hence plenty of time to tidy up.
>
> Jonathan
>

Hi Jonathan,
I have no rush, thank you for the explanation!

> > diff --git a/drivers/iio/pressure/sdp500.c b/drivers/iio/pressure/sdp500.c
> > new file mode 100644
> > index 000000000000..661c70bc1b5b
> > --- /dev/null
> > +++ b/drivers/iio/pressure/sdp500.c
> > @@ -0,0 +1,153 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +/*
> > + * Driver for Sensirion sdp500 and sdp510 pressure sensors
> > + *
> > + * Datasheet: https://sensirion.com/resource/datasheet/sdp600
> > + */
> > +
> > +#include <linux/i2c.h>
> > +#include <linux/crc8.h>
> > +#include <linux/iio/iio.h>
>
> #include <linux/mod_devicetable.h> appropriate for the id tables.

I don't understand. Why add an extra header to a working driver?
I will add it and test the driver in the meantime.

>
> > +#include <linux/regulator/consumer.h>
> > +#include <asm/unaligned.h>
> > +
> > +#define SDP500_CRC8_POLYNOMIAL  0x31   // x8 + x5 + x4 + 1 (normalized to 0x31)
>
> For IIO we tend to just use c style comments /* xxx */
> and not c++ ones.

I try to follow this rule but once in a while I slip to my old habits.
My teachers all used // for C for whatever reason. Will fix.

>
> > +#define SDP500_READ_SIZE        3
>
> > +static int sdp500_read_raw(struct iio_dev *indio_dev,
> > +                       struct iio_chan_spec const *chan,
> > +                       int *val, int *val2, long mask)
> > +{
> > +     int ret;
> > +     u8 rxbuf[SDP500_READ_SIZE];
> > +     u8 received_crc, calculated_crc;
> > +     struct sdp500_data *data = iio_priv(indio_dev);
> > +     struct i2c_client *client = to_i2c_client(data->dev);
> > +
> > +     switch (mask) {
> > +     case IIO_CHAN_INFO_RAW:
> > +             ret = i2c_master_recv(client, rxbuf, SDP500_READ_SIZE);
> > +             if (ret < 0) {
> > +                     dev_err(data->dev, "Failed to receive data");
> > +                     return ret;
> > +             }
> > +             if (ret != SDP500_READ_SIZE) {
> > +                     dev_err(data->dev, "Data is received wrongly");
> > +                     return -EIO;
> > +             }
> > +
> > +             received_crc = rxbuf[2];
> > +             calculated_crc = crc8(sdp500_crc8_table, rxbuf, sizeof(rxbuf) - 1, 0x00);
> A line break in here to keep it under 80 chars would be good (see below).

I find the 80 chars too constraining and also saw that the limit was updated
to 100 somewhere in kernel.org which made me happy. But.. you seem to
feel strongly enough about this so I'll trim lines to 80.

>
> > +             if (received_crc != calculated_crc) {
> > +                     dev_err(data->dev, "calculated crc = 0x%.2X, received 0x%.2X",
> > +                             calculated_crc, received_crc);
> > +                     return -EIO;
> > +             }
> > +
> > +             *val = get_unaligned_be16(rxbuf);
> > +             return IIO_VAL_INT;
> > +     case IIO_CHAN_INFO_SCALE:
> > +             *val = 1;
> > +             *val2 = 60;
> > +
> > +             return IIO_VAL_FRACTIONAL;
> > +     default:
> > +             return -EINVAL;
> > +     }
> > +}
> > +
> > +static const struct iio_info sdp500_info = {
> > +     .read_raw = &sdp500_read_raw,
> > +};
> > +
> > +static int sdp500_probe(struct i2c_client *client)
> > +{
> > +     struct iio_dev *indio_dev;
> > +     struct sdp500_data *data;
> > +     struct device *dev = &client->dev;
> > +     int ret;
> > +     u8 rxbuf[SDP500_READ_SIZE];
> > +
> > +     ret = devm_regulator_get_enable(dev, "vdd");
> > +     if (ret)
> > +             return dev_err_probe(dev, ret, "Failed to get and enable regulator\n");
> Given you are going around again.  Add a line break before "
> General rule is stay under 80 chars unless it hurts readability.
>
> > +

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ