Re: [PATCH v3 2/2] iio: light: Add Capella CM3217 ambient light sensor driver
From: Jonathan Cameron
Date: Mon Nov 16 2026 - 22:11:20 EST
On Mon, 16 Nov 2026 11:23:28 +0200
Andy Shevchenko <andriy.shevchenko@xxxxxxxxx> wrote:
> 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.
I agree though in this particular case a property presence check doesn't
solve the same gap. The intent was to pick up on the driver having been
force loaded without firmware. Normally we'd just fail that given it
looks like it needs firmware. In practice it doesn't as the address this
give is always one greater than the device address.
Thinking more on that, just don't read it from firmware at all. It's
fine that the binding wants to describe it, but we don't have to ask
the firmware when we know the answer.
Jonathan
>
> > > + if (!device_property_read_u32_array(dev, "reg", reg, ARRAY_SIZE(reg)))
> > > + addr_lsb = reg[1];
>