diff mbox series

[v1,2/3] hwmon: tmp513: Simplify with dev_err_probe()

Message ID 20231128180654.395692-3-andriy.shevchenko@linux.intel.com (mailing list archive)
State Accepted
Headers show
Series hwmon: tmp513: A few cleanups | expand

Commit Message

Andy Shevchenko Nov. 28, 2023, 6:06 p.m. UTC
Common pattern of handling deferred probe can be simplified with
dev_err_probe().  Less code and also it prints the error value.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/hwmon/tmp513.c | 34 ++++++++++++++--------------------
 1 file changed, 14 insertions(+), 20 deletions(-)

Comments

Guenter Roeck Dec. 1, 2023, 4:10 a.m. UTC | #1
On Tue, Nov 28, 2023 at 08:06:03PM +0200, Andy Shevchenko wrote:
> Common pattern of handling deferred probe can be simplified with
> dev_err_probe().  Less code and also it prints the error value.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Applied, but ...

> ---
>  drivers/hwmon/tmp513.c | 34 ++++++++++++++--------------------
>  1 file changed, 14 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/hwmon/tmp513.c b/drivers/hwmon/tmp513.c
> index 849a8c3e1020..6e01800404fc 100644
> --- a/drivers/hwmon/tmp513.c
> +++ b/drivers/hwmon/tmp513.c
> @@ -630,9 +630,9 @@ static int tmp51x_vbus_range_to_reg(struct device *dev,
>  	} else if (data->vbus_range_uvolt == TMP51X_VBUS_RANGE_16V) {
>  		data->shunt_config &= ~TMP51X_BUS_VOLTAGE_MASK;
>  	} else {
> -		dev_err(dev, "ti,bus-range-microvolt is invalid: %u\n",
> -			data->vbus_range_uvolt);
> -		return -EINVAL;
> +		return dev_err_probe(dev, -EINVAL,
> +				     "ti,bus-range-microvolt is invalid: %u\n",
> +				     data->vbus_range_uvolt);
>  	}
>  	return 0;
>  }
> @@ -648,8 +648,8 @@ static int tmp51x_pga_gain_to_reg(struct device *dev, struct tmp51x_data *data)
>  	} else if (data->pga_gain == 1) {
>  		data->shunt_config |= CURRENT_SENSE_VOLTAGE_40_MASK;
>  	} else {
> -		dev_err(dev, "ti,pga-gain is invalid: %u\n", data->pga_gain);
> -		return -EINVAL;
> +		return dev_err_probe(dev, -EINVAL,
> +				     "ti,pga-gain is invalid: %u\n", data->pga_gain);
>  	}
>  	return 0;
>  }
> @@ -679,9 +679,9 @@ static int tmp51x_read_properties(struct device *dev, struct tmp51x_data *data)
>  
>  	// Check if shunt value is compatible with pga-gain
>  	if (data->shunt_uohms > data->pga_gain * 40 * 1000 * 1000) {
> -		dev_err(dev, "shunt-resistor: %u too big for pga_gain: %u\n",
> -			data->shunt_uohms, data->pga_gain);
> -		return -EINVAL;
> +		return dev_err_probe(dev, -EINVAL,
> +				     "shunt-resistor: %u too big for pga_gain: %u\n",
> +				     data->shunt_uohms, data->pga_gain);
>  	}
>  
>  	return 0;
> @@ -721,22 +721,16 @@ static int tmp51x_probe(struct i2c_client *client)
>  	data->max_channels = (uintptr_t)i2c_get_match_data(client);
>  
>  	ret = tmp51x_configure(dev, data);
> -	if (ret < 0) {
> -		dev_err(dev, "error configuring the device: %d\n", ret);
> -		return ret;
> -	}
> +	if (ret < 0)
> +		return dev_err_probe(dev, ret, "error configuring the device\n");
>  
>  	data->regmap = devm_regmap_init_i2c(client, &tmp51x_regmap_config);
> -	if (IS_ERR(data->regmap)) {
> -		dev_err(dev, "failed to allocate register map\n");
> -		return PTR_ERR(data->regmap);
> -	}
> +	if (IS_ERR(data->regmap))
> +		return dev_err_probe(dev, PTR_ERR(data->regmap), "failed to allocate register map\n");

That line length was getting too long. Please consider running checkpatch
on your patches.

Guenter
Andy Shevchenko Dec. 1, 2023, 1:53 p.m. UTC | #2
On Thu, Nov 30, 2023 at 08:10:12PM -0800, Guenter Roeck wrote:
> On Tue, Nov 28, 2023 at 08:06:03PM +0200, Andy Shevchenko wrote:
> > Common pattern of handling deferred probe can be simplified with
> > dev_err_probe().  Less code and also it prints the error value.

...

> > +	if (IS_ERR(data->regmap))
> > +		return dev_err_probe(dev, PTR_ERR(data->regmap), "failed to allocate register map\n");
> 
> That line length was getting too long. Please consider running checkpatch
> on your patches.

I got your point, but checkpatch has no limit for the string literals, see

f4c014c0dede ("checkpatch: allow printk strings to exceed 80 characters to maintain their searchability")
ca56dc098caf ("checkpatch: check for quoted strings broken across lines")

