[PATCH v4 2/3] w1: ds2482: Add regulator support

Kryštof Černý via B4 Relay posted 3 patches 1 year, 2 months ago
There is a newer version of this series
[PATCH v4 2/3] w1: ds2482: Add regulator support
Posted by Kryštof Černý via B4 Relay 1 year, 2 months ago
From: Kryštof Černý <cleverline1mc@gmail.com>

Adds a support for attaching a supply regulator.

Signed-off-by: Kryštof Černý <cleverline1mc@gmail.com>
---
 drivers/w1/masters/ds2482.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/w1/masters/ds2482.c b/drivers/w1/masters/ds2482.c
index a2ecbb863c57f38bffc8e3cd463db1940e603179..2e5bbe11d8a0cdabd12e89e22537423749e7f9ff 100644
--- a/drivers/w1/masters/ds2482.c
+++ b/drivers/w1/masters/ds2482.c
@@ -15,6 +15,7 @@
 #include <linux/slab.h>
 #include <linux/i2c.h>
 #include <linux/delay.h>
+#include <linux/regulator/consumer.h>
 
 #include <linux/w1.h>
 
@@ -445,6 +446,7 @@ static int ds2482_probe(struct i2c_client *client)
 	int err = -ENODEV;
 	int temp1;
 	int idx;
+	int ret;
 
 	if (!i2c_check_functionality(client->adapter,
 				     I2C_FUNC_SMBUS_WRITE_BYTE_DATA |
@@ -457,6 +459,10 @@ static int ds2482_probe(struct i2c_client *client)
 		goto exit;
 	}
 
+	ret = devm_regulator_get_enable(&client->dev, "vcc");
+	if (ret)
+		return dev_err_probe(&client->dev, ret, "Failed to enable regulator\n");
+
 	data->client = client;
 	i2c_set_clientdata(client, data);
 

-- 
2.39.5


Re: [PATCH v4 2/3] w1: ds2482: Add regulator support
Posted by Kryštof Černý 1 year, 2 months ago
			     I2C_FUNC_SMBUS_WRITE_BYTE_DATA |
> @@ -457,6 +459,10 @@ static int ds2482_probe(struct i2c_client *client)
>   		goto exit;
>   	}
>   
> +	ret = devm_regulator_get_enable(&client->dev, "vcc");
> +	if (ret)
> +		return dev_err_probe(&client->dev, ret, "Failed to enable regulator\n");

This will cause a memory leak of `data`, I would refactor the driver a 
bit in the next patch revision. Should I create a separate commit that 
switches from kzalloc() to devm_kzalloc() or keep it in patch 2/3? The 
separate commits way seems correct to me, so it is clearly 
distinguished. Sorry that I missed it.

> +
>   	data->client = client;
>   	i2c_set_clientdata(client, data);

Best regards,
Kryštof Černý
Re: [PATCH v4 2/3] w1: ds2482: Add regulator support
Posted by Krzysztof Kozlowski 1 year, 2 months ago
On 27/11/2024 15:21, Kryštof Černý wrote:
> 			     I2C_FUNC_SMBUS_WRITE_BYTE_DATA |
>> @@ -457,6 +459,10 @@ static int ds2482_probe(struct i2c_client *client)
>>   		goto exit;
>>   	}
>>   
>> +	ret = devm_regulator_get_enable(&client->dev, "vcc");
>> +	if (ret)
>> +		return dev_err_probe(&client->dev, ret, "Failed to enable regulator\n");
> 
> This will cause a memory leak of `data`, I would refactor the driver a 
> bit in the next patch revision. Should I create a separate commit that 
> switches from kzalloc() to devm_kzalloc() or keep it in patch 2/3? The 
> separate commits way seems correct to me, so it is clearly 
> distinguished. Sorry that I missed it.
Separate commit, please.

Best regards,
Krzysztof
Re: [PATCH v4 2/3] w1: ds2482: Add regulator support
Posted by Stefan Wahren 1 year, 2 months ago
Hi Kryštof,

Am 27.11.24 um 15:21 schrieb Kryštof Černý:
> I2C_FUNC_SMBUS_WRITE_BYTE_DATA |
>> @@ -457,6 +459,10 @@ static int ds2482_probe(struct i2c_client *client)
>>           goto exit;
>>       }
>>   +    ret = devm_regulator_get_enable(&client->dev, "vcc");
>> +    if (ret)
>> +        return dev_err_probe(&client->dev, ret, "Failed to enable
>> regulator\n");
>
> This will cause a memory leak of `data`, I would refactor the driver a
> bit in the next patch revision. Should I create a separate commit that
> switches from kzalloc() to devm_kzalloc() or keep it in patch 2/3? The
> separate commits way seems correct to me, so it is clearly
> distinguished. Sorry that I missed it.
I'm not the maintainer, but i suggests to send a V5 and add a separate
commit to avoid this issue. The merge window is still open.

Best regards
>
>> +
>>       data->client = client;
>>       i2c_set_clientdata(client, data);
>
> Best regards,
> Kryštof Černý