Skip to content

Commit d926054

Browse files
lztojic23
authored andcommitted
iio:imu:bmi160: disable regulator in error path
Regulator should be disabled in error path as mentioned in _regulator_put(). Also disable accel if gyro cannot be enabled. [ 16.233604] WARNING: CPU: 0 PID: 2177 at drivers/regulator/core.c:2257 _regulator_put [ 16.240453] Call Trace: [ 16.240572] <TASK> [ 16.240676] regulator_put+0x26/0x40 [ 16.240853] regulator_bulk_free+0x26/0x50 [ 16.241050] release_nodes+0x3f/0x70 [ 16.241225] devres_release_group+0x147/0x1c0 [ 16.241441] ? bmi160_core_probe+0x175/0x3a0 [bmi160_core] Fixes: 5dea3fb ("iio: imu: bmi160: added regulator support") Reviewed-by: Andy Shevchenko <[email protected]> Signed-off-by: Tong Zhang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jonathan Cameron <[email protected]>
1 parent f502321 commit d926054

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

drivers/iio/imu/bmi160/bmi160_core.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)
730730

731731
ret = regmap_write(data->regmap, BMI160_REG_CMD, BMI160_CMD_SOFTRESET);
732732
if (ret)
733-
return ret;
733+
goto disable_regulator;
734734

735735
usleep_range(BMI160_SOFTRESET_USLEEP, BMI160_SOFTRESET_USLEEP + 1);
736736

@@ -741,29 +741,37 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)
741741
if (use_spi) {
742742
ret = regmap_read(data->regmap, BMI160_REG_DUMMY, &val);
743743
if (ret)
744-
return ret;
744+
goto disable_regulator;
745745
}
746746

747747
ret = regmap_read(data->regmap, BMI160_REG_CHIP_ID, &val);
748748
if (ret) {
749749
dev_err(dev, "Error reading chip id\n");
750-
return ret;
750+
goto disable_regulator;
751751
}
752752
if (val != BMI160_CHIP_ID_VAL) {
753753
dev_err(dev, "Wrong chip id, got %x expected %x\n",
754754
val, BMI160_CHIP_ID_VAL);
755-
return -ENODEV;
755+
ret = -ENODEV;
756+
goto disable_regulator;
756757
}
757758

758759
ret = bmi160_set_mode(data, BMI160_ACCEL, true);
759760
if (ret)
760-
return ret;
761+
goto disable_regulator;
761762

762763
ret = bmi160_set_mode(data, BMI160_GYRO, true);
763764
if (ret)
764-
return ret;
765+
goto disable_accel;
765766

766767
return 0;
768+
769+
disable_accel:
770+
bmi160_set_mode(data, BMI160_ACCEL, false);
771+
772+
disable_regulator:
773+
regulator_bulk_disable(ARRAY_SIZE(data->supplies), data->supplies);
774+
return ret;
767775
}
768776

769777
static int bmi160_data_rdy_trigger_set_state(struct iio_trigger *trig,

0 commit comments

Comments
 (0)