/* * Make sure we don't overflow an unsigned int after kfifo rounds up to * the next power of 2.
*/ if (roundup_pow_of_two(length) > UINT_MAX / bytes_per_datum) return -EINVAL;
staticint iio_set_length_kfifo(struct iio_buffer *r, unsignedint length)
{ /* Avoid an invalid state */ if (length < 2)
length = 2; if (r->length != length) {
r->length = length;
iio_mark_update_needed_kfifo(r);
} return 0;
}
staticint iio_store_to_kfifo(struct iio_buffer *r, constvoid *data)
{ int ret; struct iio_kfifo *kf = iio_to_kfifo(r);
ret = kfifo_in(&kf->kf, data, 1); if (ret != 1) return -EBUSY; return 0;
}
staticint iio_read_kfifo(struct iio_buffer *r, size_t n, char __user *buf)
{ int ret, copied; struct iio_kfifo *kf = iio_to_kfifo(r);
if (mutex_lock_interruptible(&kf->user_lock)) return -ERESTARTSYS;
if (!kfifo_initialized(&kf->kf) || n < kfifo_esize(&kf->kf))
ret = -EINVAL; else
ret = kfifo_to_user(&kf->kf, buf, n, &copied);
mutex_unlock(&kf->user_lock); if (ret < 0) return ret;
staticint iio_kfifo_write(struct iio_buffer *r, size_t n, constchar __user *buf)
{ struct iio_kfifo *kf = iio_to_kfifo(r); int ret, copied;
mutex_lock(&kf->user_lock); if (!kfifo_initialized(&kf->kf) || n < kfifo_esize(&kf->kf))
ret = -EINVAL; else
ret = kfifo_from_user(&kf->kf, buf, n, &copied);
mutex_unlock(&kf->user_lock); if (ret) return ret;
/** * devm_iio_kfifo_allocate - Resource-managed iio_kfifo_allocate() * @dev: Device to allocate kfifo buffer for * * RETURNS: * Pointer to allocated iio_buffer on success, NULL on failure.
*/ staticstruct iio_buffer *devm_iio_kfifo_allocate(struct device *dev)
{ struct iio_buffer **ptr, *r;
ptr = devres_alloc(devm_iio_kfifo_release, sizeof(*ptr), GFP_KERNEL); if (!ptr) return NULL;
r = iio_kfifo_allocate(); if (r) {
*ptr = r;
devres_add(dev, ptr);
} else {
devres_free(ptr);
}
return r;
}
/** * devm_iio_kfifo_buffer_setup_ext - Allocate a kfifo buffer & attach it to an IIO device * @dev: Device object to which to attach the life-time of this kfifo buffer * @indio_dev: The device the buffer should be attached to * @setup_ops: The setup_ops required to configure the HW part of the buffer (optional) * @buffer_attrs: Extra sysfs buffer attributes for this IIO buffer * * This function allocates a kfifo buffer via devm_iio_kfifo_allocate() and * attaches it to the IIO device via iio_device_attach_buffer(). * This is meant to be a bit of a short-hand/helper function as there are a few * drivers that seem to do this.
*/ int devm_iio_kfifo_buffer_setup_ext(struct device *dev, struct iio_dev *indio_dev, conststruct iio_buffer_setup_ops *setup_ops, conststruct iio_dev_attr **buffer_attrs)
{ struct iio_buffer *buffer;
buffer = devm_iio_kfifo_allocate(dev); if (!buffer) return -ENOMEM;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.