[PATCH v3 6/6] iio: light: vcnl4000: use variables for I2C client and device instances

Erikas Bitovtas posted 6 patches 3 weeks, 2 days ago
There is a newer version of this series
[PATCH v3 6/6] iio: light: vcnl4000: use variables for I2C client and device instances
Posted by Erikas Bitovtas 3 weeks, 2 days ago
After moving data->client and client->dev into variables of their own,
replace all instances of data->client and client->dev being used in
vcnl4200_init and vcnl4000_probe by the said variables to reduce
clutter.

Signed-off-by: Erikas Bitovtas <xerikasxx@gmail.com>
---
 drivers/iio/light/vcnl4000.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
index c8bb1826b916..9b7cd3f0c8fb 100644
--- a/drivers/iio/light/vcnl4000.c
+++ b/drivers/iio/light/vcnl4000.c
@@ -362,14 +362,14 @@ static int vcnl4200_init(struct vcnl4000_data *data)
 	int ret, id;
 	u16 regval;
 
-	ret = i2c_smbus_read_word_data(data->client, VCNL4200_DEV_ID);
+	ret = i2c_smbus_read_word_data(client, VCNL4200_DEV_ID);
 	if (ret < 0)
 		return ret;
 
 	id = ret & 0xff;
 
 	if (id != VCNL4200_PROD_ID) {
-		ret = i2c_smbus_read_word_data(data->client, VCNL4040_DEV_ID);
+		ret = i2c_smbus_read_word_data(client, VCNL4040_DEV_ID);
 		if (ret < 0)
 			return ret;
 
@@ -379,7 +379,7 @@ static int vcnl4200_init(struct vcnl4000_data *data)
 			return -ENODEV;
 	}
 
-	dev_dbg(&data->client->dev, "device id 0x%x", id);
+	dev_dbg(dev, "device id 0x%x", id);
 
 	data->rev = (ret >> 8) & 0xf;
 	data->ps_int = 0;
@@ -413,23 +413,23 @@ static int vcnl4200_init(struct vcnl4000_data *data)
 		return ret;
 
 	/* Use 16 bits proximity sensor readings */
-	ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1);
+	ret = i2c_smbus_read_word_data(client, VCNL4200_PS_CONF1);
 	if (ret < 0)
 		return ret;
 
 	regval = ret | VCNL4040_PS_CONF2_PS_HD;
-	ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1,
+	ret = i2c_smbus_write_word_data(client, VCNL4200_PS_CONF1,
 					regval);
 	if (ret < 0)
 		return ret;
 
 	/* Align proximity sensor sample rate to 16 bits data width */
-	ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF3);
+	ret = i2c_smbus_read_word_data(client, VCNL4200_PS_CONF3);
 	if (ret < 0)
 		return ret;
 
 	regval = ret | VCNL4040_CONF3_PS_SAMPLE_16BITS;
-	ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF3,
+	ret = i2c_smbus_write_word_data(client, VCNL4200_PS_CONF3,
 					regval);
 	if (ret < 0)
 		return ret;
@@ -1998,7 +1998,7 @@ static int vcnl4000_probe(struct i2c_client *client)
 	struct device *dev = &client->dev;
 	int ret;
 
-	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
 	if (!indio_dev)
 		return -ENOMEM;
 
@@ -2022,10 +2022,10 @@ static int vcnl4000_probe(struct i2c_client *client)
 	if (ret < 0)
 		return ret;
 
