Re: [PATCH v3 2/2] iio: light: Add Capella CM3217 ambient light sensor driver
From: Andy Shevchenko
Date: Mon Nov 16 2026 - 04:23:38 EST
On Sat, Nov 14, 2026 at 01:29:06AM +0000, Jonathan Cameron wrote:
> On Fri, 13 Nov 2026 20:59:00 +0100
> Patrick Fischer via B4 Relay <devnull+admin.tsv-stahl-riesa.de@xxxxxxxxxx> wrote:
...
> > +static int cm3217_probe(struct i2c_client *client)
> > +{
> > + struct device *dev = &client->dev;
> > + struct cm3217_data *data;
> > + struct iio_dev *indio_dev;
> > + u16 addr_lsb = CM3217_ADDR_CMD2_LSB;
> > + u32 reg[2];
> > + u8 cmd1, cmd2;
Keep reversed xmas tree order.
> > + int ret;
> > +
> > + indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
> > + if (!indio_dev)
> > + return -ENOMEM;
> > +
> > + data = iio_priv(indio_dev);
> > + data->client = client;
> > + i2c_set_clientdata(client, indio_dev);
> > +
> > + ret = devm_mutex_init(dev, &data->lock);
> > + if (ret)
> > + return ret;
> > +
> > + ret = devm_regulator_get_enable(dev, "vdd");
> > + if (ret)
> > + return dev_err_probe(dev, ret, "failed to enable vdd supply\n");
> > +
> > + /* Without a firmware node (e.g. sysfs new_device) use the fixed one */
>
> I'd rather we handled that explicitly.
>
> if (dev_fwmode(dev))
>
> That way we can return an error if there is firmware but it's broken.
I think here we want
if (device_property_present()) {
...
} else {
addr_lsb = CM3217_ADDR_CMD2_LSB;
}
I really discourage people to check for FW node presence with dev_fwnode(dev).
This is a corner case which is in most cases needs better granularity (like
distinguishing the fwnode by type). But in general ideally it has not to be
used at all.
> > + if (!device_property_read_u32_array(dev, "reg", reg, ARRAY_SIZE(reg)))
> > + addr_lsb = reg[1];
--
With Best Regards,
Andy Shevchenko