Skip to contentSkip to conversation

iio: light: vcnl4000: Fix WARN_ON on uninitialized lock

PATCH Applied Mårten Lindahl 3 participants 3 messages Jan 31, 2023 – Feb 2, 2023 IIO

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 iio: light: vcnl4000: Fix WARN_ON on uninitialized lock

There are different init functions for the sensors in this driver in which only one initializes the generic vcnl4000_lock. With commit e21b5b1f2669 ("iio: light: vcnl4000: Preserve conf bits when toggle power") the vcnl4040 sensor started to depend on the lock, but it was missed to initialize it in vcnl4040's init function. This has not been visible until we run lockdep on it:

DEBUG_LOCKS_WARN_ON(lock->magic != lock)

  at kernel/locking/mutex.c:575 __mutex_lock+0x4f8/0x890
  Call trace:
  __mutex_lock
  mutex_lock_nested
  vcnl4200_set_power_state
  vcnl4200_init
  vcnl4000_probe

Fix this by initializing the lock in the probe function instead of doing it in the chip specific init functions.

Fixes e21b5b1f2669 ("iio: light: vcnl4000: Preserve conf bits when toggle power")

---

v3:
- Trimmed backtrace in commit message even more
- New line before mutex_init

v2:
- Trimmed backtrace in commit message
- Have 12 digit sha-1 id in Fixes tag
- Make the lock initialization in probe instead of in _init function

 drivers/iio/light/vcnl4000.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/light/vcnl4000.c +2 -1
index cc1a2062e76d..69c5bc987e26 100644
@@ -199,7 +199,6 @@ static int vcnl4000_init(struct vcnl4000_data *data)
 
 	data->rev = ret & 0xf;
 	data->al_scale = 250000;
-	mutex_init(&data->vcnl4000_lock);
 
 	return data->chip_spec->set_power_state(data, true);
 };
@@ -1197,6 +1196,8 @@ static int vcnl4000_probe(struct i2c_client *client)
 	data->id = id->driver_data;
 	data->chip_spec = &vcnl4000_chip_spec_cfg[data->id];
 
+	mutex_init(&data->vcnl4000_lock);
+
 	ret = data->chip_spec->init(data);
 	if (ret < 0)
 		return ret;
Signature · 1 line
2.30.2
Reviewed-by on v3 1/1
#1 lore raw
Quoted 16 lines · Mårten Lindahl

There are different init functions for the sensors in this driver in which only one initializes the generic vcnl4000_lock. With commit e21b5b1f2669 ("iio: light: vcnl4000: Preserve conf bits when toggle power") the vcnl4040 sensor started to depend on the lock, but it was missed to initialize it in vcnl4040's init function. This has not been visible until we run lockdep on it:

DEBUG_LOCKS_WARN_ON(lock->magic != lock)

  at kernel/locking/mutex.c:575 __mutex_lock+0x4f8/0x890
  Call trace:
  __mutex_lock
  mutex_lock_nested
  vcnl4200_set_power_state
  vcnl4200_init
  vcnl4000_probe
Quoted 2 lines

Fix this by initializing the lock in the probe function instead of doing it in the chip specific init functions.

Fine now, thanks!

Quoted 40 lines
Fixes e21b5b1f2669 ("iio: light: vcnl4000: Preserve conf bits when toggle power")

---

v3:
- Trimmed backtrace in commit message even more
- New line before mutex_init

v2:
- Trimmed backtrace in commit message
- Have 12 digit sha-1 id in Fixes tag
- Make the lock initialization in probe instead of in _init function

 drivers/iio/light/vcnl4000.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/light/vcnl4000.c +2 -1
index cc1a2062e76d..69c5bc987e26 100644
@@ -199,7 +199,6 @@ static int vcnl4000_init(struct vcnl4000_data *data)
 
 	data->rev = ret & 0xf;
 	data->al_scale = 250000;
-	mutex_init(&data->vcnl4000_lock);
 
 	return data->chip_spec->set_power_state(data, true);
 };
@@ -1197,6 +1196,8 @@ static int vcnl4000_probe(struct i2c_client *client)
 	data->id = id->driver_data;
 	data->chip_spec = &vcnl4000_chip_spec_cfg[data->id];
 
+	mutex_init(&data->vcnl4000_lock);
+
 	ret = data->chip_spec->init(data);
 	if (ret < 0)
 		return ret;
Signature · 1 line
2.30.2
Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer Applied
#2 lore raw
Quoted 17 lines · On Tue, 31 Jan 2023 16:14:11 +0200 Andy Shevchenko…
Quoted 16 lines · Mårten Lindahl

There are different init functions for the sensors in this driver in which only one initializes the generic vcnl4000_lock. With commit e21b5b1f2669 ("iio: light: vcnl4000: Preserve conf bits when toggle power") the vcnl4040 sensor started to depend on the lock, but it was missed to initialize it in vcnl4040's init function. This has not been visible until we run lockdep on it:

DEBUG_LOCKS_WARN_ON(lock->magic != lock)

  at kernel/locking/mutex.c:575 __mutex_lock+0x4f8/0x890
  Call trace:
  __mutex_lock
  mutex_lock_nested
  vcnl4200_set_power_state
  vcnl4200_init
  vcnl4000_probe
Quoted 8 lines
Quoted 2 lines

Fix this by initializing the lock in the probe function instead of doing it in the chip specific init functions.

Fine now, thanks!

Quoted 2 lines
Fixes e21b5b1f2669 ("iio: light: vcnl4000: Preserve conf bits when toggle power")

Applied to the fixes-togreg branch and marked for stable.

Thanks,

Jonathan

Quoted 39 lines
Quoted 38 lines

---

v3:
- Trimmed backtrace in commit message even more
- New line before mutex_init

v2:
- Trimmed backtrace in commit message
- Have 12 digit sha-1 id in Fixes tag
- Make the lock initialization in probe instead of in _init function

 drivers/iio/light/vcnl4000.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/light/vcnl4000.c +2 -1
index cc1a2062e76d..69c5bc987e26 100644
@@ -199,7 +199,6 @@ static int vcnl4000_init(struct vcnl4000_data *data)
 
 	data->rev = ret & 0xf;
 	data->al_scale = 250000;
-	mutex_init(&data->vcnl4000_lock);
 
 	return data->chip_spec->set_power_state(data, true);
 };
@@ -1197,6 +1196,8 @@ static int vcnl4000_probe(struct i2c_client *client)
 	data->id = id->driver_data;
 	data->chip_spec = &vcnl4000_chip_spec_cfg[data->id];
 
+	mutex_init(&data->vcnl4000_lock);
+
 	ret = data->chip_spec->init(data);
 	if (ret < 0)
 		return ret;
Signature · 1 line
2.30.2