Skip to content

Commit 7347d29

Browse files
darianaromanjic23
authored andcommitted
iio: adc: ad7192: Clean up dev
Clean up by using a local variable struct device *dev. Also use dev_err_probe where possible. Signed-off-by: Alisa-Dariana Roman <alisa.roman@analog.com> Link: https://patch.msgid.link/20240613114001.270233-2-alisa.roman@analog.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 40c0f07 commit 7347d29

File tree

1 file changed

+30
-35
lines changed

1 file changed

+30
-35
lines changed

drivers/iio/adc/ad7192.c

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,17 +1196,16 @@ static void ad7192_reg_disable(void *reg)
11961196

11971197
static int ad7192_probe(struct spi_device *spi)
11981198
{
1199+
struct device *dev = &spi->dev;
11991200
struct ad7192_state *st;
12001201
struct iio_dev *indio_dev;
12011202
struct regulator *aincom;
12021203
int ret;
12031204

1204-
if (!spi->irq) {
1205-
dev_err(&spi->dev, "no IRQ?\n");
1206-
return -ENODEV;
1207-
}
1205+
if (!spi->irq)
1206+
return dev_err_probe(dev, -ENODEV, "Failed to get IRQ\n");
12081207

1209-
indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
1208+
indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
12101209
if (!indio_dev)
12111210
return -ENOMEM;
12121211

@@ -1219,71 +1218,69 @@ static int ad7192_probe(struct spi_device *spi)
12191218
* Newer firmware should provide a zero volt fixed supply if wired to
12201219
* ground.
12211220
*/
1222-
aincom = devm_regulator_get_optional(&spi->dev, "aincom");
1221+
aincom = devm_regulator_get_optional(dev, "aincom");
12231222
if (IS_ERR(aincom)) {
12241223
if (PTR_ERR(aincom) != -ENODEV)
1225-
return dev_err_probe(&spi->dev, PTR_ERR(aincom),
1224+
return dev_err_probe(dev, PTR_ERR(aincom),
12261225
"Failed to get AINCOM supply\n");
12271226

12281227
st->aincom_mv = 0;
12291228
} else {
12301229
ret = regulator_enable(aincom);
12311230
if (ret)
1232-
return dev_err_probe(&spi->dev, ret,
1231+
return dev_err_probe(dev, ret,
12331232
"Failed to enable specified AINCOM supply\n");
12341233

1235-
ret = devm_add_action_or_reset(&spi->dev, ad7192_reg_disable, aincom);
1234+
ret = devm_add_action_or_reset(dev, ad7192_reg_disable, aincom);
12361235
if (ret)
12371236
return ret;
12381237

12391238
ret = regulator_get_voltage(aincom);
12401239
if (ret < 0)
1241-
return dev_err_probe(&spi->dev, ret,
1240+
return dev_err_probe(dev, ret,
12421241
"Device tree error, AINCOM voltage undefined\n");
12431242
st->aincom_mv = ret / MILLI;
12441243
}
12451244

1246-
st->avdd = devm_regulator_get(&spi->dev, "avdd");
1245+
st->avdd = devm_regulator_get(dev, "avdd");
12471246
if (IS_ERR(st->avdd))
12481247
return PTR_ERR(st->avdd);
12491248

12501249
ret = regulator_enable(st->avdd);
1251-
if (ret) {
1252-
dev_err(&spi->dev, "Failed to enable specified AVdd supply\n");
1253-
return ret;
1254-
}
1250+
if (ret)
1251+
return dev_err_probe(dev, ret,
1252+
"Failed to enable specified AVdd supply\n");
12551253

1256-
ret = devm_add_action_or_reset(&spi->dev, ad7192_reg_disable, st->avdd);
1254+
ret = devm_add_action_or_reset(dev, ad7192_reg_disable, st->avdd);
12571255
if (ret)
12581256
return ret;
12591257

1260-
ret = devm_regulator_get_enable(&spi->dev, "dvdd");
1258+
ret = devm_regulator_get_enable(dev, "dvdd");
12611259
if (ret)
1262-
return dev_err_probe(&spi->dev, ret, "Failed to enable specified DVdd supply\n");
1260+
return dev_err_probe(dev, ret, "Failed to enable specified DVdd supply\n");
12631261

1264-
st->vref = devm_regulator_get_optional(&spi->dev, "vref");
1262+
st->vref = devm_regulator_get_optional(dev, "vref");
12651263
if (IS_ERR(st->vref)) {
12661264
if (PTR_ERR(st->vref) != -ENODEV)
12671265
return PTR_ERR(st->vref);
12681266

12691267
ret = regulator_get_voltage(st->avdd);
12701268
if (ret < 0)
1271-
return dev_err_probe(&spi->dev, ret,
1269+
return dev_err_probe(dev, ret,
12721270
"Device tree error, AVdd voltage undefined\n");
12731271
} else {
12741272
ret = regulator_enable(st->vref);
1275-
if (ret) {
1276-
dev_err(&spi->dev, "Failed to enable specified Vref supply\n");
1277-
return ret;
1278-
}
1273+
if (ret)
1274+
return dev_err_probe(dev, ret,
1275+
"Failed to enable specified Vref supply\n");
12791276

1280-
ret = devm_add_action_or_reset(&spi->dev, ad7192_reg_disable, st->vref);
1277+
ret = devm_add_action_or_reset(dev, ad7192_reg_disable, st->vref);
12811278
if (ret)
12821279
return ret;
12831280

12841281
ret = regulator_get_voltage(st->vref);
12851282
if (ret < 0)
1286-
return dev_err_probe(&spi->dev, ret,
1283+
return dev_err_probe(dev, ret,
12871284
"Device tree error, Vref voltage undefined\n");
12881285
}
12891286
st->int_vref_mv = ret / 1000;
@@ -1305,13 +1302,13 @@ static int ad7192_probe(struct spi_device *spi)
13051302
if (ret)
13061303
return ret;
13071304

1308-
ret = devm_ad_sd_setup_buffer_and_trigger(&spi->dev, indio_dev);
1305+
ret = devm_ad_sd_setup_buffer_and_trigger(dev, indio_dev);
13091306
if (ret)
13101307
return ret;
13111308

13121309
st->fclk = AD7192_INT_FREQ_MHZ;
13131310

1314-
st->mclk = devm_clk_get_optional_enabled(&spi->dev, "mclk");
1311+
st->mclk = devm_clk_get_optional_enabled(dev, "mclk");
13151312
if (IS_ERR(st->mclk))
13161313
return PTR_ERR(st->mclk);
13171314

@@ -1320,18 +1317,16 @@ static int ad7192_probe(struct spi_device *spi)
13201317
if (st->clock_sel == AD7192_CLK_EXT_MCLK1_2 ||
13211318
st->clock_sel == AD7192_CLK_EXT_MCLK2) {
13221319
st->fclk = clk_get_rate(st->mclk);
1323-
if (!ad7192_valid_external_frequency(st->fclk)) {
1324-
dev_err(&spi->dev,
1325-
"External clock frequency out of bounds\n");
1326-
return -EINVAL;
1327-
}
1320+
if (!ad7192_valid_external_frequency(st->fclk))
1321+
return dev_err_probe(dev, -EINVAL,
1322+
"External clock frequency out of bounds\n");
13281323
}
13291324

1330-
ret = ad7192_setup(indio_dev, &spi->dev);
1325+
ret = ad7192_setup(indio_dev, dev);
13311326
if (ret)
13321327
return ret;
13331328

1334-
return devm_iio_device_register(&spi->dev, indio_dev);
1329+
return devm_iio_device_register(dev, indio_dev);
13351330
}
13361331

13371332
static const struct of_device_id ad7192_of_match[] = {

0 commit comments

Comments
 (0)