[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20231204100517.30df720e@jic23-huawei>
Date: Mon, 4 Dec 2023 10:05:17 +0000
From: Jonathan Cameron <jic23@...nel.org>
To: Anshul Dalal <anshulusr@...il.com>
Cc: linux-kernel@...r.kernel.org, linux-iio@...r.kernel.org,
devicetree@...r.kernel.org, Conor Dooley <conor+dt@...nel.org>,
Lars-Peter Clausen <lars@...afoo.de>,
Rob Herring <robh+dt@...nel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
linux-kernel-mentees@...ts.linuxfoundation.org,
Shuah Khan <skhan@...uxfoundation.org>
Subject: Re: [PATCH v2 2/2] iio: light: driver for Lite-On ltr390
> >> +struct ltr390_data {
> >> + struct regmap *regmap;
> >> + struct i2c_client *client;
> >> + struct mutex lock;
> >
> > All locks need a comment explaining the scope of data they protect.
> > Note that regmap and the i2c bus will have their own locks by default
> > so I'm not sure you need one here at all as I'm not seeing read modify write
> > cycles or anything like that (I might be missing one though!)
>
> My goal with the mutex was to protect the sysfs though that might be
> unnecessary.
Ok. So, there is nothing stopping multiple parallel sysfs accesses, but
what you'll actually be protecting is either device or driver state, not
sysfs as such.
>
> >> +};
> >> +
> >> +static const struct regmap_config ltr390_regmap_config = {
> >> + .name = LTR390_DEVICE_NAME,
> >> + .reg_bits = 8,
> >> + .reg_stride = 1,
> >> + .val_bits = 8,
> >> +};
> >> +
> >> +static int ltr390_probe(struct i2c_client *client)
> >> +{
> >> + struct ltr390_data *data;
> >> + struct iio_dev *indio_dev;
> >> + int ret, part_number;
> >> +
> >> + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
> >> + if (!indio_dev)
> >> + return -ENOMEM;
> >> +
> >> + data = iio_priv(indio_dev);
> >> +
> >> + data->regmap = devm_regmap_init_i2c(client, <r390_regmap_config);
> >> + if (IS_ERR(data->regmap))
> >> + return dev_err_probe(&client->dev, PTR_ERR(data->regmap),
> > There are quite a few &client->dev in here. I'd introduce
> > struct device *dev = &client->dev;
> > as a local variable then use that to shorten all those lines a little.
> >
> >> + "regmap initialization failed\n");
> >> +
> >> + data->client = client;
> >> + i2c_set_clientdata(client, indio_dev);
> >
> > Why set this? I don' think you are using it.
> >
>
> It seems to be necessary for regmap to work properly, I tested without
> it and I get an EREMOTEIO(121) when reading the part id.
That's weird given regmap will have no understanding of an iio_dev.
If you can do some more debugging on where that error is coming from
in regmap that would be great.
I suspect it's coming from down in the bus master which should not
be touching this at all. What is the i2c master in this case?
Jonathan
>
> >> [..]
>
> Thanks for the review,
> Best regards,
> Anshul
Powered by blists - more mailing lists