-	dev_dbg(&client->dev, "%s Ambient light/proximity sensor, Rev: %02x\n",
+	dev_dbg(dev, "%s Ambient light/proximity sensor, Rev: %02x\n",
 		data->chip_spec->prod, data->rev);
 
-	if (device_property_read_u32(&client->dev, "proximity-near-level",
+	if (device_property_read_u32(dev, "proximity-near-level",
 				     &data->near_level))
 		data->near_level = 0;
 
@@ -2037,7 +2037,7 @@ static int vcnl4000_probe(struct i2c_client *client)
 
 	if (data->chip_spec->trig_buffer_func &&
 	    data->chip_spec->buffer_setup_ops) {
-		ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev,
+		ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
 						      NULL,
 						      data->chip_spec->trig_buffer_func,
 						      data->chip_spec->buffer_setup_ops);
@@ -2046,8 +2046,8 @@ static int vcnl4000_probe(struct i2c_client *client)
 	}
 
 	if (client->irq && data->chip_spec->irq_thread) {
-		ret = devm_request_threaded_irq(&client->dev, client->irq,
-						NULL, data->chip_spec->irq_thread,
+		ret = devm_request_threaded_irq(dev, client->irq, NULL,
+						data->chip_spec->irq_thread,
 						IRQF_TRIGGER_FALLING |
 						IRQF_ONESHOT,
 						"vcnl4000_irq",
@@ -2060,7 +2060,7 @@ static int vcnl4000_probe(struct i2c_client *client)
 			return ret;
 	}
 
-	ret = pm_runtime_set_active(&client->dev);
+	ret = pm_runtime_set_active(dev);
 	if (ret < 0)
 		goto fail_poweroff;
 
@@ -2068,9 +2068,9 @@ static int vcnl4000_probe(struct i2c_client *client)
 	if (ret < 0)
 		goto fail_poweroff;
 
-	pm_runtime_enable(&client->dev);
-	pm_runtime_set_autosuspend_delay(&client->dev, VCNL4000_SLEEP_DELAY_MS);
-	pm_runtime_use_autosuspend(&client->dev);
+	pm_runtime_enable(dev);
+	pm_runtime_set_autosuspend_delay(dev, VCNL4000_SLEEP_DELAY_MS);
+	pm_runtime_use_autosuspend(dev);
 
 	return 0;
 fail_poweroff:

-- 
2.53.0
Re: [PATCH v3 6/6] iio: light: vcnl4000: use variables for I2C client and device instances
Posted by Andy Shevchenko 3 weeks ago
On Sat, Mar 14, 2026 at 06:06:35PM +0200, Erikas Bitovtas wrote:
> After moving data->client and client->dev into variables of their own,
> replace all instances of data->client and client->dev being used in
> vcnl4200_init and vcnl4000_probe by the said variables to reduce
> clutter.

...

> -	ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1,
> +	ret = i2c_smbus_write_word_data(client, VCNL4200_PS_CONF1,
>  					regval);

Now it's perfectly a single line.

	ret = i2c_smbus_write_word_data(client, VCNL4200_PS_CONF1, regval);

>  	if (ret < 0)
>  		return ret;

...

>  	regval = ret | VCNL4040_CONF3_PS_SAMPLE_16BITS;
> -	ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF3,
> +	ret = i2c_smbus_write_word_data(client, VCNL4200_PS_CONF3,
>  					regval);

Ditto.

>  	if (ret < 0)
>  		return ret;

> -	if (device_property_read_u32(&client->dev, "proximity-near-level",
> +	if (device_property_read_u32(dev, "proximity-near-level",
>  				     &data->near_level))
>  		data->near_level = 0;

The 'if' is redundant, I think you can drop it at some point, probably to avoid
churn in the follow up

 -	if (device_property_read_u32(&client->dev, "proximity-near-level",
 -		data->near_level = 0;
 +	device_property_read_u32(dev, "proximity-near-level", &data->near_level);

Assuming data is allocated with kzalloc() or equivalent.

...

> -		ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev,
> +		ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
>  						      NULL,

Now NULL can be moved to upper line.

>  						      data->chip_spec->trig_buffer_func,
>  						      data->chip_spec->buffer_setup_ops);

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v3 6/6] iio: light: vcnl4000: use variables for I2C client and device instances
Posted by Erikas Bitovtas 3 weeks ago

On 3/16/26 12:39 PM, Andy Shevchenko wrote:
> On Sat, Mar 14, 2026 at 06:06:35PM +0200, Erikas Bitovtas wrote:
>> After moving data->client and client->dev into variables of their own,
>> replace all instances of data->client and client->dev being used in
>> vcnl4200_init and vcnl4000_probe by the said variables to reduce
>> clutter.
> 
> ...
> 
>> -	ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1,
>> +	ret = i2c_smbus_write_word_data(client, VCNL4200_PS_CONF1,
>>  					regval);
> 
> Now it's perfectly a single line.
> 
> 	ret = i2c_smbus_write_word_data(client, VCNL4200_PS_CONF1, regval);
> 
>>  	if (ret < 0)
>>  		return ret;
> 
> ...
> 
>>  	regval = ret | VCNL4040_CONF3_PS_SAMPLE_16BITS;
>> -	ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF3,
>> +	ret = i2c_smbus_write_word_data(client, VCNL4200_PS_CONF3,
>>  					regval);
> 
> Ditto.
> 
>>  	if (ret < 0)
>>  		return ret;
> 
>> -	if (device_property_read_u32(&client->dev, "proximity-near-level",
>> +	if (device_property_read_u32(dev, "proximity-near-level",
>>  				     &data->near_level))
>>  		data->near_level = 0;
> 
> The 'if' is redundant, I think you can drop it at some point, probably to avoid
> churn in the follow up
> 
>  -	if (device_property_read_u32(&client->dev, "proximity-near-level",
>  -		data->near_level = 0;
>  +	device_property_read_u32(dev, "proximity-near-level", &data->near_level);
> 

device_property_read_u32() throws an error if a property is missing.
Would data->near_level be left without an assigned default value in that
case?
Re: [PATCH v3 6/6] iio: light: vcnl4000: use variables for I2C client and device instances
Posted by Andy Shevchenko 3 weeks ago
On Mon, Mar 16, 2026 at 12:50:48PM +0200, Erikas Bitovtas wrote:
> On 3/16/26 12:39 PM, Andy Shevchenko wrote:

First of all, remove the content you are not replying to!

...

> >> -	if (device_property_read_u32(&client->dev, "proximity-near-level",
> >> +	if (device_property_read_u32(dev, "proximity-near-level",
> >>  				     &data->near_level))
> >>  		data->near_level = 0;
> > 
> > The 'if' is redundant, I think you can drop it at some point, probably to avoid
> > churn in the follow up
> > 
> >  -	if (device_property_read_u32(&client->dev, "proximity-near-level",
> >  -		data->near_level = 0;
> >  +	device_property_read_u32(dev, "proximity-near-level", &data->near_level);
> > 
> 
> device_property_read_u32() throws an error if a property is missing.
> Would data->near_level be left without an assigned default value in that
> case?

Second, have you read my reply carefully?

-- 
With Best Regards,
Andy Shevchenko