Commit 66e748ae authored by Jonathan Cameron's avatar Jonathan Cameron

iio: temp: mlx90614: Handle failure in pm_runtime_resume_and_get()

Converts from using pm_runtime_get_sync() with no error handling over
to pm_runtime_resume_and_get() which will ensure we don't end up
holding a reference.  Ensure this error return is then handled at
calls to mlx90614_power_get(). These are all direct returns.
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Link: https://lore.kernel.org/r/20210509113354.660190-25-jic23@kernel.org
parent 6e4183ec
...@@ -176,11 +176,14 @@ static inline s32 mlx90614_iir_search(const struct i2c_client *client, ...@@ -176,11 +176,14 @@ static inline s32 mlx90614_iir_search(const struct i2c_client *client,
static int mlx90614_power_get(struct mlx90614_data *data, bool startup) static int mlx90614_power_get(struct mlx90614_data *data, bool startup)
{ {
unsigned long now; unsigned long now;
int ret;
if (!data->wakeup_gpio) if (!data->wakeup_gpio)
return 0; return 0;
pm_runtime_get_sync(&data->client->dev); ret = pm_runtime_resume_and_get(&data->client->dev);
if (ret < 0)
return ret;
if (startup) { if (startup) {
now = jiffies; now = jiffies;
...@@ -267,7 +270,10 @@ static int mlx90614_read_raw(struct iio_dev *indio_dev, ...@@ -267,7 +270,10 @@ static int mlx90614_read_raw(struct iio_dev *indio_dev,
*val = MLX90614_CONST_SCALE; *val = MLX90614_CONST_SCALE;
return IIO_VAL_INT; return IIO_VAL_INT;
case IIO_CHAN_INFO_CALIBEMISSIVITY: /* 1/65535 / LSB */ case IIO_CHAN_INFO_CALIBEMISSIVITY: /* 1/65535 / LSB */
mlx90614_power_get(data, false); ret = mlx90614_power_get(data, false);
if (ret < 0)
return ret;
mutex_lock(&data->lock); mutex_lock(&data->lock);
ret = i2c_smbus_read_word_data(data->client, ret = i2c_smbus_read_word_data(data->client,
MLX90614_EMISSIVITY); MLX90614_EMISSIVITY);
...@@ -287,7 +293,10 @@ static int mlx90614_read_raw(struct iio_dev *indio_dev, ...@@ -287,7 +293,10 @@ static int mlx90614_read_raw(struct iio_dev *indio_dev,
return IIO_VAL_INT_PLUS_NANO; return IIO_VAL_INT_PLUS_NANO;
case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: /* IIR setting with case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: /* IIR setting with
FIR = 1024 */ FIR = 1024 */
mlx90614_power_get(data, false); ret = mlx90614_power_get(data, false);
if (ret < 0)
return ret;
mutex_lock(&data->lock); mutex_lock(&data->lock);
ret = i2c_smbus_read_word_data(data->client, MLX90614_CONFIG); ret = i2c_smbus_read_word_data(data->client, MLX90614_CONFIG);
mutex_unlock(&data->lock); mutex_unlock(&data->lock);
...@@ -319,7 +328,10 @@ static int mlx90614_write_raw(struct iio_dev *indio_dev, ...@@ -319,7 +328,10 @@ static int mlx90614_write_raw(struct iio_dev *indio_dev,
val = val * MLX90614_CONST_RAW_EMISSIVITY_MAX + val = val * MLX90614_CONST_RAW_EMISSIVITY_MAX +
val2 / MLX90614_CONST_EMISSIVITY_RESOLUTION; val2 / MLX90614_CONST_EMISSIVITY_RESOLUTION;
mlx90614_power_get(data, false); ret = mlx90614_power_get(data, false);
if (ret < 0)
return ret;
mutex_lock(&data->lock); mutex_lock(&data->lock);
ret = mlx90614_write_word(data->client, MLX90614_EMISSIVITY, ret = mlx90614_write_word(data->client, MLX90614_EMISSIVITY,
val); val);
...@@ -331,7 +343,10 @@ static int mlx90614_write_raw(struct iio_dev *indio_dev, ...@@ -331,7 +343,10 @@ static int mlx90614_write_raw(struct iio_dev *indio_dev,
if (val < 0 || val2 < 0) if (val < 0 || val2 < 0)
return -EINVAL; return -EINVAL;
mlx90614_power_get(data, false); ret = mlx90614_power_get(data, false);
if (ret < 0)
return ret;
mutex_lock(&data->lock); mutex_lock(&data->lock);
ret = mlx90614_iir_search(data->client, ret = mlx90614_iir_search(data->client,
val * 100 + val2 / 10000); val * 100 + val2 / 10000);
......
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