1

iio: buffer: make use of iio_get_masklength()

Use iio_get_masklength() to access '.masklength' so it can be annotated
as __private when there are no more direct users of it.

While at it, remove some unneeded line breaks.

Signed-off-by: Nuno Sa <nuno.sa@analog.com>
Reviewed-by: Alexandru Ardelean <aardelean@baylibre.com>
Link: https://patch.msgid.link/20240702-dev-iio-masklength-private-v1-3-98193bf536a6@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
Nuno Sa 2024-07-02 18:02:35 +02:00 committed by Jonathan Cameron
parent c6c47852c1
commit 52fe020e7f
3 changed files with 26 additions and 30 deletions

View File

@ -77,7 +77,7 @@ struct iio_cb_buffer *iio_channel_get_all_cb(struct device *dev,
} }
cb_buff->indio_dev = cb_buff->channels[0].indio_dev; cb_buff->indio_dev = cb_buff->channels[0].indio_dev;
cb_buff->buffer.scan_mask = bitmap_zalloc(cb_buff->indio_dev->masklength, cb_buff->buffer.scan_mask = bitmap_zalloc(iio_get_masklength(cb_buff->indio_dev),
GFP_KERNEL); GFP_KERNEL);
if (cb_buff->buffer.scan_mask == NULL) { if (cb_buff->buffer.scan_mask == NULL) {
ret = -ENOMEM; ret = -ENOMEM;

View File

@ -52,6 +52,7 @@ static const struct iio_buffer_access_funcs iio_hw_buf_access = {
static struct hw_consumer_buffer *iio_hw_consumer_get_buffer( static struct hw_consumer_buffer *iio_hw_consumer_get_buffer(
struct iio_hw_consumer *hwc, struct iio_dev *indio_dev) struct iio_hw_consumer *hwc, struct iio_dev *indio_dev)
{ {
unsigned int mask_longs = BITS_TO_LONGS(iio_get_masklength(indio_dev));
struct hw_consumer_buffer *buf; struct hw_consumer_buffer *buf;
list_for_each_entry(buf, &hwc->buffers, head) { list_for_each_entry(buf, &hwc->buffers, head) {
@ -59,8 +60,7 @@ static struct hw_consumer_buffer *iio_hw_consumer_get_buffer(
return buf; return buf;
} }
buf = kzalloc(struct_size(buf, scan_mask, BITS_TO_LONGS(indio_dev->masklength)), buf = kzalloc(struct_size(buf, scan_mask, mask_longs), GFP_KERNEL);
GFP_KERNEL);
if (!buf) if (!buf)
return NULL; return NULL;

View File

@ -508,18 +508,19 @@ static bool iio_validate_scan_mask(struct iio_dev *indio_dev,
static int iio_scan_mask_set(struct iio_dev *indio_dev, static int iio_scan_mask_set(struct iio_dev *indio_dev,
struct iio_buffer *buffer, int bit) struct iio_buffer *buffer, int bit)
{ {
unsigned int masklength = iio_get_masklength(indio_dev);
const unsigned long *mask; const unsigned long *mask;
unsigned long *trialmask; unsigned long *trialmask;
if (!indio_dev->masklength) { if (!masklength) {
WARN(1, "Trying to set scanmask prior to registering buffer\n"); WARN(1, "Trying to set scanmask prior to registering buffer\n");
return -EINVAL; return -EINVAL;
} }
trialmask = bitmap_alloc(indio_dev->masklength, GFP_KERNEL); trialmask = bitmap_alloc(masklength, GFP_KERNEL);
if (!trialmask) if (!trialmask)
return -ENOMEM; return -ENOMEM;
bitmap_copy(trialmask, buffer->scan_mask, indio_dev->masklength); bitmap_copy(trialmask, buffer->scan_mask, masklength);
set_bit(bit, trialmask); set_bit(bit, trialmask);
if (!iio_validate_scan_mask(indio_dev, trialmask)) if (!iio_validate_scan_mask(indio_dev, trialmask))
@ -527,12 +528,11 @@ static int iio_scan_mask_set(struct iio_dev *indio_dev,
if (indio_dev->available_scan_masks) { if (indio_dev->available_scan_masks) {
mask = iio_scan_mask_match(indio_dev->available_scan_masks, mask = iio_scan_mask_match(indio_dev->available_scan_masks,
indio_dev->masklength, masklength, trialmask, false);
trialmask, false);
if (!mask) if (!mask)
goto err_invalid_mask; goto err_invalid_mask;
} }
bitmap_copy(buffer->scan_mask, trialmask, indio_dev->masklength); bitmap_copy(buffer->scan_mask, trialmask, masklength);
bitmap_free(trialmask); bitmap_free(trialmask);
@ -552,7 +552,7 @@ static int iio_scan_mask_clear(struct iio_buffer *buffer, int bit)
static int iio_scan_mask_query(struct iio_dev *indio_dev, static int iio_scan_mask_query(struct iio_dev *indio_dev,
struct iio_buffer *buffer, int bit) struct iio_buffer *buffer, int bit)
{ {
if (bit > indio_dev->masklength) if (bit > iio_get_masklength(indio_dev))
return -EINVAL; return -EINVAL;
if (!buffer->scan_mask) if (!buffer->scan_mask)
@ -768,8 +768,7 @@ static int iio_compute_scan_bytes(struct iio_dev *indio_dev,
int length, i, largest = 0; int length, i, largest = 0;
/* How much space will the demuxed element take? */ /* How much space will the demuxed element take? */
for_each_set_bit(i, mask, for_each_set_bit(i, mask, iio_get_masklength(indio_dev)) {
indio_dev->masklength) {
length = iio_storage_bytes_for_si(indio_dev, i); length = iio_storage_bytes_for_si(indio_dev, i);
if (length < 0) if (length < 0)
return length; return length;
@ -890,6 +889,7 @@ static int iio_verify_update(struct iio_dev *indio_dev,
struct iio_device_config *config) struct iio_device_config *config)
{ {
struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
unsigned int masklength = iio_get_masklength(indio_dev);
unsigned long *compound_mask; unsigned long *compound_mask;
const unsigned long *scan_mask; const unsigned long *scan_mask;
bool strict_scanmask = false; bool strict_scanmask = false;
@ -898,7 +898,7 @@ static int iio_verify_update(struct iio_dev *indio_dev,
unsigned int modes; unsigned int modes;
if (insert_buffer && if (insert_buffer &&
bitmap_empty(insert_buffer->scan_mask, indio_dev->masklength)) { bitmap_empty(insert_buffer->scan_mask, masklength)) {
dev_dbg(&indio_dev->dev, dev_dbg(&indio_dev->dev,
"At least one scan element must be enabled first\n"); "At least one scan element must be enabled first\n");
return -EINVAL; return -EINVAL;
@ -952,7 +952,7 @@ static int iio_verify_update(struct iio_dev *indio_dev,
} }
/* What scan mask do we actually have? */ /* What scan mask do we actually have? */
compound_mask = bitmap_zalloc(indio_dev->masklength, GFP_KERNEL); compound_mask = bitmap_zalloc(masklength, GFP_KERNEL);
if (!compound_mask) if (!compound_mask)
return -ENOMEM; return -ENOMEM;
@ -962,20 +962,19 @@ static int iio_verify_update(struct iio_dev *indio_dev,
if (buffer == remove_buffer) if (buffer == remove_buffer)
continue; continue;
bitmap_or(compound_mask, compound_mask, buffer->scan_mask, bitmap_or(compound_mask, compound_mask, buffer->scan_mask,
indio_dev->masklength); masklength);
scan_timestamp |= buffer->scan_timestamp; scan_timestamp |= buffer->scan_timestamp;
} }
if (insert_buffer) { if (insert_buffer) {
bitmap_or(compound_mask, compound_mask, bitmap_or(compound_mask, compound_mask,
insert_buffer->scan_mask, indio_dev->masklength); insert_buffer->scan_mask, masklength);
scan_timestamp |= insert_buffer->scan_timestamp; scan_timestamp |= insert_buffer->scan_timestamp;
} }
if (indio_dev->available_scan_masks) { if (indio_dev->available_scan_masks) {
scan_mask = iio_scan_mask_match(indio_dev->available_scan_masks, scan_mask = iio_scan_mask_match(indio_dev->available_scan_masks,
indio_dev->masklength, masklength, compound_mask,
compound_mask,
strict_scanmask); strict_scanmask);
bitmap_free(compound_mask); bitmap_free(compound_mask);
if (!scan_mask) if (!scan_mask)
@ -1040,6 +1039,7 @@ static int iio_buffer_add_demux(struct iio_buffer *buffer,
static int iio_buffer_update_demux(struct iio_dev *indio_dev, static int iio_buffer_update_demux(struct iio_dev *indio_dev,
struct iio_buffer *buffer) struct iio_buffer *buffer)
{ {
unsigned int masklength = iio_get_masklength(indio_dev);
int ret, in_ind = -1, out_ind, length; int ret, in_ind = -1, out_ind, length;
unsigned int in_loc = 0, out_loc = 0; unsigned int in_loc = 0, out_loc = 0;
struct iio_demux_table *p = NULL; struct iio_demux_table *p = NULL;
@ -1051,17 +1051,13 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev,
/* First work out which scan mode we will actually have */ /* First work out which scan mode we will actually have */
if (bitmap_equal(indio_dev->active_scan_mask, if (bitmap_equal(indio_dev->active_scan_mask,
buffer->scan_mask, buffer->scan_mask, masklength))
indio_dev->masklength))
return 0; return 0;
/* Now we have the two masks, work from least sig and build up sizes */ /* Now we have the two masks, work from least sig and build up sizes */
for_each_set_bit(out_ind, for_each_set_bit(out_ind, buffer->scan_mask, masklength) {
buffer->scan_mask,
indio_dev->masklength) {
in_ind = find_next_bit(indio_dev->active_scan_mask, in_ind = find_next_bit(indio_dev->active_scan_mask,
indio_dev->masklength, masklength, in_ind + 1);
in_ind + 1);
while (in_ind != out_ind) { while (in_ind != out_ind) {
ret = iio_storage_bytes_for_si(indio_dev, in_ind); ret = iio_storage_bytes_for_si(indio_dev, in_ind);
if (ret < 0) if (ret < 0)
@ -1071,8 +1067,7 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev,
/* Make sure we are aligned */ /* Make sure we are aligned */
in_loc = roundup(in_loc, length) + length; in_loc = roundup(in_loc, length) + length;
in_ind = find_next_bit(indio_dev->active_scan_mask, in_ind = find_next_bit(indio_dev->active_scan_mask,
indio_dev->masklength, masklength, in_ind + 1);
in_ind + 1);
} }
ret = iio_storage_bytes_for_si(indio_dev, in_ind); ret = iio_storage_bytes_for_si(indio_dev, in_ind);
if (ret < 0) if (ret < 0)
@ -2104,6 +2099,7 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer,
int index) int index)
{ {
struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
unsigned int masklength = iio_get_masklength(indio_dev);
struct iio_dev_attr *p; struct iio_dev_attr *p;
const struct iio_dev_attr *id_attr; const struct iio_dev_attr *id_attr;
struct attribute **attr; struct attribute **attr;
@ -2166,8 +2162,8 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer,
iio_dev_opaque->scan_index_timestamp = iio_dev_opaque->scan_index_timestamp =
channels[i].scan_index; channels[i].scan_index;
} }
if (indio_dev->masklength && !buffer->scan_mask) { if (masklength && !buffer->scan_mask) {
buffer->scan_mask = bitmap_zalloc(indio_dev->masklength, buffer->scan_mask = bitmap_zalloc(masklength,
GFP_KERNEL); GFP_KERNEL);
if (!buffer->scan_mask) { if (!buffer->scan_mask) {
ret = -ENOMEM; ret = -ENOMEM;
@ -2337,7 +2333,7 @@ void iio_buffers_free_sysfs_and_mask(struct iio_dev *indio_dev)
bool iio_validate_scan_mask_onehot(struct iio_dev *indio_dev, bool iio_validate_scan_mask_onehot(struct iio_dev *indio_dev,
const unsigned long *mask) const unsigned long *mask)
{ {
return bitmap_weight(mask, indio_dev->masklength) == 1; return bitmap_weight(mask, iio_get_masklength(indio_dev)) == 1;
} }
EXPORT_SYMBOL_GPL(iio_validate_scan_mask_onehot); EXPORT_SYMBOL_GPL(iio_validate_scan_mask_onehot);