Re: [ 11/21] hwmon: (sht15) Check return value of regulator_enable()

From: Ben Hutchings
Date: Sat Mar 16 2013 - 00:15:58 EST


On Tue, 2013-03-12 at 15:44 -0700, Greg Kroah-Hartman wrote:
> 3.0-stable review patch. If anyone has any objections, please let me know.
>
> ------------------
>
> From: Mark Brown <broonie@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
>
> commit 3e78080f81481aa8340374d5a37ae033c1cf4272 upstream.
>
> Not having power is a pretty serious error so check that we are able to
> enable the supply and error out if we can't.
>
> Signed-off-by: Mark Brown <broonie@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
> Signed-off-by: Guenter Roeck <linux@xxxxxxxxxxxx>

> ---
> drivers/hwmon/sht15.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> --- a/drivers/hwmon/sht15.c
> +++ b/drivers/hwmon/sht15.c
> @@ -926,7 +926,13 @@ static int __devinit sht15_probe(struct
> if (voltage)
> data->supply_uV = voltage;
>
> - regulator_enable(data->reg);
> + ret = regulator_enable(data->reg);
> + if (ret != 0) {
> + dev_err(&pdev->dev,
> + "failed to enable regulator: %d\n", ret);
> + return ret;
> + }
> +
> /*
> * Setup a notifier block to update this if another device
> * causes the voltage to change

Since this has now been released, I think you need this follow-up fix in
3.0.y and 3.4.y:

---
From: Ben Hutchings <ben@xxxxxxxxxxxxxxx>
Subject: hwmon: sht15: Fix memory leak if regulator_enable() fails
Date: Sat, 16 Mar 2013 04:11:01 +0000

Commit 3e78080f8148 ('hwmon: (sht15) Check return value of
regulator_enable()') depends on the use of devm_kmalloc() for automatic
resource cleanup in the failure cases, which was introduced in 3.7. In
older stable branches, explicit cleanup is needed.

Signed-off-by: Ben Hutchings <ben@xxxxxxxxxxxxxxx>
---
--- a/drivers/hwmon/sht15.c
+++ b/drivers/hwmon/sht15.c
@@ -930,7 +930,7 @@
if (ret != 0) {
dev_err(&pdev->dev,
"failed to enable regulator: %d\n", ret);
- return ret;
+ goto err_free_data;
}

/*


--
Ben Hutchings
It is easier to change the specification to fit the program than vice versa.

Attachment: signature.asc
Description: This is a digitally signed message part