So, what the exact parameters should I supply to it?
Guenter Roeck Dec. 1, 2023, 2:51 p.m. UTC | #3
On 12/1/23 05:53, Andy Shevchenko wrote:
> On Thu, Nov 30, 2023 at 08:10:12PM -0800, Guenter Roeck wrote:
>> On Tue, Nov 28, 2023 at 08:06:03PM +0200, Andy Shevchenko wrote:
>>> Common pattern of handling deferred probe can be simplified with
>>> dev_err_probe().  Less code and also it prints the error value.
> 
> ...
> 
>>> +	if (IS_ERR(data->regmap))
>>> +		return dev_err_probe(dev, PTR_ERR(data->regmap), "failed to allocate register map\n");
>>
>> That line length was getting too long. Please consider running checkpatch
>> on your patches.
> 
> I got your point, but checkpatch has no limit for the string literals, see
> 
> f4c014c0dede ("checkpatch: allow printk strings to exceed 80 characters to maintain their searchability")
> ca56dc098caf ("checkpatch: check for quoted strings broken across lines")
> 
> So, what the exact parameters should I supply to it?
> 

None. Please just run checkpatch.

$ scripts/checkpatch.pl index.html
WARNING: line length of 102 exceeds 100 columns
#126: FILE: drivers/hwmon/tmp513.c:729:
+		return dev_err_probe(dev, PTR_ERR(data->regmap), "failed to allocate register map\n");

Guenter
Andy Shevchenko Dec. 1, 2023, 3:08 p.m. UTC | #4
On Fri, Dec 01, 2023 at 06:51:32AM -0800, Guenter Roeck wrote:
> On 12/1/23 05:53, Andy Shevchenko wrote:
> > On Thu, Nov 30, 2023 at 08:10:12PM -0800, Guenter Roeck wrote:
> > > On Tue, Nov 28, 2023 at 08:06:03PM +0200, Andy Shevchenko wrote:

...

> > > > +	if (IS_ERR(data->regmap))
> > > > +		return dev_err_probe(dev, PTR_ERR(data->regmap), "failed to allocate register map\n");
> > > 
> > > That line length was getting too long. Please consider running checkpatch
> > > on your patches.
> > 
> > I got your point, but checkpatch has no limit for the string literals, see
> > 
> > f4c014c0dede ("checkpatch: allow printk strings to exceed 80 characters to maintain their searchability")
> > ca56dc098caf ("checkpatch: check for quoted strings broken across lines")
> > 
> > So, what the exact parameters should I supply to it?
> 
> None. Please just run checkpatch.
> 
> $ scripts/checkpatch.pl index.html
> WARNING: line length of 102 exceeds 100 columns
> #126: FILE: drivers/hwmon/tmp513.c:729:
> +		return dev_err_probe(dev, PTR_ERR(data->regmap), "failed to allocate register map\n");

Ah, thanks!
diff mbox series

Patch

diff --git a/drivers/hwmon/tmp513.c b/drivers/hwmon/tmp513.c
index 849a8c3e1020..6e01800404fc 100644
--- a/drivers/hwmon/tmp513.c
+++ b/drivers/hwmon/tmp513.c
@@ -630,9 +630,9 @@  static int tmp51x_vbus_range_to_reg(struct device *dev,
 	} else if (data->vbus_range_uvolt == TMP51X_VBUS_RANGE_16V) {
 		data->shunt_config &= ~TMP51X_BUS_VOLTAGE_MASK;
 	} else {
-		dev_err(dev, "ti,bus-range-microvolt is invalid: %u\n",
-			data->vbus_range_uvolt);
-		return -EINVAL;
+		return dev_err_probe(dev, -EINVAL,
+				     "ti,bus-range-microvolt is invalid: %u\n",
+				     data->vbus_range_uvolt);
 	}
 	return 0;
 }
@@ -648,8 +648,8 @@  static int tmp51x_pga_gain_to_reg(struct device *dev, struct tmp51x_data *data)
 	} else if (data->pga_gain == 1) {
 		data->shunt_config |= CURRENT_SENSE_VOLTAGE_40_MASK;
 	} else {
-		dev_err(dev, "ti,pga-gain is invalid: %u\n", data->pga_gain);
-		return -EINVAL;
+		return dev_err_probe(dev, -EINVAL,
+				     "ti,pga-gain is invalid: %u\n", data->pga_gain);
 	}
 	return 0;
 }
@@ -679,9 +679,9 @@  static int tmp51x_read_properties(struct device *dev, struct tmp51x_data *data)
 
 	// Check if shunt value is compatible with pga-gain
 	if (data->shunt_uohms > data->pga_gain * 40 * 1000 * 1000) {
-		dev_err(dev, "shunt-resistor: %u too big for pga_gain: %u\n",
-			data->shunt_uohms, data->pga_gain);
-		return -EINVAL;
+		return dev_err_probe(dev, -EINVAL,
+				     "shunt-resistor: %u too big for pga_gain: %u\n",
+				     data->shunt_uohms, data->pga_gain);
 	}
 
 	return 0;
@@ -721,22 +721,16 @@  static int tmp51x_probe(struct i2c_client *client)
 	data->max_channels = (uintptr_t)i2c_get_match_data(client);
 
 	ret = tmp51x_configure(dev, data);
-	if (ret < 0) {
-		dev_err(dev, "error configuring the device: %d\n", ret);
-		return ret;
-	}
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "error configuring the device\n");
 
 	data->regmap = devm_regmap_init_i2c(client, &tmp51x_regmap_config);
-	if (IS_ERR(data->regmap)) {
-		dev_err(dev, "failed to allocate register map\n");
-		return PTR_ERR(data->regmap);
-	}
+	if (IS_ERR(data->regmap))
+		return dev_err_probe(dev, PTR_ERR(data->regmap), "failed to allocate register map\n");
 
 	ret = tmp51x_init(data);
-	if (ret < 0) {
-		dev_err(dev, "error configuring the device: %d\n", ret);
-		return -ENODEV;
-	}
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "error configuring the device\n");
 
 	hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name,
 							 data,