summaryrefslogtreecommitdiff
path: root/drivers/iio/inkern.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/iio/inkern.c')
-rw-r--r--drivers/iio/inkern.c107
1 files changed, 51 insertions, 56 deletions
diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
index 9c22697b7e83..391a3380a1d1 100644
--- a/drivers/iio/inkern.c
+++ b/drivers/iio/inkern.c
@@ -10,6 +10,7 @@
#include <linux/of.h>
#include <linux/iio/iio.h>
+#include <linux/iio/iio-opaque.h>
#include "iio_core.h"
#include <linux/iio/machine.h>
#include <linux/iio/driver.h>
@@ -359,30 +360,24 @@ void iio_channel_release(struct iio_channel *channel)
}
EXPORT_SYMBOL_GPL(iio_channel_release);
-static void devm_iio_channel_free(struct device *dev, void *res)
+static void devm_iio_channel_free(void *iio_channel)
{
- struct iio_channel *channel = *(struct iio_channel **)res;
-
- iio_channel_release(channel);
+ iio_channel_release(iio_channel);
}
struct iio_channel *devm_iio_channel_get(struct device *dev,
const char *channel_name)
{
- struct iio_channel **ptr, *channel;
-
- ptr = devres_alloc(devm_iio_channel_free, sizeof(*ptr), GFP_KERNEL);
- if (!ptr)
- return ERR_PTR(-ENOMEM);
+ struct iio_channel *channel;
+ int ret;
channel = iio_channel_get(dev, channel_name);
- if (IS_ERR(channel)) {
- devres_free(ptr);
+ if (IS_ERR(channel))
return channel;
- }
- *ptr = channel;
- devres_add(dev, ptr);
+ ret = devm_add_action_or_reset(dev, devm_iio_channel_free, channel);
+ if (ret)
+ return ERR_PTR(ret);
return channel;
}
@@ -392,20 +387,16 @@ struct iio_channel *devm_of_iio_channel_get_by_name(struct device *dev,
struct device_node *np,
const char *channel_name)
{
- struct iio_channel **ptr, *channel;
-
- ptr = devres_alloc(devm_iio_channel_free, sizeof(*ptr), GFP_KERNEL);
- if (!ptr)
- return ERR_PTR(-ENOMEM);
+ struct iio_channel *channel;
+ int ret;
channel = of_iio_channel_get_by_name(np, channel_name);
- if (IS_ERR(channel)) {
- devres_free(ptr);
+ if (IS_ERR(channel))
return channel;
- }
- *ptr = channel;
- devres_add(dev, ptr);
+ ret = devm_add_action_or_reset(dev, devm_iio_channel_free, channel);
+ if (ret)
+ return ERR_PTR(ret);
return channel;
}
@@ -496,29 +487,24 @@ void iio_channel_release_all(struct iio_channel *channels)
}
EXPORT_SYMBOL_GPL(iio_channel_release_all);
-static void devm_iio_channel_free_all(struct device *dev, void *res)
+static void devm_iio_channel_free_all(void *iio_channels)
{
- struct iio_channel *channels = *(struct iio_channel **)res;
-
- iio_channel_release_all(channels);
+ iio_channel_release_all(iio_channels);
}
struct iio_channel *devm_iio_channel_get_all(struct device *dev)
{
- struct iio_channel **ptr, *channels;
-
- ptr = devres_alloc(devm_iio_channel_free_all, sizeof(*ptr), GFP_KERNEL);
- if (!ptr)
- return ERR_PTR(-ENOMEM);
+ struct iio_channel *channels;
+ int ret;
channels = iio_channel_get_all(dev);
- if (IS_ERR(channels)) {
- devres_free(ptr);
+ if (IS_ERR(channels))
return channels;
- }
- *ptr = channels;
- devres_add(dev, ptr);
+ ret = devm_add_action_or_reset(dev, devm_iio_channel_free_all,
+ channels);
+ if (ret)
+ return ERR_PTR(ret);
return channels;
}
@@ -553,9 +539,10 @@ static int iio_channel_read(struct iio_channel *chan, int *val, int *val2,
int iio_read_channel_raw(struct iio_channel *chan, int *val)
{
+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
int ret;
- mutex_lock(&chan->indio_dev->info_exist_lock);
+ mutex_lock(&iio_dev_opaque->info_exist_lock);
if (chan->indio_dev->info == NULL) {
ret = -ENODEV;
goto err_unlock;
@@ -563,7 +550,7 @@ int iio_read_channel_raw(struct iio_channel *chan, int *val)
ret = iio_channel_read(chan, val, NULL, IIO_CHAN_INFO_RAW);
err_unlock:
- mutex_unlock(&chan->indio_dev->info_exist_lock);
+ mutex_unlock(&iio_dev_opaque->info_exist_lock);
return ret;
}
@@ -571,9 +558,10 @@ EXPORT_SYMBOL_GPL(iio_read_channel_raw);
int iio_read_channel_average_raw(struct iio_channel *chan, int *val)
{
+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
int ret;
- mutex_lock(&chan->indio_dev->info_exist_lock);
+ mutex_lock(&iio_dev_opaque->info_exist_lock);
if (chan->indio_dev->info == NULL) {
ret = -ENODEV;
goto err_unlock;
@@ -581,7 +569,7 @@ int iio_read_channel_average_raw(struct iio_channel *chan, int *val)
ret = iio_channel_read(chan, val, NULL, IIO_CHAN_INFO_AVERAGE_RAW);
err_unlock:
- mutex_unlock(&chan->indio_dev->info_exist_lock);
+ mutex_unlock(&iio_dev_opaque->info_exist_lock);
return ret;
}
@@ -646,9 +634,10 @@ static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan,
int iio_convert_raw_to_processed(struct iio_channel *chan, int raw,
int *processed, unsigned int scale)
{
+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
int ret;
- mutex_lock(&chan->indio_dev->info_exist_lock);
+ mutex_lock(&iio_dev_opaque->info_exist_lock);
if (chan->indio_dev->info == NULL) {
ret = -ENODEV;
goto err_unlock;
@@ -657,7 +646,7 @@ int iio_convert_raw_to_processed(struct iio_channel *chan, int raw,
ret = iio_convert_raw_to_processed_unlocked(chan, raw, processed,
scale);
err_unlock:
- mutex_unlock(&chan->indio_dev->info_exist_lock);
+ mutex_unlock(&iio_dev_opaque->info_exist_lock);
return ret;
}
@@ -666,9 +655,10 @@ EXPORT_SYMBOL_GPL(iio_convert_raw_to_processed);
int iio_read_channel_attribute(struct iio_channel *chan, int *val, int *val2,
enum iio_chan_info_enum attribute)
{
+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
int ret;
- mutex_lock(&chan->indio_dev->info_exist_lock);
+ mutex_lock(&iio_dev_opaque->info_exist_lock);
if (chan->indio_dev->info == NULL) {
ret = -ENODEV;
goto err_unlock;
@@ -676,7 +666,7 @@ int iio_read_channel_attribute(struct iio_channel *chan, int *val, int *val2,
ret = iio_channel_read(chan, val, val2, attribute);
err_unlock:
- mutex_unlock(&chan->indio_dev->info_exist_lock);
+ mutex_unlock(&iio_dev_opaque->info_exist_lock);
return ret;
}
@@ -691,9 +681,10 @@ EXPORT_SYMBOL_GPL(iio_read_channel_offset);
int iio_read_channel_processed_scale(struct iio_channel *chan, int *val,
unsigned int scale)
{
+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
int ret;
- mutex_lock(&chan->indio_dev->info_exist_lock);
+ mutex_lock(&iio_dev_opaque->info_exist_lock);
if (chan->indio_dev->info == NULL) {
ret = -ENODEV;
goto err_unlock;
@@ -714,7 +705,7 @@ int iio_read_channel_processed_scale(struct iio_channel *chan, int *val,
}
err_unlock:
- mutex_unlock(&chan->indio_dev->info_exist_lock);
+ mutex_unlock(&iio_dev_opaque->info_exist_lock);
return ret;
}
@@ -748,9 +739,10 @@ int iio_read_avail_channel_attribute(struct iio_channel *chan,
const int **vals, int *type, int *length,
enum iio_chan_info_enum attribute)
{
+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
int ret;
- mutex_lock(&chan->indio_dev->info_exist_lock);
+ mutex_lock(&iio_dev_opaque->info_exist_lock);
if (!chan->indio_dev->info) {
ret = -ENODEV;
goto err_unlock;
@@ -758,7 +750,7 @@ int iio_read_avail_channel_attribute(struct iio_channel *chan,
ret = iio_channel_read_avail(chan, vals, type, length, attribute);
err_unlock:
- mutex_unlock(&chan->indio_dev->info_exist_lock);
+ mutex_unlock(&iio_dev_opaque->info_exist_lock);
return ret;
}
@@ -830,10 +822,11 @@ static int iio_channel_read_max(struct iio_channel *chan,
int iio_read_max_channel_raw(struct iio_channel *chan, int *val)
{
+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
int ret;
int type;
- mutex_lock(&chan->indio_dev->info_exist_lock);
+ mutex_lock(&iio_dev_opaque->info_exist_lock);
if (!chan->indio_dev->info) {
ret = -ENODEV;
goto err_unlock;
@@ -841,7 +834,7 @@ int iio_read_max_channel_raw(struct iio_channel *chan, int *val)
ret = iio_channel_read_max(chan, val, NULL, &type, IIO_CHAN_INFO_RAW);
err_unlock:
- mutex_unlock(&chan->indio_dev->info_exist_lock);
+ mutex_unlock(&iio_dev_opaque->info_exist_lock);
return ret;
}
@@ -849,10 +842,11 @@ EXPORT_SYMBOL_GPL(iio_read_max_channel_raw);
int iio_get_channel_type(struct iio_channel *chan, enum iio_chan_type *type)
{
+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
int ret = 0;
/* Need to verify underlying driver has not gone away */
- mutex_lock(&chan->indio_dev->info_exist_lock);
+ mutex_lock(&iio_dev_opaque->info_exist_lock);
if (chan->indio_dev->info == NULL) {
ret = -ENODEV;
goto err_unlock;
@@ -860,7 +854,7 @@ int iio_get_channel_type(struct iio_channel *chan, enum iio_chan_type *type)
*type = chan->channel->type;
err_unlock:
- mutex_unlock(&chan->indio_dev->info_exist_lock);
+ mutex_unlock(&iio_dev_opaque->info_exist_lock);
return ret;
}
@@ -876,9 +870,10 @@ static int iio_channel_write(struct iio_channel *chan, int val, int val2,
int iio_write_channel_attribute(struct iio_channel *chan, int val, int val2,
enum iio_chan_info_enum attribute)
{
+ struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
int ret;
- mutex_lock(&chan->indio_dev->info_exist_lock);
+ mutex_lock(&iio_dev_opaque->info_exist_lock);
if (chan->indio_dev->info == NULL) {
ret = -ENODEV;
goto err_unlock;
@@ -886,7 +881,7 @@ int iio_write_channel_attribute(struct iio_channel *chan, int val, int val2,
ret = iio_channel_write(chan, val, val2, attribute);
err_unlock:
- mutex_unlock(&chan->indio_dev->info_exist_lock);
+ mutex_unlock(&iio_dev_opaque->info_exist_lock);
return ret;
}