Commit 01676b0f authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Jonathan Cameron

iio: accel: adxl345: Convert to use dev_err_probe()

It's fine to call dev_err_probe() in ->probe() when error code is known.
Convert the driver to use dev_err_probe().
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Tested-by: default avatarKai-Heng Feng <kai.heng.feng@canonical.com>
Link: https://lore.kernel.org/r/20220222090009.2060-1-andriy.shevchenko@linux.intel.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent b30537a4
...@@ -222,16 +222,12 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, ...@@ -222,16 +222,12 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,
int ret; int ret;
ret = regmap_read(regmap, ADXL345_REG_DEVID, &regval); ret = regmap_read(regmap, ADXL345_REG_DEVID, &regval);
if (ret < 0) { if (ret < 0)
dev_err(dev, "Error reading device ID: %d\n", ret); return dev_err_probe(dev, ret, "Error reading device ID\n");
return ret;
}
if (regval != ADXL345_DEVID) { if (regval != ADXL345_DEVID)
dev_err(dev, "Invalid device ID: %x, expected %x\n", return dev_err_probe(dev, -ENODEV, "Invalid device ID: %x, expected %x\n",
regval, ADXL345_DEVID); regval, ADXL345_DEVID);
return -ENODEV;
}
indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
if (!indio_dev) if (!indio_dev)
...@@ -245,10 +241,8 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, ...@@ -245,10 +241,8 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,
ret = regmap_write(data->regmap, ADXL345_REG_DATA_FORMAT, ret = regmap_write(data->regmap, ADXL345_REG_DATA_FORMAT,
data->data_range); data->data_range);
if (ret < 0) { if (ret < 0)
dev_err(dev, "Failed to set data range: %d\n", ret); return dev_err_probe(dev, ret, "Failed to set data range\n");
return ret;
}
indio_dev->name = name; indio_dev->name = name;
indio_dev->info = &adxl345_info; indio_dev->info = &adxl345_info;
...@@ -259,10 +253,8 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, ...@@ -259,10 +253,8 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,
/* Enable measurement mode */ /* Enable measurement mode */
ret = regmap_write(data->regmap, ADXL345_REG_POWER_CTL, ret = regmap_write(data->regmap, ADXL345_REG_POWER_CTL,
ADXL345_POWER_CTL_MEASURE); ADXL345_POWER_CTL_MEASURE);
if (ret < 0) { if (ret < 0)
dev_err(dev, "Failed to enable measurement mode: %d\n", ret); return dev_err_probe(dev, ret, "Failed to enable measurement mode\n");
return ret;
}
ret = devm_add_action_or_reset(dev, adxl345_powerdown, data->regmap); ret = devm_add_action_or_reset(dev, adxl345_powerdown, data->regmap);
if (ret < 0) if (ret < 0)
......
...@@ -28,11 +28,8 @@ static int adxl345_i2c_probe(struct i2c_client *client, ...@@ -28,11 +28,8 @@ static int adxl345_i2c_probe(struct i2c_client *client,
return -ENODEV; return -ENODEV;
regmap = devm_regmap_init_i2c(client, &adxl345_i2c_regmap_config); regmap = devm_regmap_init_i2c(client, &adxl345_i2c_regmap_config);
if (IS_ERR(regmap)) { if (IS_ERR(regmap))
dev_err(&client->dev, "Error initializing i2c regmap: %ld\n", return dev_err_probe(&client->dev, PTR_ERR(regmap), "Error initializing regmap\n");
PTR_ERR(regmap));
return PTR_ERR(regmap);
}
return adxl345_core_probe(&client->dev, regmap, id->driver_data, return adxl345_core_probe(&client->dev, regmap, id->driver_data,
id->name); id->name);
......
...@@ -26,18 +26,13 @@ static int adxl345_spi_probe(struct spi_device *spi) ...@@ -26,18 +26,13 @@ static int adxl345_spi_probe(struct spi_device *spi)
struct regmap *regmap; struct regmap *regmap;
/* Bail out if max_speed_hz exceeds 5 MHz */ /* Bail out if max_speed_hz exceeds 5 MHz */
if (spi->max_speed_hz > ADXL345_MAX_SPI_FREQ_HZ) { if (spi->max_speed_hz > ADXL345_MAX_SPI_FREQ_HZ)
dev_err(&spi->dev, "SPI CLK, %d Hz exceeds 5 MHz\n", return dev_err_probe(&spi->dev, -EINVAL, "SPI CLK, %d Hz exceeds 5 MHz\n",
spi->max_speed_hz); spi->max_speed_hz);
return -EINVAL;
}
regmap = devm_regmap_init_spi(spi, &adxl345_spi_regmap_config); regmap = devm_regmap_init_spi(spi, &adxl345_spi_regmap_config);
if (IS_ERR(regmap)) { if (IS_ERR(regmap))
dev_err(&spi->dev, "Error initializing spi regmap: %ld\n", return dev_err_probe(&spi->dev, PTR_ERR(regmap), "Error initializing regmap\n");
PTR_ERR(regmap));
return PTR_ERR(regmap);
}
return adxl345_core_probe(&spi->dev, regmap, id->driver_data, id->name); return adxl345_core_probe(&spi->dev, regmap, id->driver_data, id->name);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment