@@ -730,7 +730,7 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)
730
730
731
731
ret = regmap_write (data -> regmap , BMI160_REG_CMD , BMI160_CMD_SOFTRESET );
732
732
if (ret )
733
- return ret ;
733
+ goto disable_regulator ;
734
734
735
735
usleep_range (BMI160_SOFTRESET_USLEEP , BMI160_SOFTRESET_USLEEP + 1 );
736
736
@@ -741,29 +741,37 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)
741
741
if (use_spi ) {
742
742
ret = regmap_read (data -> regmap , BMI160_REG_DUMMY , & val );
743
743
if (ret )
744
- return ret ;
744
+ goto disable_regulator ;
745
745
}
746
746
747
747
ret = regmap_read (data -> regmap , BMI160_REG_CHIP_ID , & val );
748
748
if (ret ) {
749
749
dev_err (dev , "Error reading chip id\n" );
750
- return ret ;
750
+ goto disable_regulator ;
751
751
}
752
752
if (val != BMI160_CHIP_ID_VAL ) {
753
753
dev_err (dev , "Wrong chip id, got %x expected %x\n" ,
754
754
val , BMI160_CHIP_ID_VAL );
755
- return - ENODEV ;
755
+ ret = - ENODEV ;
756
+ goto disable_regulator ;
756
757
}
757
758
758
759
ret = bmi160_set_mode (data , BMI160_ACCEL , true);
759
760
if (ret )
760
- return ret ;
761
+ goto disable_regulator ;
761
762
762
763
ret = bmi160_set_mode (data , BMI160_GYRO , true);
763
764
if (ret )
764
- return ret ;
765
+ goto disable_accel ;
765
766
766
767
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 ;
767
775
}
768
776
769
777
static int bmi160_data_rdy_trigger_set_state (struct iio_trigger * trig ,
0 commit comments