diff mbox

[1/1] hwmon: (ina2xx) initialize mutex before locking

Message ID 1523901203-2981-1-git-send-email-ahsan_hussain@mentor.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Ahsan Hussain April 16, 2018, 5:53 p.m. UTC
From: Ahsan Hussain <ahsan_hussain@mentor.com>

Upstream commit 8d008c0c ("hwmon: (ina2xx) Make calibration register
value fixed"), makes ina2xx_set_shunt() call mutex_lock on an
un-initialized mutex. Initialize it prior so we don't get a NULL pointer
dereference error.

Fixes: 8d008c0c ("hwmon: (ina2xx) Make calibration register value fixed")

Signed-off-by: Ahsan Hussain <ahsan_hussain@mentor.com>
---
 drivers/hwmon/ina2xx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Guenter Roeck April 16, 2018, 6:37 p.m. UTC | #1
On Mon, Apr 16, 2018 at 10:53:23PM +0500, ahsan_hussain@mentor.com wrote:
> From: Ahsan Hussain <ahsan_hussain@mentor.com>
> 
> Upstream commit 8d008c0c ("hwmon: (ina2xx) Make calibration register
> value fixed"), makes ina2xx_set_shunt() call mutex_lock on an
> un-initialized mutex. Initialize it prior so we don't get a NULL pointer
> dereference error.
> 
> Fixes: 8d008c0c ("hwmon: (ina2xx) Make calibration register value fixed")
> 
> Signed-off-by: Ahsan Hussain <ahsan_hussain@mentor.com>

Hmm ... the patch still does not apply ... having closer look ....

It appears that you don't use the mainline kernel. Commit 8d008c0c
is not upstream. It is in a stable release. Only which one ... ok,
I see it in linux-4.9.y. The offending commit is also in 4.4.y,
4.14.y, and 4.15.y. The fix needs to be pulled from upstream into
those stable releases. I'll send a request to Greg.

Thanks,
Guenter
--
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c
index a629f7c..1304f01 100644
--- a/drivers/hwmon/ina2xx.c
+++ b/drivers/hwmon/ina2xx.c
@@ -457,6 +457,8 @@  static int ina2xx_probe(struct i2c_client *client,
 			val = INA2XX_RSHUNT_DEFAULT;
 	}
 
+	mutex_init(&data->config_lock);
+
 	ina2xx_set_shunt(data, val);
 
 	ina2xx_regmap_config.max_register = data->config->registers;
@@ -473,8 +475,6 @@  static int ina2xx_probe(struct i2c_client *client,
 		return -ENODEV;
 	}
 
-	mutex_init(&data->config_lock);
-
 	data->groups[group++] = &ina2xx_group;
 	if (id->driver_data == ina226)
 		data->groups[group++] = &ina226_group;