mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/5] iio: split struct iio_dev_attr into typed core attributes
@ 2026-11-27  9:47 Rodrigo Alencar via B4 Relay
  2026-11-27  9:47 ` [PATCH v2 1/5] iio: core: emit channel prefixes into a struct seq_buf Rodrigo Alencar via B4 Relay
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Rodrigo Alencar via B4 Relay @ 2026-11-27  9:47 UTC (permalink / raw)
  To: linux-kernel, linux-iio
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko

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>
---
Changes in v2:
- Drop the RFC prefix.
- New patch 1: emit channel prefixes into a struct seq_buf.
- Remove each struct iio_dev_attr field in the patch where it stops being used.
- iio_buffer_wrap_attr(): use __free(kfree) and no_free_ptr().
- Link to v1: https://patch.msgid.link/20261120-iio-core-attr-review-v1-0-05b41f8133c2@analog.com

To: linux-kernel@vger.kernel.org
To: linux-iio@vger.kernel.org
Cc: Jonathan Cameron <jic23@kernel.org>
Cc: David Lechner <dlechner@baylibre.com>
Cc: Nuno Sá <nuno.sa@analog.com>
Cc: Andy Shevchenko <andy@kernel.org>

---
Rodrigo Alencar (5):
      iio: core: emit channel prefixes into a struct seq_buf
      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

 drivers/iio/buffer/industrialio-buffer-dmaengine.c |   2 +-
 drivers/iio/iio_core.h                             |  58 +++-
 drivers/iio/industrialio-buffer.c                  | 154 ++++++----
 drivers/iio/industrialio-core.c                    | 321 +++++++++++----------
 drivers/iio/industrialio-event.c                   |  99 +++++--
 include/linux/iio/buffer_impl.h                    |   3 +
 include/linux/iio/sysfs.h                          |   9 -
 7 files changed, 387 insertions(+), 259 deletions(-)
---
base-commit: 39508411b82d4dc29dd245bb471ec9ecc1111c9d
change-id: 20261120-iio-core-attr-review-1323b39846f9

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



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

end of thread, other threads:[~2026-11-27  9:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-27  9:47 [PATCH v2 0/5] iio: split struct iio_dev_attr into typed core attributes Rodrigo Alencar via B4 Relay
2026-11-27  9:47 ` [PATCH v2 1/5] iio: core: emit channel prefixes into a struct seq_buf Rodrigo Alencar via B4 Relay
2026-11-27  9:47 ` [PATCH v2 2/5] iio: buffer: add iio_attr_to_buffer() helper Rodrigo Alencar via B4 Relay
2026-11-27  9:47 ` [PATCH v2 3/5] iio: core: add struct iio_chan_attr and split attribute creation Rodrigo Alencar via B4 Relay
2026-11-27  9:47 ` [PATCH v2 4/5] iio: event: add struct iio_event_attr Rodrigo Alencar via B4 Relay
2026-11-27  9:47 ` [PATCH v2 5/5] iio: buffer: add struct iio_buffer_attr Rodrigo Alencar via B4 Relay

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®