@@ -572,21 +572,25 @@ static int ktd202x_probe(struct i2c_client *client)
return ret;
}
+ mutex_init(&chip->mutex);
+
ret = ktd202x_probe_fw(chip);
if (ret < 0) {
regulator_bulk_disable(ARRAY_SIZE(chip->regulators), chip->regulators);
- return ret;
+ goto destroy_mutex;
}
ret = regulator_bulk_disable(ARRAY_SIZE(chip->regulators), chip->regulators);
if (ret) {
dev_err_probe(dev, ret, "Failed to disable regulators.\n");
- return ret;
+ goto destroy_mutex;
}
- mutex_init(&chip->mutex);
-
return 0;
+
+destroy_mutex:
+ mutex_destroy(&chip->mutex);
+ return ret;
}
static void ktd202x_remove(struct i2c_client *client)
The mutex must be initialized before the LED class device is registered otherwise there is a race where it may get used before it is initialized: DEBUG_LOCKS_WARN_ON(lock->magic != lock) WARNING: CPU: 2 PID: 2045 at kernel/locking/mutex.c:587 __mutex_lock ... RIP: 0010:__mutex_lock+0x7db/0xc10 ... set_brightness_delayed_set_brightness.part.0+0x17/0x60 set_brightness_delayed+0xf1/0x100 process_one_work+0x222/0x5a0 Signed-off-by: Hans de Goede <hdegoede@redhat.com> --- drivers/leds/rgb/leds-ktd202x.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)