mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH RFC 0/5] iio: split struct iio_dev_attr into typed core attributes
@ 2026-11-20 18:03 Rodrigo Alencar via B4 Relay
  2026-11-20 18:03 ` [PATCH RFC 1/5] iio: buffer: add iio_attr_to_buffer() helper Rodrigo Alencar via B4 Relay
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Rodrigo Alencar via B4 Relay @ 2026-11-20 18:03 UTC (permalink / raw)
  To: linux-iio, linux-kernel
  Cc: Jonathan Cameron, David Lechner, Andy Shevchenko, Rodrigo Alencar

struct iio_dev_attr does three unrelated jobs: it backs the static
attributes declared by drivers through IIO_DEVICE_ATTR*(), the channel
and event attributes generated by the IIO core, and the per-buffer
attributes. Every user carries every field (l, c, buffer), whether it
needs them or not, and the meaning of @address depends on the context:
an info mask bit, an ext_info index, a scan index or, for events, the
event_spec index and the event info packed together.

This series keeps struct iio_dev_attr as what drivers use (dev_attr and
address) and moves the core-only state into private types embedding it:

  struct iio_chan_attr   - core channel attributes (channel, list node)
  struct iio_event_attr  - extends it with the event spec
  struct iio_buffer_attr - extends it with the owning buffer

Attribute creation is split into iio_chan_attr_prepare(), which builds
the full name and runs the duplicate check, and iio_chan_attr_add(),
which initializes an attribute allocated by the caller. Each context
allocates its own type and sets its own fields, so the core needs no
size, offset or context pointer.

The intended benefits are:

- Static driver attributes no longer carry the core-only fields: 32
  bytes less per IIO_DEVICE_ATTR*() on 64-bit (72 -> 40, without
  lockdep), for roughly 220 users in tree.

- Core channel attributes fit a smaller slab class: struct iio_chan_attr
  is 64 bytes on 64-bit, where struct iio_dev_attr was 72 (kmalloc-64
  instead of kmalloc-96).

- Shared attributes (info_mask_shared_by_*, shared ext_info and shared
  event info) are deduplicated before anything is allocated. Today,
  every channel after the first one allocates the attribute and its
  name, finds the duplicate and frees both again.

- Event attributes point to their struct iio_event_spec instead of
  packing (info << 16) | spec_index into the address.

- Buffer implementations no longer depend on the attribute layout to
  find their buffer: iio_attr_to_buffer() replaces
  to_iio_dev_attr(attr)->buffer.

- Context-specific attributes become an extension point instead of yet
  another field in a shared structure. The IIO backend framework is the
  obvious next user: iio_backend_ext_info_{get,set}() recover the
  backend from indio_dev->dev.parent, which, as noted there, breaks as
  soon as a frontend has more than one backend, and
  iio_backend_extend_chan_spec() refuses to combine backend ext_info with
  the frontend's own. A struct iio_backend_attr carrying its struct
  iio_backend, created through the same prepare/add steps (and so
  deduplicated against the frontend attributes), could address both
  without touching struct iio_dev_attr or struct iio_info. That is not
  part of this series.

No ABI change is intended: attribute names, modes and callbacks are
unchanged.

This series was developed with the help of an AI coding assistant
(Claude Opus 5.5, through Claude Code). Over an interactive session, it
reviewed the IIO core, discussed design alternatives, wrote the code
under my direction and helped write the commit messages. I reviewed all
of it, and the design choices are mine.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
---
Rodrigo Alencar (5):
      iio: buffer: add iio_attr_to_buffer() helper
      iio: core: add struct iio_chan_attr and split attribute creation
      iio: event: add struct iio_event_attr
      iio: buffer: add struct iio_buffer_attr
      iio: sysfs: drop core-only fields from struct iio_dev_attr

 drivers/iio/buffer/industrialio-buffer-dmaengine.c |   2 +-
 drivers/iio/iio_core.h                             |  58 +++--
 drivers/iio/industrialio-buffer.c                  | 153 +++++++-----
 drivers/iio/industrialio-core.c                    | 278 +++++++++++----------
 drivers/iio/industrialio-event.c                   |  99 ++++++--
 include/linux/iio/buffer_impl.h                    |   3 +
 include/linux/iio/sysfs.h                          |   9 -
 7 files changed, 361 insertions(+), 241 deletions(-)
---
base-commit: c1b99c6982dccade0199879966a2d97f27a0a110
change-id: 20261120-iio-core-attr-review-1323b39846f9

Best regards,
--  
Rodrigo Alencar <rodrigo.alencar@analog.com>



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-11-21  1:53 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20 18:03 [PATCH RFC 0/5] iio: split struct iio_dev_attr into typed core attributes Rodrigo Alencar via B4 Relay
2026-11-20 18:03 ` [PATCH RFC 1/5] iio: buffer: add iio_attr_to_buffer() helper Rodrigo Alencar via B4 Relay
2026-11-20 18:03 ` [PATCH RFC 2/5] iio: core: add struct iio_chan_attr and split attribute creation Rodrigo Alencar via B4 Relay
2026-11-21  1:25   ` Jonathan Cameron
2026-11-20 18:03 ` [PATCH RFC 3/5] iio: event: add struct iio_event_attr Rodrigo Alencar via B4 Relay
2026-11-20 18:04 ` [PATCH RFC 4/5] iio: buffer: add struct iio_buffer_attr Rodrigo Alencar via B4 Relay
2026-11-21  1:52   ` Jonathan Cameron
2026-11-20 18:04 ` [PATCH RFC 5/5] iio: sysfs: drop core-only fields from struct iio_dev_attr Rodrigo Alencar via B4 Relay
2026-11-21  1:36   ` Jonathan Cameron
2026-11-21  1:39 ` [PATCH RFC 0/5] iio: split struct iio_dev_attr into typed core attributes Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®