Commit 83ca56b6 authored by Lars-Peter Clausen's avatar Lars-Peter Clausen Committed by Jonathan Cameron

iio: core: Use sysfs_emit() (trivial bits)

sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
knows about the sysfs buffer specifics and has some built-in sanity checks.

This patch converts the places in the iio core that follow the pattern of

   return s*printf(...)

to

   return sysfs_emit(...)
Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Link: https://lore.kernel.org/r/20210320071405.9347-2-lars@metafoo.deSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 7b2d92a3
...@@ -260,7 +260,7 @@ static ssize_t iio_show_scan_index(struct device *dev, ...@@ -260,7 +260,7 @@ static ssize_t iio_show_scan_index(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
char *buf) char *buf)
{ {
return sprintf(buf, "%u\n", to_iio_dev_attr(attr)->c->scan_index); return sysfs_emit(buf, "%u\n", to_iio_dev_attr(attr)->c->scan_index);
} }
static ssize_t iio_show_fixed_type(struct device *dev, static ssize_t iio_show_fixed_type(struct device *dev,
...@@ -278,15 +278,15 @@ static ssize_t iio_show_fixed_type(struct device *dev, ...@@ -278,15 +278,15 @@ static ssize_t iio_show_fixed_type(struct device *dev,
#endif #endif
} }
if (this_attr->c->scan_type.repeat > 1) if (this_attr->c->scan_type.repeat > 1)
return sprintf(buf, "%s:%c%d/%dX%d>>%u\n", return sysfs_emit(buf, "%s:%c%d/%dX%d>>%u\n",
iio_endian_prefix[type], iio_endian_prefix[type],
this_attr->c->scan_type.sign, this_attr->c->scan_type.sign,
this_attr->c->scan_type.realbits, this_attr->c->scan_type.realbits,
this_attr->c->scan_type.storagebits, this_attr->c->scan_type.storagebits,
this_attr->c->scan_type.repeat, this_attr->c->scan_type.repeat,
this_attr->c->scan_type.shift); this_attr->c->scan_type.shift);
else else
return sprintf(buf, "%s:%c%d/%d>>%u\n", return sysfs_emit(buf, "%s:%c%d/%d>>%u\n",
iio_endian_prefix[type], iio_endian_prefix[type],
this_attr->c->scan_type.sign, this_attr->c->scan_type.sign,
this_attr->c->scan_type.realbits, this_attr->c->scan_type.realbits,
...@@ -305,7 +305,7 @@ static ssize_t iio_scan_el_show(struct device *dev, ...@@ -305,7 +305,7 @@ static ssize_t iio_scan_el_show(struct device *dev,
ret = !!test_bit(to_iio_dev_attr(attr)->address, ret = !!test_bit(to_iio_dev_attr(attr)->address,
buffer->scan_mask); buffer->scan_mask);
return sprintf(buf, "%d\n", ret); return sysfs_emit(buf, "%d\n", ret);
} }
/* Note NULL used as error indicator as it doesn't make sense. */ /* Note NULL used as error indicator as it doesn't make sense. */
...@@ -449,7 +449,7 @@ static ssize_t iio_scan_el_ts_show(struct device *dev, ...@@ -449,7 +449,7 @@ static ssize_t iio_scan_el_ts_show(struct device *dev,
{ {
struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer;
return sprintf(buf, "%d\n", buffer->scan_timestamp); return sysfs_emit(buf, "%d\n", buffer->scan_timestamp);
} }
static ssize_t iio_scan_el_ts_store(struct device *dev, static ssize_t iio_scan_el_ts_store(struct device *dev,
...@@ -541,7 +541,7 @@ static ssize_t iio_buffer_read_length(struct device *dev, ...@@ -541,7 +541,7 @@ static ssize_t iio_buffer_read_length(struct device *dev,
{ {
struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer;
return sprintf(buf, "%d\n", buffer->length); return sysfs_emit(buf, "%d\n", buffer->length);
} }
static ssize_t iio_buffer_write_length(struct device *dev, static ssize_t iio_buffer_write_length(struct device *dev,
...@@ -583,7 +583,7 @@ static ssize_t iio_buffer_show_enable(struct device *dev, ...@@ -583,7 +583,7 @@ static ssize_t iio_buffer_show_enable(struct device *dev,
{ {
struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer;
return sprintf(buf, "%d\n", iio_buffer_is_active(buffer)); return sysfs_emit(buf, "%d\n", iio_buffer_is_active(buffer));
} }
static unsigned int iio_storage_bytes_for_si(struct iio_dev *indio_dev, static unsigned int iio_storage_bytes_for_si(struct iio_dev *indio_dev,
...@@ -1227,7 +1227,7 @@ static ssize_t iio_buffer_show_watermark(struct device *dev, ...@@ -1227,7 +1227,7 @@ static ssize_t iio_buffer_show_watermark(struct device *dev,
{ {
struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer;
return sprintf(buf, "%u\n", buffer->watermark); return sysfs_emit(buf, "%u\n", buffer->watermark);
} }
static ssize_t iio_buffer_store_watermark(struct device *dev, static ssize_t iio_buffer_store_watermark(struct device *dev,
...@@ -1271,7 +1271,7 @@ static ssize_t iio_dma_show_data_available(struct device *dev, ...@@ -1271,7 +1271,7 @@ static ssize_t iio_dma_show_data_available(struct device *dev,
{ {
struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer;
return sprintf(buf, "%zu\n", iio_buffer_data_available(buffer)); return sysfs_emit(buf, "%zu\n", iio_buffer_data_available(buffer));
} }
static DEVICE_ATTR(length, S_IRUGO | S_IWUSR, iio_buffer_read_length, static DEVICE_ATTR(length, S_IRUGO | S_IWUSR, iio_buffer_read_length,
......
...@@ -234,7 +234,7 @@ ssize_t iio_read_const_attr(struct device *dev, ...@@ -234,7 +234,7 @@ ssize_t iio_read_const_attr(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
char *buf) char *buf)
{ {
return sprintf(buf, "%s\n", to_iio_const_attr(attr)->string); return sysfs_emit(buf, "%s\n", to_iio_const_attr(attr)->string);
} }
EXPORT_SYMBOL(iio_read_const_attr); EXPORT_SYMBOL(iio_read_const_attr);
...@@ -529,7 +529,7 @@ ssize_t iio_enum_read(struct iio_dev *indio_dev, ...@@ -529,7 +529,7 @@ ssize_t iio_enum_read(struct iio_dev *indio_dev,
else if (i >= e->num_items || !e->items[i]) else if (i >= e->num_items || !e->items[i])
return -EINVAL; return -EINVAL;
return snprintf(buf, PAGE_SIZE, "%s\n", e->items[i]); return sysfs_emit(buf, "%s\n", e->items[i]);
} }
EXPORT_SYMBOL_GPL(iio_enum_read); EXPORT_SYMBOL_GPL(iio_enum_read);
...@@ -580,10 +580,10 @@ ssize_t iio_show_mount_matrix(struct iio_dev *indio_dev, uintptr_t priv, ...@@ -580,10 +580,10 @@ ssize_t iio_show_mount_matrix(struct iio_dev *indio_dev, uintptr_t priv,
if (!mtx) if (!mtx)
mtx = &iio_mount_idmatrix; mtx = &iio_mount_idmatrix;
return snprintf(buf, PAGE_SIZE, "%s, %s, %s; %s, %s, %s; %s, %s, %s\n", return sysfs_emit(buf, "%s, %s, %s; %s, %s, %s; %s, %s, %s\n",
mtx->rotation[0], mtx->rotation[1], mtx->rotation[2], mtx->rotation[0], mtx->rotation[1], mtx->rotation[2],
mtx->rotation[3], mtx->rotation[4], mtx->rotation[5], mtx->rotation[3], mtx->rotation[4], mtx->rotation[5],
mtx->rotation[6], mtx->rotation[7], mtx->rotation[8]); mtx->rotation[6], mtx->rotation[7], mtx->rotation[8]);
} }
EXPORT_SYMBOL_GPL(iio_show_mount_matrix); EXPORT_SYMBOL_GPL(iio_show_mount_matrix);
...@@ -1369,7 +1369,7 @@ static ssize_t iio_show_dev_name(struct device *dev, ...@@ -1369,7 +1369,7 @@ static ssize_t iio_show_dev_name(struct device *dev,
char *buf) char *buf)
{ {
struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct iio_dev *indio_dev = dev_to_iio_dev(dev);
return snprintf(buf, PAGE_SIZE, "%s\n", indio_dev->name); return sysfs_emit(buf, "%s\n", indio_dev->name);
} }
static DEVICE_ATTR(name, S_IRUGO, iio_show_dev_name, NULL); static DEVICE_ATTR(name, S_IRUGO, iio_show_dev_name, NULL);
...@@ -1379,7 +1379,7 @@ static ssize_t iio_show_dev_label(struct device *dev, ...@@ -1379,7 +1379,7 @@ static ssize_t iio_show_dev_label(struct device *dev,
char *buf) char *buf)
{ {
struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct iio_dev *indio_dev = dev_to_iio_dev(dev);
return snprintf(buf, PAGE_SIZE, "%s\n", indio_dev->label); return sysfs_emit(buf, "%s\n", indio_dev->label);
} }
static DEVICE_ATTR(label, S_IRUGO, iio_show_dev_label, NULL); static DEVICE_ATTR(label, S_IRUGO, iio_show_dev_label, NULL);
......
...@@ -297,7 +297,7 @@ static ssize_t iio_ev_state_show(struct device *dev, ...@@ -297,7 +297,7 @@ static ssize_t iio_ev_state_show(struct device *dev,
if (val < 0) if (val < 0)
return val; return val;
else else
return sprintf(buf, "%d\n", val); return sysfs_emit(buf, "%d\n", val);
} }
static ssize_t iio_ev_value_show(struct device *dev, static ssize_t iio_ev_value_show(struct device *dev,
......
...@@ -50,7 +50,7 @@ static ssize_t iio_trigger_read_name(struct device *dev, ...@@ -50,7 +50,7 @@ static ssize_t iio_trigger_read_name(struct device *dev,
char *buf) char *buf)
{ {
struct iio_trigger *trig = to_iio_trigger(dev); struct iio_trigger *trig = to_iio_trigger(dev);
return sprintf(buf, "%s\n", trig->name); return sysfs_emit(buf, "%s\n", trig->name);
} }
static DEVICE_ATTR(name, S_IRUGO, iio_trigger_read_name, NULL); static DEVICE_ATTR(name, S_IRUGO, iio_trigger_read_name, NULL);
...@@ -375,7 +375,7 @@ static ssize_t iio_trigger_read_current(struct device *dev, ...@@ -375,7 +375,7 @@ static ssize_t iio_trigger_read_current(struct device *dev,
struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct iio_dev *indio_dev = dev_to_iio_dev(dev);
if (indio_dev->trig) if (indio_dev->trig)
return sprintf(buf, "%s\n", indio_dev->trig->name); return sysfs_emit(buf, "%s\n", indio_dev->trig->name);
return 0; return 0;
} }
......
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