Re: [PATCH 1/3] iio: chemical: sgp40: Implement get_serial_number-command
From: Andy Shevchenko
Date: Sat Sep 19 2026 - 10:10:10 EST
On Fri, Sep 18, 2026 at 04:40:17PM +0300, Jaakko Koivisto wrote:
> -Retrieve the chip serial number.
> -Present the serial number to userspace as device attribute.
> -Rename the tg_measure -struct now that is is used for multiple
> commands.
...
> + ret = i2c_master_send(client, (char*)&get_sn, sizeof(get_sn.command));
> + if (ret != sizeof(get_sn.command)) {
> + dev_err(data->dev, "i2c_master_send ret: %d, expected %zu", ret, sizeof(get_sn.command));
> + return -EIO;
> + }
> + msleep(1);
Explain this sleep.
> + ret = i2c_master_recv(client, (char*)&res, sizeof(res));
> + if (ret < 0)
> + return ret;
> + if (ret != sizeof(res)) {
> + dev_err(data->dev, "i2c_master_recv ret: %d, expected: %zu", ret, sizeof(res));
> + return -EIO;
> + }
> +
> + if (crc8(sgp40_crc8_table, (u8*)&res.A, 2, SGP40_CRC8_INIT) != res.A_crc ||
> + crc8(sgp40_crc8_table, (u8*)&res.B, 2, SGP40_CRC8_INIT) != res.B_crc ||
> + crc8(sgp40_crc8_table, (u8*)&res.C, 2, SGP40_CRC8_INIT) != res.C_crc)
> + {
> + dev_warn(data->dev, "CRC error in get_serial_number");
> + }
> +
> + data->serial_number = 0LL | ((u64)be16_to_cpu(res.A) << 32) | ((u64)be16_to_cpu(res.B) << 16) | (u64)be16_to_cpu(res.C);
0LL ?!
> + dev_dbg(data->dev, "serial number: %llu", data->serial_number);
Why?!
...
> - struct sgp40_tg_measure tg = {.command = {0x26, 0x0F}};
> + struct sgp40_command tg = {.command = {0x26, 0x0F}};
While at it, add more spaces.
...
> +}
> +
Unneeded blank line.
> +static IIO_DEVICE_ATTR_RO(serial_number, 0);
> +
> +static struct attribute *sgp40_attributes[] = {
> + &iio_dev_attr_serial_number.dev_attr.attr,
> + NULL
> +};
> +
> +static struct attribute_group sgp40_attribute_group = {
> + .attrs = sgp40_attributes,
> +};
> +
> +
Single blank line is enough and we have ATTRIBUTE_GROUPS().
--
With Best Regards,
Andy Shevchenko