Commit 3862828a authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Jonathan Cameron

iio: buffer: Switch to bitmap_zalloc()

Switch to bitmap_zalloc() to show clearly what we are allocating.
Besides that it returns pointer of bitmap type instead of opaque void *.
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 74c420e0
...@@ -36,7 +36,8 @@ static int iio_buffer_cb_store_to(struct iio_buffer *buffer, const void *data) ...@@ -36,7 +36,8 @@ static int iio_buffer_cb_store_to(struct iio_buffer *buffer, const void *data)
static void iio_buffer_cb_release(struct iio_buffer *buffer) static void iio_buffer_cb_release(struct iio_buffer *buffer)
{ {
struct iio_cb_buffer *cb_buff = buffer_to_cb_buffer(buffer); struct iio_cb_buffer *cb_buff = buffer_to_cb_buffer(buffer);
kfree(cb_buff->buffer.scan_mask);
bitmap_free(cb_buff->buffer.scan_mask);
kfree(cb_buff); kfree(cb_buff);
} }
...@@ -74,9 +75,8 @@ struct iio_cb_buffer *iio_channel_get_all_cb(struct device *dev, ...@@ -74,9 +75,8 @@ 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 cb_buff->buffer.scan_mask = bitmap_zalloc(cb_buff->indio_dev->masklength,
= kcalloc(BITS_TO_LONGS(cb_buff->indio_dev->masklength), GFP_KERNEL);
sizeof(long), GFP_KERNEL);
if (cb_buff->buffer.scan_mask == NULL) { if (cb_buff->buffer.scan_mask == NULL) {
ret = -ENOMEM; ret = -ENOMEM;
goto error_release_channels; goto error_release_channels;
...@@ -95,7 +95,7 @@ struct iio_cb_buffer *iio_channel_get_all_cb(struct device *dev, ...@@ -95,7 +95,7 @@ struct iio_cb_buffer *iio_channel_get_all_cb(struct device *dev,
return cb_buff; return cb_buff;
error_free_scan_mask: error_free_scan_mask:
kfree(cb_buff->buffer.scan_mask); bitmap_free(cb_buff->buffer.scan_mask);
error_release_channels: error_release_channels:
iio_channel_release_all(cb_buff->channels); iio_channel_release_all(cb_buff->channels);
error_free_cb_buff: error_free_cb_buff:
......
...@@ -320,9 +320,7 @@ static int iio_scan_mask_set(struct iio_dev *indio_dev, ...@@ -320,9 +320,7 @@ static int iio_scan_mask_set(struct iio_dev *indio_dev,
const unsigned long *mask; const unsigned long *mask;
unsigned long *trialmask; unsigned long *trialmask;
trialmask = kmalloc_array(BITS_TO_LONGS(indio_dev->masklength), trialmask = bitmap_alloc(indio_dev->masklength, GFP_KERNEL);
sizeof(*trialmask),
GFP_KERNEL);
if (trialmask == NULL) if (trialmask == NULL)
return -ENOMEM; return -ENOMEM;
if (!indio_dev->masklength) { if (!indio_dev->masklength) {
...@@ -344,12 +342,12 @@ static int iio_scan_mask_set(struct iio_dev *indio_dev, ...@@ -344,12 +342,12 @@ static int iio_scan_mask_set(struct iio_dev *indio_dev,
} }
bitmap_copy(buffer->scan_mask, trialmask, indio_dev->masklength); bitmap_copy(buffer->scan_mask, trialmask, indio_dev->masklength);
kfree(trialmask); bitmap_free(trialmask);
return 0; return 0;
err_invalid_mask: err_invalid_mask:
kfree(trialmask); bitmap_free(trialmask);
return -EINVAL; return -EINVAL;
} }
...@@ -666,7 +664,7 @@ static void iio_free_scan_mask(struct iio_dev *indio_dev, ...@@ -666,7 +664,7 @@ static void iio_free_scan_mask(struct iio_dev *indio_dev,
{ {
/* If the mask is dynamically allocated free it, otherwise do nothing */ /* If the mask is dynamically allocated free it, otherwise do nothing */
if (!indio_dev->available_scan_masks) if (!indio_dev->available_scan_masks)
kfree(mask); bitmap_free(mask);
} }
struct iio_device_config { struct iio_device_config {
...@@ -736,8 +734,7 @@ static int iio_verify_update(struct iio_dev *indio_dev, ...@@ -736,8 +734,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 = kcalloc(BITS_TO_LONGS(indio_dev->masklength), compound_mask = bitmap_zalloc(indio_dev->masklength, GFP_KERNEL);
sizeof(long), GFP_KERNEL);
if (compound_mask == NULL) if (compound_mask == NULL)
return -ENOMEM; return -ENOMEM;
...@@ -762,7 +759,7 @@ static int iio_verify_update(struct iio_dev *indio_dev, ...@@ -762,7 +759,7 @@ static int iio_verify_update(struct iio_dev *indio_dev,
indio_dev->masklength, indio_dev->masklength,
compound_mask, compound_mask,
strict_scanmask); strict_scanmask);
kfree(compound_mask); bitmap_free(compound_mask);
if (scan_mask == NULL) if (scan_mask == NULL)
return -EINVAL; return -EINVAL;
} else { } else {
...@@ -1303,8 +1300,7 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev) ...@@ -1303,8 +1300,7 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
channels[i].scan_index; channels[i].scan_index;
} }
if (indio_dev->masklength && buffer->scan_mask == NULL) { if (indio_dev->masklength && buffer->scan_mask == NULL) {
buffer->scan_mask = kcalloc(BITS_TO_LONGS(indio_dev->masklength), buffer->scan_mask = bitmap_zalloc(indio_dev->masklength,
sizeof(*buffer->scan_mask),
GFP_KERNEL); GFP_KERNEL);
if (buffer->scan_mask == NULL) { if (buffer->scan_mask == NULL) {
ret = -ENOMEM; ret = -ENOMEM;
...@@ -1334,7 +1330,7 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev) ...@@ -1334,7 +1330,7 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
return 0; return 0;
error_free_scan_mask: error_free_scan_mask:
kfree(buffer->scan_mask); bitmap_free(buffer->scan_mask);
error_cleanup_dynamic: error_cleanup_dynamic:
iio_free_chan_devattr_list(&buffer->scan_el_dev_attr_list); iio_free_chan_devattr_list(&buffer->scan_el_dev_attr_list);
kfree(indio_dev->buffer->buffer_group.attrs); kfree(indio_dev->buffer->buffer_group.attrs);
...@@ -1347,7 +1343,7 @@ void iio_buffer_free_sysfs_and_mask(struct iio_dev *indio_dev) ...@@ -1347,7 +1343,7 @@ void iio_buffer_free_sysfs_and_mask(struct iio_dev *indio_dev)
if (!indio_dev->buffer) if (!indio_dev->buffer)
return; return;
kfree(indio_dev->buffer->scan_mask); bitmap_free(indio_dev->buffer->scan_mask);
kfree(indio_dev->buffer->buffer_group.attrs); kfree(indio_dev->buffer->buffer_group.attrs);
kfree(indio_dev->buffer->scan_el_group.attrs); kfree(indio_dev->buffer->scan_el_group.attrs);
iio_free_chan_devattr_list(&indio_dev->buffer->scan_el_dev_attr_list); iio_free_chan_devattr_list(&indio_dev->buffer->scan_el_dev_attr_list);
......
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