Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: pressure: bmp280: use devm action and remove labels from probe

We can drop some duplicate code if we use devm_action for disabling
regulators and pm and the managed variant of iio_device_register().

This allows us to completely remove all remove() callbacks from both
i2c and spi code.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Bartosz Golaszewski and committed by
Jonathan Cameron
2f4292a8 1372d1a1

+30 -45
+30 -32
drivers/iio/pressure/bmp280-core.c
··· 986 986 return 0; 987 987 } 988 988 989 + static void bmp280_pm_disable(void *data) 990 + { 991 + struct device *dev = data; 992 + 993 + pm_runtime_get_sync(dev); 994 + pm_runtime_put_noidle(dev); 995 + pm_runtime_disable(dev); 996 + } 997 + 998 + static void bmp280_regulators_disable(void *data) 999 + { 1000 + struct regulator_bulk_data *supplies = data; 1001 + 1002 + regulator_bulk_disable(BMP280_NUM_SUPPLIES, supplies); 1003 + } 1004 + 989 1005 int bmp280_common_probe(struct device *dev, 990 1006 struct regmap *regmap, 991 1007 unsigned int chip, ··· 1073 1057 return ret; 1074 1058 } 1075 1059 1060 + ret = devm_add_action_or_reset(dev, bmp280_regulators_disable, 1061 + data->supplies); 1062 + if (ret) 1063 + return ret; 1064 + 1076 1065 /* Wait to make sure we started up properly */ 1077 1066 usleep_range(data->start_up_time, data->start_up_time + 100); 1078 1067 ··· 1092 1071 data->regmap = regmap; 1093 1072 ret = regmap_read(regmap, BMP280_REG_ID, &chip_id); 1094 1073 if (ret < 0) 1095 - goto out_disable_regulators; 1074 + return ret; 1096 1075 if (chip_id != chip) { 1097 1076 dev_err(dev, "bad chip id: expected %x got %x\n", 1098 1077 chip, chip_id); 1099 - ret = -EINVAL; 1100 - goto out_disable_regulators; 1078 + return -EINVAL; 1101 1079 } 1102 1080 1103 1081 ret = data->chip_info->chip_config(data); 1104 1082 if (ret < 0) 1105 - goto out_disable_regulators; 1083 + return ret; 1106 1084 1107 1085 dev_set_drvdata(dev, indio_dev); 1108 1086 ··· 1115 1095 if (ret < 0) { 1116 1096 dev_err(data->dev, 1117 1097 "failed to read calibration coefficients\n"); 1118 - goto out_disable_regulators; 1098 + return ret; 1119 1099 } 1120 1100 } else if (chip_id == BMP280_CHIP_ID || chip_id == BME280_CHIP_ID) { 1121 1101 ret = bmp280_read_calib(data, &data->calib.bmp280, chip_id); 1122 1102 if (ret < 0) { 1123 1103 dev_err(data->dev, 1124 1104 "failed to read calibration coefficients\n"); 1125 - goto out_disable_regulators; 1105 + return ret; 1126 1106 } 1127 1107 } 1128 1108 ··· 1134 1114 if (irq > 0 || (chip_id == BMP180_CHIP_ID)) { 1135 1115 ret = bmp085_fetch_eoc_irq(dev, name, irq, data); 1136 1116 if (ret) 1137 - goto out_disable_regulators; 1117 + return ret; 1138 1118 } 1139 1119 1140 1120 /* Enable runtime PM */ ··· 1149 1129 pm_runtime_use_autosuspend(dev); 1150 1130 pm_runtime_put(dev); 1151 1131 1152 - ret = iio_device_register(indio_dev); 1132 + ret = devm_add_action_or_reset(dev, bmp280_pm_disable, dev); 1153 1133 if (ret) 1154 - goto out_runtime_pm_disable; 1134 + return ret; 1155 1135 1156 - return 0; 1157 - 1158 - out_runtime_pm_disable: 1159 - pm_runtime_get_sync(data->dev); 1160 - pm_runtime_put_noidle(data->dev); 1161 - pm_runtime_disable(data->dev); 1162 - out_disable_regulators: 1163 - regulator_bulk_disable(BMP280_NUM_SUPPLIES, data->supplies); 1164 - return ret; 1136 + return devm_iio_device_register(dev, indio_dev); 1165 1137 } 1166 1138 EXPORT_SYMBOL(bmp280_common_probe); 1167 - 1168 - int bmp280_common_remove(struct device *dev) 1169 - { 1170 - struct iio_dev *indio_dev = dev_get_drvdata(dev); 1171 - struct bmp280_data *data = iio_priv(indio_dev); 1172 - 1173 - iio_device_unregister(indio_dev); 1174 - pm_runtime_get_sync(data->dev); 1175 - pm_runtime_put_noidle(data->dev); 1176 - pm_runtime_disable(data->dev); 1177 - regulator_bulk_disable(BMP280_NUM_SUPPLIES, data->supplies); 1178 - return 0; 1179 - } 1180 - EXPORT_SYMBOL(bmp280_common_remove); 1181 1139 1182 1140 #ifdef CONFIG_PM 1183 1141 static int bmp280_runtime_suspend(struct device *dev)
-6
drivers/iio/pressure/bmp280-i2c.c
··· 38 38 client->irq); 39 39 } 40 40 41 - static int bmp280_i2c_remove(struct i2c_client *client) 42 - { 43 - return bmp280_common_remove(&client->dev); 44 - } 45 - 46 41 static const struct acpi_device_id bmp280_acpi_i2c_match[] = { 47 42 {"BMP0280", BMP280_CHIP_ID }, 48 43 {"BMP0180", BMP180_CHIP_ID }, ··· 77 82 .pm = &bmp280_dev_pm_ops, 78 83 }, 79 84 .probe = bmp280_i2c_probe, 80 - .remove = bmp280_i2c_remove, 81 85 .id_table = bmp280_i2c_id, 82 86 }; 83 87 module_i2c_driver(bmp280_i2c_driver);
-6
drivers/iio/pressure/bmp280-spi.c
··· 86 86 spi->irq); 87 87 } 88 88 89 - static int bmp280_spi_remove(struct spi_device *spi) 90 - { 91 - return bmp280_common_remove(&spi->dev); 92 - } 93 - 94 89 static const struct of_device_id bmp280_of_spi_match[] = { 95 90 { .compatible = "bosch,bmp085", }, 96 91 { .compatible = "bosch,bmp180", }, ··· 113 118 }, 114 119 .id_table = bmp280_spi_id, 115 120 .probe = bmp280_spi_probe, 116 - .remove = bmp280_spi_remove, 117 121 }; 118 122 module_spi_driver(bmp280_spi_driver); 119 123
-1
drivers/iio/pressure/bmp280.h
··· 112 112 unsigned int chip, 113 113 const char *name, 114 114 int irq); 115 - int bmp280_common_remove(struct device *dev); 116 115 117 116 /* PM ops */ 118 117 extern const struct dev_pm_ops bmp280_dev_pm_ops;