drivers/iio/buffer/industrialio-buffer-cb.c
Source file repositories/reference/linux-study-clean/drivers/iio/buffer/industrialio-buffer-cb.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/buffer/industrialio-buffer-cb.c- Extension
.c- Size
- 3973 bytes
- Lines
- 157
- Domain
- Driver Families
- Bucket
- drivers/iio
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/module.hlinux/slab.hlinux/err.hlinux/export.hlinux/iio/iio.hlinux/iio/buffer_impl.hlinux/iio/consumer.h
Detected Declarations
struct iio_cb_bufferfunction iio_buffer_cb_store_tofunction iio_buffer_cb_releasefunction intfunction iio_channel_cb_set_buffer_watermarkfunction iio_channel_start_all_cbfunction iio_channel_stop_all_cbfunction iio_channel_release_all_cbexport iio_channel_get_all_cbexport iio_channel_cb_set_buffer_watermarkexport iio_channel_start_all_cbexport iio_channel_stop_all_cbexport iio_channel_release_all_cbexport iio_channel_cb_get_channelsexport iio_channel_cb_get_iio_dev
Annotated Snippet
struct iio_cb_buffer {
struct iio_buffer buffer;
/* Must be safe to call from any context (e.g. must not sleep). */
int (*cb)(const void *data, void *private);
void *private;
struct iio_channel *channels;
struct iio_dev *indio_dev;
};
static struct iio_cb_buffer *buffer_to_cb_buffer(struct iio_buffer *buffer)
{
return container_of(buffer, struct iio_cb_buffer, buffer);
}
static int iio_buffer_cb_store_to(struct iio_buffer *buffer, const void *data)
{
struct iio_cb_buffer *cb_buff = buffer_to_cb_buffer(buffer);
return cb_buff->cb(data, cb_buff->private);
}
static void iio_buffer_cb_release(struct iio_buffer *buffer)
{
struct iio_cb_buffer *cb_buff = buffer_to_cb_buffer(buffer);
bitmap_free(cb_buff->buffer.scan_mask);
kfree(cb_buff);
}
static const struct iio_buffer_access_funcs iio_cb_access = {
.store_to = &iio_buffer_cb_store_to,
.release = &iio_buffer_cb_release,
.modes = INDIO_BUFFER_SOFTWARE | INDIO_BUFFER_TRIGGERED,
};
struct iio_cb_buffer *iio_channel_get_all_cb(struct device *dev,
int (*cb)(const void *data,
void *private),
void *private)
{
int ret;
struct iio_cb_buffer *cb_buff;
struct iio_channel *chan;
if (!cb) {
dev_err(dev, "Invalid arguments: A callback must be provided!\n");
return ERR_PTR(-EINVAL);
}
cb_buff = kzalloc_obj(*cb_buff);
if (cb_buff == NULL)
return ERR_PTR(-ENOMEM);
iio_buffer_init(&cb_buff->buffer);
cb_buff->private = private;
cb_buff->cb = cb;
cb_buff->buffer.access = &iio_cb_access;
cb_buff->channels = iio_channel_get_all(dev);
if (IS_ERR(cb_buff->channels)) {
ret = PTR_ERR(cb_buff->channels);
goto error_free_cb_buff;
}
cb_buff->indio_dev = cb_buff->channels[0].indio_dev;
cb_buff->buffer.scan_mask = bitmap_zalloc(iio_get_masklength(cb_buff->indio_dev),
GFP_KERNEL);
if (cb_buff->buffer.scan_mask == NULL) {
ret = -ENOMEM;
goto error_release_channels;
}
chan = &cb_buff->channels[0];
while (chan->indio_dev) {
if (chan->indio_dev != cb_buff->indio_dev) {
ret = -EINVAL;
goto error_free_scan_mask;
}
set_bit(chan->channel->scan_index,
cb_buff->buffer.scan_mask);
chan++;
}
return cb_buff;
error_free_scan_mask:
bitmap_free(cb_buff->buffer.scan_mask);
error_release_channels:
iio_channel_release_all(cb_buff->channels);
error_free_cb_buff:
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/slab.h`, `linux/err.h`, `linux/export.h`, `linux/iio/iio.h`, `linux/iio/buffer_impl.h`, `linux/iio/consumer.h`.
- Detected declarations: `struct iio_cb_buffer`, `function iio_buffer_cb_store_to`, `function iio_buffer_cb_release`, `function int`, `function iio_channel_cb_set_buffer_watermark`, `function iio_channel_start_all_cb`, `function iio_channel_stop_all_cb`, `function iio_channel_release_all_cb`, `export iio_channel_get_all_cb`, `export iio_channel_cb_set_buffer_watermark`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.