iio: light: vcnl4000: Fix WARN_ON on uninitialized lock
PATCH v2 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 initialize 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 i2c_device_probe really_probe __driver_probe_device driver_probe_device __driver_attach bus_for_each_dev driver_attach bus_add_driver driver_register i2c_register_driver vcnl4000_driver_init do_one_initcall do_init_module load_module __do_sys_finit_module
Fix this by initializing the lock in the probe function instead of doing it in the chip specific init functions.
---
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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/light/vcnl4000.c +1 -1
@@ -208,7 +208,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); };
@@ -1366,6 +1365,7 @@ static int vcnl4000_probe(struct i2c_client *client, data->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 )
Signature · 1 line
2.30.2
Quoted 2 lines · Mårten Lindahl
There are different init functions for the sensors in this driver in which only one initialize the generic
vcnl4000_lock. With commit
initializes ?
Quoted 16 lines
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 i2c_device_probe really_probe __driver_probe_device
Quoted 8 lines
driver_probe_device __driver_attach bus_for_each_dev driver_attach bus_add_driver driver_register i2c_register_driver vcnl4000_driver_init
E.g. the following can be cut without losing significance of the data (see below as well).
Quoted 8 lines
do_one_initcall
do_init_module
load_module
__do_sys_finit_moduleFix this by initializing the lock in the probe function instead of doing it in the chip specific init functions.
Quoted 6 lines
Fixes e21b5b1f2669 ("iio: light: vcnl4000: Preserve conf bits when toggle power")Signed-off-by Mårten Lindahl <[email protected]>---
v2:
- Trimmed backtrace in commit message
Not enough, please try harder. The ideal is to have ~3-5 lines of traceback.
Quoted 2 lines
- Have 12 digit sha-1 id in Fixes tag
- Make the lock initialization in probe instead of in_initfunction
...
drivers/iio/light/vcnl4000.c static int vcnl4000_probe(struct i2c_client *client, · line 1367
Quoted 3 lines
drivers/iio/light/vcnl4000.c +0
-0data->client = client; data->id = id->driver_data; data->chip_spec = &vcnl4000_chip_spec_cfg[data->id];
+ Blank line.
Quoted 4 lines
drivers/iio/light/vcnl4000.c +1
-0+mutex_init (&data->vcnl4000_lock); ret = data->chip_spec->init (data);if (ret <0 )
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 1 line · Andy Shevchenko
On Tue, Jan 31, 2023 at 11:29:51AM +0100, Mårten Lindahl wrote:
...
Quoted 3 lines
Quoted 1 line
- Trimmed backtrace in commit message
Not enough, please try harder. The ideal is to have ~3-5 lines of traceback.
Just to clarify, the above example (in previous mail) under "E.g." is just to show the way of thinking about the traceback data significance. Looking at the whole traceback I believe ~7 lines is what should be left in the result.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 39 lines · Andy Shevchenko
Quoted 2 lines · Mårten Lindahl
There are different init functions for the sensors in this driver in which only one initialize the generic
vcnl4000_lock. With commitinitializes ?
Quoted 16 lines
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 i2c_device_probe really_probe __driver_probe_deviceQuoted 8 lines
driver_probe_device __driver_attach bus_for_each_dev driver_attach bus_add_driver driver_register i2c_register_driver vcnl4000_driver_initE.g. the following can be cut without losing significance of the data (see below as well).
Quoted 7 lines
do_one_initcall
do_init_module
load_module
__do_sys_finit_module
Fix this by initializing the lock in the probe function instead of doing it in the chip specific init functions.
Quoted 7 lines
Quoted 6 lines
Fixes e21b5b1f2669 ("iio: light: vcnl4000: Preserve conf bits when toggle power")Signed-off-by Mårten Lindahl <[email protected]>---
v2:
- Trimmed backtrace in commit messageNot enough, please try harder. The ideal is to have ~3-5 lines of traceback.
Hi Andy, Maybe I get it right soon ;). Could it perhaps be stripped like this?
Call trace:
__mutex_lockmutex_lock_nestedvcnl4200_set_power_statevcnl4200_initvcnl4000_probei2c_device_probe
Kind regards
Mårten
Quoted 14 lines
Quoted 3 lines
- Have 12 digit sha-1 id in Fixes tag
- Make the lock initialization in probe instead of in_initfunction...
Quoted 3 lines
data->client = client; data->id = id->driver_data; data->chip_spec = &vcnl4000_chip_spec_cfg[data->id];+ Blank line.
Quoted 4 lines
drivers/iio/light/vcnl4000.c +1
-0+mutex_init (&data->vcnl4000_lock); ret = data->chip_spec->init (data);if (ret <0 )
Quoted 2 lines · Mårten Lindahl
Quoted 1 line · Andy Shevchenko
On Tue, Jan 31, 2023 at 11:29:51AM +0100, Mårten Lindahl wrote:
...
Quoted 5 lines
Quoted 2 lines
Quoted 1 line
- Trimmed backtrace in commit message
Not enough, please try harder. The ideal is to have ~3-5 lines of traceback.
Hi Andy, Maybe I get it right soon ;). Could it perhaps be stripped like this?
Lockdep warning is important.
Assuming you left the warning still in place, almost there.
Quoted 6 lines
Call trace:
__mutex_lockmutex_lock_nestedvcnl4200_set_power_statevcnl4200_initvcnl4000_probe
Can be cut out:
Quoted 1 line
i2c_device_probe
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 13 lines · Andy Shevchenko
Quoted 2 lines · Mårten Lindahl
Quoted 1 line · Andy Shevchenko
On Tue, Jan 31, 2023 at 11:29:51AM +0100, Mårten Lindahl wrote:
...
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
- Trimmed backtrace in commit message
Not enough, please try harder. The ideal is to have ~3-5 lines of traceback.
Hi Andy, Maybe I get it right soon ;). Could it perhaps be stripped like this?
Lockdep warning is important.
Assuming you left the warning still in place, almost there.
Quoted 7 lines
Quoted 6 lines
Call trace:
__mutex_lockmutex_lock_nestedvcnl4200_set_power_statevcnl4200_initvcnl4000_probeCan be cut out:
Ok, I'll have it like this then:
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
Kind regards
Mårten
Quoted 2 lines
Quoted 2 lines
i2c_device_probe
Quoted 59 lines · Mårten Lindahl
There are different init functions for the sensors in this driver in which only one initialize the generic
vcnl4000_lock. With commite21b5b1f2669("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 i2c_device_probe really_probe __driver_probe_device driver_probe_device __driver_attach bus_for_each_dev driver_attach bus_add_driver driver_register i2c_register_driver vcnl4000_driver_init do_one_initcall do_init_module load_module __do_sys_finit_moduleFix 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")Signed-off-by Mårten Lindahl <[email protected]>---
v2:
- Trimmed backtrace in commit message
- Have 12 digit sha-1 id in Fixes tag
- Make the lock initialization in probe instead of in_initfunctiondrivers/iio/light/vcnl4000.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/light/vcnl4000.c +0
-1@@ -208,7 +208,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); };
drivers/iio/light/vcnl4000.c static int vcnl4000_probe(struct i2c_client *client, · line 1371
Quoted 7 lines
drivers/iio/light/vcnl4000.c +1
-0@@ -1366,6 +1365,7 @@ static int vcnl4000_probe(struct i2c_client *client, data->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 )
Why not add mutex_init(&data->vcnl4000_lock) in vcnl4200_init. like this
@@ -330,6 +330,7 @@ static int vcnl4200_init(struct vcnl4000_data *data)
}
mutex_init(&data->vcnl4200_al.lock);
mutex_init(&data->vcnl4200_ps.lock);+ mutex_init(&data->vcnl4000_lock);
ret = data->chip_spec->set_power_state(data, true);
if (ret < 0)Perfer adding mutex_init to vcnl4200_init.
Quoted 3 lines
Signature · 1 line
2.30.2
Quoted 79 lines · Cai Huoqing
Quoted 59 lines · Mårten Lindahl
There are different init functions for the sensors in this driver in which only one initialize the generic
vcnl4000_lock. With commite21b5b1f2669("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 i2c_device_probe really_probe __driver_probe_device driver_probe_device __driver_attach bus_for_each_dev driver_attach bus_add_driver driver_register i2c_register_driver vcnl4000_driver_init do_one_initcall do_init_module load_module __do_sys_finit_moduleFix 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")Signed-off-by Mårten Lindahl <[email protected]>---
v2:
- Trimmed backtrace in commit message
- Have 12 digit sha-1 id in Fixes tag
- Make the lock initialization in probe instead of in_initfunctiondrivers/iio/light/vcnl4000.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/light/vcnl4000.c +0
-1@@ -208,7 +208,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); };drivers/iio/light/vcnl4000.c static int vcnl4000_probe(struct i2c_client *client, · line 1371
Quoted 7 lines
drivers/iio/light/vcnl4000.c +1
-0@@ -1366,6 +1365,7 @@ static int vcnl4000_probe(struct i2c_client *client, data->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 )Why not add
mutex_init(&data->vcnl4000_lock)invcnl4200_init. like this(quoted diff) +1
-0@@ -330,6 +330,7 @@ static int vcnl4200_init(struct vcnl4000_data *data) } mutex_init(&data->vcnl4200_al.lock); mutex_init(&data->vcnl4200_ps.lock); + mutex_init(&data->vcnl4000_lock); ret = data->chip_spec->set_power_state(data, true); if (ret < 0)
Quoted 1 line
Perfer adding
mutex_inittovcnl4200_init.
Hi Cai!
This is what I did in v1, but I got a suggestion to move it to the probe instead.
Having it in probe takes one mutex_init. Otherwise it needs to be in two places (both init functions).
Kind regards
Mårten
Quoted 3 lines
Quoted 3 lines
Signature · 1 line
2.30.2
Quoted 2 lines · Mårten Lindahl
Quoted 1 line · Cai Huoqing
On 31 1月 23 11:29:51, Mårten Lindahl wrote:
...
Quoted 16 lines
Quoted 12 lines
Why not add
mutex_init(&data->vcnl4000_lock)invcnl4200_init. like this(quoted diff) +1
-0@@ -330,6 +330,7 @@ static int vcnl4200_init(struct vcnl4000_data *data) } mutex_init(&data->vcnl4200_al.lock); mutex_init(&data->vcnl4200_ps.lock); + mutex_init(&data->vcnl4000_lock); ret = data->chip_spec->set_power_state(data, true); if (ret < 0)Quoted 1 line
Perfer adding
mutex_inittovcnl4200_init.Hi Cai!
Quoted 5 lines
This is what I did in v1, but I got a suggestion to move it to the probe instead.
Having it in probe takes one
mutex_init. Otherwise it needs to be in two places (both init functions).
Exactly and if one more device will be added, we won't miss it, so it's less error prone.
Signature · 2 lines
With Best Regards, Andy Shevchenko