Skip to contentSkip to conversation

misc: add a virtual driver for testing the GPIO API

PATCH In review Bartosz Golaszewski 2 participants 8 messages Jun 13, 2024

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v8 cover misc: add a virtual driver for testing the GPIO API

From: Bartosz Golaszewski <[email protected]>

The GPIO subsystem used to have a serious problem with undefined behavior and use-after-free bugs on hot-unplug of GPIO chips. This can be considered a corner-case by some as most GPIO controllers are enabled early in the boot process and live until the system goes down but most GPIO drivers do allow unbind over sysfs, many are loadable modules that can be (force) unloaded and there are also GPIO devices that can be dynamically detached, for instance CP2112 which is a USB GPIO expender.

Bugs can be triggered both from user-space as well as by in-kernel users. We have the means of testing it from user-space via the character device but the issues manifest themselves differently in the kernel.

This is a proposition of adding a new virtual driver - a configurable GPIO consumer that can be configured over configfs (similarly to gpio-sim) or described on the device-tree.

This driver is aimed as a helper in spotting any regressions in hot-unplug handling in GPIOLIB.

v7 -> v8:
- move the driver to drivers/misc/ as it's not a GPIO provider and so its place is not in drivers/gpio/
- rework the data structures to make them more compact using unions
- use correct string helpers for given use-cases
- drop dependency on the gpio/driver.h, string.h and kernel.h headers
- add a patch exporting to_ext_attribute() to be used by this driver
- various minor improvements suggested by Andy
Link to v7: https://lore.kernel.org/linux-gpio/[email protected]/

v6 -> v7:
- this is a complete rewrite of the original idea, the entire interface has changed so it warrants a new round of reviews
Link to v6: https://lore.kernel.org/linux-gpio/[email protected]/

v5 -> v6:
- initialize the flags temp variables at declaration and hopefully make Andy happy finally :)

v4 -> v5:
- add the gpio-consumer docs to the admin-guide/gpio/ index (reported by kernel test robot <[email protected]>)

v3 -> v4:
- fix the toggle value assignment
- use guard(mutex)() wherever we can return directly from the subsequent function call
- use skip_spaces() + strim() to avoid having to do a memmove() when stripping strings off whitespaces
- DON'T try to save a couple LOC in ifdefs if that makes them less readable (Andy :) )

v2 -> v3:
- use cleanup.h interfaces
- add some clarifying commets
- more minor code tweaks

RFC -> v2:
- add documentation
- fix various issues pointed out by Andy: use struct_size() where applicable, improve the logic when storing the 'live' property, improve log messages, remove commas in terminators, etc.

Bartosz Golaszewski (2):
drivers: export to_ext_attr()
misc: gpio-virtuser: new virtual testing driver for the GPIO API

 .../admin-guide/gpio/gpio-virtuser.rst        |  176 ++
 Documentation/admin-guide/gpio/index.rst      |    1 +
 MAINTAINERS                                   |    8 +
 drivers/base/core.c                           |    2 -
 drivers/misc/Kconfig                          |    8 +
 drivers/misc/Makefile                         |    1 +
 drivers/misc/gpio-virtuser.c                  | 1790 +++++++++++++++++
 include/linux/device.h                        |    6 +
 8 files changed, 1990 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/admin-guide/gpio/gpio-virtuser.rst
 create mode 100644 drivers/misc/gpio-virtuser.c
Signature · 1 line
2.43.0
#1 lore raw

PATCH v8 1/2 drivers: export to_ext_attr()

From: Bartosz Golaszewski <[email protected]>

Make to_ext_attr() available to code that wants to reuse struct dev_ext_attribute. While at it: make it into a static inline function.

---
 drivers/base/core.c    | 2 --
 include/linux/device.h | 6 ++++++
 2 files changed, 6 insertions(+), 2 deletions(-)
drivers/base/core.c +0 -2
index 131d96c6090b..d51e7f05d15a 100644
@@ -2459,8 +2459,6 @@ static const struct sysfs_ops dev_sysfs_ops = {
 	.store	= dev_attr_store,
 };
 
-#define to_ext_attr(x) container_of(x, struct dev_ext_attribute, attr)
-
 ssize_t device_store_ulong(struct device *dev,
 			   struct device_attribute *attr,
 			   const char *buf, size_t size)
include/linux/device.h +6 -0
index fc3bd7116ab9..f7957ec918a3 100644
@@ -120,6 +120,12 @@ struct dev_ext_attribute {
 	void *var;
 };
 
+static inline struct dev_ext_attribute *
+to_ext_attr(struct device_attribute *attr)
+{
+	return container_of(attr, struct dev_ext_attribute, attr);
+}
+
 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
 			  char *buf);
 ssize_t device_store_ulong(struct device *dev, struct device_attribute *attr,
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v8 1/2] drivers: export to_ext_attr()

Quoted 4 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Make to_ext_attr() available to code that wants to reuse struct dev_ext_attribute. While at it: make it into a static inline function.

Please don't use this, why is it needed?

thanks,

greg k-h

#3 lore raw

Re: [PATCH v8 1/2] drivers: export to_ext_attr()

Quoted 4 lines · Greg Kroah-Hartman
Quoted 2 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Quoted 8 lines
Quoted 2 lines

Make to_ext_attr() available to code that wants to reuse struct dev_ext_attribute. While at it: make it into a static inline function.

Please don't use this, why is it needed?

thanks,

greg k-h

I had a struct in the gpio-virtuser module that consisted of a device_attribute and a void pointer. Andy suggested reusing struct dev_ext_attribute for that but I need this macro to access it when only having the embedded struct device_attribute address.

Bart

#4 lore raw

PATCH v8 2/2 misc: gpio-virtuser: new virtual testing driver for the GPIO API

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

The GPIO subsystem used to have a serious problem with undefined behavior and use-after-free bugs on hot-unplug of GPIO chips. This can be considered a corner-case by some as most GPIO controllers are enabled early in the boot process and live until the system goes down but most GPIO drivers do allow unbind over sysfs, many are loadable modules that can be (force) unloaded and there are also GPIO devices that can be dynamically detached, for instance CP2112 which is a USB GPIO expender.

Bugs can be triggered both from user-space as well as by in-kernel users. We have the means of testing it from user-space via the character device but the issues manifest themselves differently in the kernel.

This is a proposition of adding a new virtual driver - a configurable GPIO consumer that can be configured over configfs (similarly to gpio-sim) or described on the device-tree.

This driver is aimed as a helper in spotting any regressions in hot-unplug handling in GPIOLIB.

---
 .../admin-guide/gpio/gpio-virtuser.rst        |  176 ++
 Documentation/admin-guide/gpio/index.rst      |    1 +
 MAINTAINERS                                   |    8 +
 drivers/misc/Kconfig                          |    8 +
 drivers/misc/Makefile                         |    1 +
 drivers/misc/gpio-virtuser.c                  | 1790 +++++++++++++++++
 6 files changed, 1984 insertions(+)
 create mode 100644 Documentation/admin-guide/gpio/gpio-virtuser.rst
 create mode 100644 drivers/misc/gpio-virtuser.c
Documentation/admin-guide/gpio/gpio-virtuser.rst new file +176 -0
new file mode 100644
index 000000000000..d0d4712cf394
@@ -0,0 +1,176 @@
+.. SPDX-License-Identifier: GPL-2.0-only
+
+Virtual GPIO Consumer
+=====================
+
+The virtual GPIO Consumer module allows users to instantiate virtual devices
+that request GPIOs and then control their behavior over sysfs. Virtual consumer
+devices can be instantiated from device-tree or over configfs.
+
+A virtual consumer uses the driver-facing GPIO APIs and allows to cover it with
+automated tests driven by user-space. The GPIOs are requested using
+``gpiod_get_array()`` and so we support multiple GPIOs per connector ID.
+
+Creating GPIO consumers
+-----------------------
+
+The gpio-consumer module registers a configfs subsystem called
+``'gpio-virtuser'``. For details of the configfs filesystem, please refer to
+the configfs documentation.
+
+The user can create a hierarchy of configfs groups and items as well as modify
+values of exposed attributes. Once the consumer is instantiated, this hierarchy
+will be translated to appropriate device properties. The general structure is:
+
+**Group:** ``/config/gpio-virtuser``
+
+This is the top directory of the gpio-consumer configfs tree.
+
+**Group:** ``/config/gpio-consumer/example-name``
+
+**Attribute:** ``/config/gpio-consumer/example-name/live``
+
+**Attribute:** ``/config/gpio-consumer/example-name/dev_name``
+
+This is a directory representing a GPIO consumer device.
+
+The read-only ``dev_name`` attribute exposes the name of the device as it will
+appear in the system on the platform bus. This is useful for locating the
+associated sysfs group under ``/sys/bus/platform/devices/$dev_name``.
+
+The ``'live'`` attribute allows to trigger the actual creation of the device
+once it's fully configured. The accepted values are: ``'1'`` to enable the
+virtual device and ``'0'`` to disable and tear it down.
+
+Creating GPIO lookup tables
+---------------------------
+
+Users can create a number of configfs groups under the device group:
+
+**Group:** ``/config/gpio-consumer/example-name/con_id``
+
+The ``'con_id'`` directory represents a single GPIO lookup and its value maps
+to the ``'con_id'`` argument of the ``gpiod_get()`` function. For example:
+``con_id`` == ``'reset'`` maps to the ``reset-gpios`` device property.
+
+Users can assign a number of GPIOs to each lookup. Each GPIO is a sub-directory
+with a user-defined name under the ``'con_id'`` group.
+
+**Attribute:** ``/config/gpio-consumer/example-name/con_id/0/key``
+
+**Attribute:** ``/config/gpio-consumer/example-name/con_id/0/offset``
+
+**Attribute:** ``/config/gpio-consumer/example-name/con_id/0/drive``
+
+**Attribute:** ``/config/gpio-consumer/example-name/con_id/0/pull``
+
+**Attribute:** ``/config/gpio-consumer/example-name/con_id/0/active_low``
+
+**Attribute:** ``/config/gpio-consumer/example-name/con_id/0/transitory``
+
+This is a group describing a single GPIO in the ``con_id-gpios`` property.
+
+For virtual consumers created using configfs we use machine lookup tables so
+this group can be considered as a mapping between the filesystem and the fields
+of a single entry in ``'struct gpiod_lookup'``.
+
+The ``'key'`` attribute represents either the name of the chip this GPIO
+belongs to or the GPIO line name. This depends on the value of the ``'offset'``
+attribute: if its value is >= 0, then ``'key'`` represents the label of the
+chip to lookup while ``'offset'`` represents the offset of the line in that
+chip. If ``'offset'`` is < 0, then ``'key'`` represents the name of the line.
+
+The remaining attributes map to the ``'flags'`` field of the GPIO lookup
+struct. The first two take string values as arguments:
+
+**``'drive'``:** ``'push-pull'``, ``'open-drain'``, ``'open-source'``
+**``'pull'``:** ``'pull-up'``, ``'pull-down'``, ``'pull-disabled'``, ``'as-is'``
+
+``'active_low'`` and ``'transitory'`` are boolean attributes.
+
+Activating GPIO consumers
+-------------------------
+
+Once the confiuration is complete, the ``'live'`` attribute must be set to 1 in
+order to instantiate the consumer. It can be set back to 0 to destroy the
+virtual device. The module will synchronously wait for the new simulated device
+to be successfully probed and if this doesn't happen, writing to ``'live'`` will
+result in an error.
+
+Device-tree
+-----------
+
+Virtual GPIO consumers can also be defined in device-tree. The compatible string
+must be: ``"gpio-virtuser"`` with at least one property following the
+standardized GPIO pattern.
+
+An example device-tree code defining a virtual GPIO consumer:
+
+.. code-block :: none
+
+    gpio-virt-consumer {
+        compatible = "gpio-virtuser";
+
+        foo-gpios = <&gpio0 5 GPIO_ACTIVE_LOW>, <&gpio1 2 0>;
+        bar-gpios = <&gpio0 6 0>;
+    };
+
+Controlling virtual GPIO consumers
+----------------------------------
+
+Once active, the device will export sysfs attributes for controlling GPIO
+arrays as well as each requested GPIO line separately. Let's consider the
+following device property: ``foo-gpios = <&gpio0 0 0>, <&gpio0 4 0>;``.
+
+The following sysfs attribute groups will be created:
+
+**Group:** ``/sys/bus/platform/device/$dev_name/gpiod:foo/``
+
+This is the group that will contain the attributes for the entire GPIO array.
+
+**Attribute:** ``/sys/bus/platform/device/$dev_name/gpiod:foo/values``
+
+**Attribute:** ``/sys/bus/platform/device/$dev_name/gpiod:foo/values_atomic``
+
+Both attributes allow to read and set arrays of GPIO values. User must pass
+exactly the number of values that the array contains in the form of a string
+containing zeroes and ones representing inactive and active GPIO states
+respectively. In this example: ``echo 11 > values``.
+
+The ``values_atomic`` attribute works the same as ``values`` but the kernel
+will execute the GPIO driver callbacks in interrupt context.
+
+**Group:** ``/sys/bus/platform/device/$dev_name/gpiod:foo:$index/``
+
+This is a group that represents a single GPIO with ``$index`` being its offset
+in the array.
+
+**Attribute:** ``/sys/bus/platform/device/$dev_name/gpiod:foo:$index/consumer``
+
+Allows to set and read the consumer label of the GPIO line.
+
+**Attribute:** ``/sys/bus/platform/device/$dev_name/gpiod:foo:$index/debounce``
+
+Allows to set and read the debounce period of the GPIO line.
+
+**Attribute:** ``/sys/bus/platform/device/$dev_name/gpiod:foo:$index/direction``
+
+**Attribute:** ``/sys/bus/platform/device/$dev_name/gpiod:foo:$index/direction_atomic``
+
+These two attributes allow to set the direction of the GPIO line. They accept
+"input" and "output" as values. The atomic variant executes the driver callback
+in interrupt context.
+
+**Attribute:** ``/sys/bus/platform/device/$dev_name/gpiod:foo:$index/interrupts``
+
+If the line is requested in input mode, writing ``1`` to this attribute will
+make the module listen for edge interrupts on the GPIO. Writing ``0`` disables
+the monitoring. Reading this attribute returns the current number of registered
+interrupts (both edges).
+
+**Attribute:** ``/sys/bus/platform/device/$dev_name/gpiod:foo:$index/value``
+
+**Attribute:** ``/sys/bus/platform/device/$dev_name/gpiod:foo:$index/value_atomic``
+
+Both attributes allow to read and set values of individual requested GPIO lines.
+They accept the following values: ``active``, ``1``, ``inactive`` and ``0``.
Documentation/admin-guide/gpio/index.rst +1 -0
index 460afd29617e..712f379731cb 100644
@@ -10,6 +10,7 @@ GPIO
     Character Device Userspace API <../../userspace-api/gpio/chardev>
     gpio-aggregator
     gpio-sim
+    gpio-virtuser
     Obsolete APIs <obsolete>
 
 .. only::  subproject and html
MAINTAINERS +8 -0
index d6c90161c7bf..3a5a83fdceea 100644
@@ -9427,6 +9427,14 @@ F:	drivers/gpio/gpiolib-cdev.c
 F:	include/uapi/linux/gpio.h
 F:	tools/gpio/
 
+GPIO VIRTUSER
+M:	Bartosz Golaszewski <[email protected]>
+L:	[email protected]
+S:	Maintained
+T:	git git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux.git
+F:	Documentation/admin-guide/gpio/gpio-virtuser.rst
+F:	drivers/misc/gpio-virtuser.c
+
 GRE DEMULTIPLEXER DRIVER
 M:	Dmitry Kozlov <[email protected]>
 L:	[email protected]
drivers/misc/Kconfig +8 -0
index faf983680040..0e705b7d0762 100644
@@ -585,6 +585,14 @@ config NSM
 	  To compile this driver as a module, choose M here.
 	  The module will be called nsm.
 
+config GPIO_VIRTUSER
+	tristate "GPIO Virtual User Testing Module"
+	select CONFIGFS_FS
+	select IRQ_WORK
+	help
+	  This enables the configurable, configfs-based virtual GPIO consumer
+	  testing driver.
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile +1 -0
index 153a3f4837e8..963307d4e69b 100644
@@ -69,3 +69,4 @@ obj-$(CONFIG_TMR_INJECT)	+= xilinx_tmr_inject.o
 obj-$(CONFIG_TPS6594_ESM)	+= tps6594-esm.o
 obj-$(CONFIG_TPS6594_PFSM)	+= tps6594-pfsm.o
 obj-$(CONFIG_NSM)		+= nsm.o
+obj-$(CONFIG_GPIO_VIRTUSER)	+= gpio-virtuser.o
drivers/misc/gpio-virtuser.c new file +1790 -0

1,790 lines not on this page · raw message

Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH v8 2/2] misc: gpio-virtuser: new virtual testing driver for the GPIO API

Quoted 18 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

The GPIO subsystem used to have a serious problem with undefined behavior and use-after-free bugs on hot-unplug of GPIO chips. This can be considered a corner-case by some as most GPIO controllers are enabled early in the boot process and live until the system goes down but most GPIO drivers do allow unbind over sysfs, many are loadable modules that can be (force) unloaded and there are also GPIO devices that can be dynamically detached, for instance CP2112 which is a USB GPIO expender.

Bugs can be triggered both from user-space as well as by in-kernel users. We have the means of testing it from user-space via the character device but the issues manifest themselves differently in the kernel.

This is a proposition of adding a new virtual driver - a configurable GPIO consumer that can be configured over configfs (similarly to gpio-sim) or described on the device-tree.

Quoted 7 lines

This driver is aimed as a helper in spotting any regressions in hot-unplug handling in GPIOLIB.

---
 .../admin-guide/gpio/gpio-virtuser.rst        |  176 ++
 Documentation/admin-guide/gpio/index.rst      |    1 +

sysfs documentation needs to go in Documentation/ABI/ not in a random .rst file where the tools that check this will not catch it.

Quoted 4 lines
 MAINTAINERS                                   |    8 +
 drivers/misc/Kconfig                          |    8 +
 drivers/misc/Makefile                         |    1 +
 drivers/misc/gpio-virtuser.c                  | 1790 +++++++++++++++++

Why not put this in drivers/gpio/? Why misc?

Documentation/admin-guide/gpio/gpio-virtuser.rst line 138

Quoted 4 lines
Documentation/admin-guide/gpio/gpio-virtuser.rst new file +4 -0
+Both attributes allow to read and set arrays of GPIO values. User must pass
+exactly the number of values that the array contains in the form of a string
+containing zeroes and ones representing inactive and active GPIO states
+respectively. In this example: ``echo 11 > values``.

sysfs is "one value per file", so why are there multiple values here?

If you want to just use this for testing, and want to put whatever you want in the files, just use debugfs, that's what it is there for, not sysfs.

drivers/misc/Kconfig config NSM · line 595

Quoted 8 lines
drivers/misc/Kconfig +8 -0
+config GPIO_VIRTUSER
+	tristate "GPIO Virtual User Testing Module"
+	select CONFIGFS_FS
+	select IRQ_WORK
+	help
+	  This enables the configurable, configfs-based virtual GPIO consumer
+	  testing driver.
+

module name?

And you need more documentation here, I have no idea what this means when it shows up in a Kconfig help entry :(

thanks,

greg k-h

#6 lore raw

Re: [PATCH v8 2/2] misc: gpio-virtuser: new virtual testing driver for the GPIO API

Quoted 23 lines · Greg Kroah-Hartman
Quoted 21 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

The GPIO subsystem used to have a serious problem with undefined behavior and use-after-free bugs on hot-unplug of GPIO chips. This can be considered a corner-case by some as most GPIO controllers are enabled early in the boot process and live until the system goes down but most GPIO drivers do allow unbind over sysfs, many are loadable modules that can be (force) unloaded and there are also GPIO devices that can be dynamically detached, for instance CP2112 which is a USB GPIO expender.

Bugs can be triggered both from user-space as well as by in-kernel users. We have the means of testing it from user-space via the character device but the issues manifest themselves differently in the kernel.

This is a proposition of adding a new virtual driver - a configurable GPIO consumer that can be configured over configfs (similarly to gpio-sim) or described on the device-tree.

This driver is aimed as a helper in spotting any regressions in hot-unplug handling in GPIOLIB.

Quoted 8 lines
Quoted 4 lines
---
 .../admin-guide/gpio/gpio-virtuser.rst        |  176 ++
 Documentation/admin-guide/gpio/index.rst      |    1 +

sysfs documentation needs to go in Documentation/ABI/ not in a random .rst file where the tools that check this will not catch it.

This is a testing driver, not representing real hardware. Do we hold such modules to the same standard?

Quoted 7 lines
Quoted 4 lines
 MAINTAINERS                                   |    8 +
 drivers/misc/Kconfig                          |    8 +
 drivers/misc/Makefile                         |    1 +
 drivers/misc/gpio-virtuser.c                  | 1790 +++++++++++++++++

Why not put this in drivers/gpio/? Why misc?

Because it's quite... well "misc". It's not a GPIO chip provider (drivers/gpio/ is for GPIO providers), it's only a GPIO consumer. It also has an interface that doesn't fit any particular subsystem.

Quoted 11 lines

Documentation/admin-guide/gpio/gpio-virtuser.rst line 138

Quoted 4 lines
Documentation/admin-guide/gpio/gpio-virtuser.rst new file +4 -0
+Both attributes allow to read and set arrays of GPIO values. User must pass
+exactly the number of values that the array contains in the form of a string
+containing zeroes and ones representing inactive and active GPIO states
+respectively. In this example: ``echo 11 > values``.

sysfs is "one value per file", so why are there multiple values here?

If you want to just use this for testing, and want to put whatever you want in the files, just use debugfs, that's what it is there for, not sysfs.

Debugfs doesn't allow me to attach attributes to a particular device which is what I want here.

Bart

Quoted 17 lines

drivers/misc/Kconfig config NSM · line 595

Quoted 8 lines
drivers/misc/Kconfig +8 -0
+config GPIO_VIRTUSER
+     tristate "GPIO Virtual User Testing Module"
+     select CONFIGFS_FS
+     select IRQ_WORK
+     help
+       This enables the configurable, configfs-based virtual GPIO consumer
+       testing driver.
+

module name?

And you need more documentation here, I have no idea what this means when it shows up in a Kconfig help entry :(

thanks,

greg k-h

#7 lore raw

Re: [PATCH v8 2/2] misc: gpio-virtuser: new virtual testing driver for the GPIO API

Quoted 30 lines · Bartosz Golaszewski
Quoted 28 lines · Greg Kroah-Hartman
Quoted 25 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

The GPIO subsystem used to have a serious problem with undefined behavior and use-after-free bugs on hot-unplug of GPIO chips. This can be considered a corner-case by some as most GPIO controllers are enabled early in the boot process and live until the system goes down but most GPIO drivers do allow unbind over sysfs, many are loadable modules that can be (force) unloaded and there are also GPIO devices that can be dynamically detached, for instance CP2112 which is a USB GPIO expender.

Bugs can be triggered both from user-space as well as by in-kernel users. We have the means of testing it from user-space via the character device but the issues manifest themselves differently in the kernel.

This is a proposition of adding a new virtual driver - a configurable GPIO consumer that can be configured over configfs (similarly to gpio-sim) or described on the device-tree.

This driver is aimed as a helper in spotting any regressions in hot-unplug handling in GPIOLIB.

---
 .../admin-guide/gpio/gpio-virtuser.rst        |  176 ++
 Documentation/admin-guide/gpio/index.rst      |    1 +
Quoted 6 lines
Quoted 3 lines

sysfs documentation needs to go in Documentation/ABI/ not in a random .rst file where the tools that check this will not catch it.

This is a testing driver, not representing real hardware. Do we hold such modules to the same standard?

Yes.

Quoted 11 lines
Quoted 7 lines
Quoted 4 lines
 MAINTAINERS                                   |    8 +
 drivers/misc/Kconfig                          |    8 +
 drivers/misc/Makefile                         |    1 +
 drivers/misc/gpio-virtuser.c                  | 1790 +++++++++++++++++

Why not put this in drivers/gpio/? Why misc?

Because it's quite... well "misc". It's not a GPIO chip provider (drivers/gpio/ is for GPIO providers), it's only a GPIO consumer. It also has an interface that doesn't fit any particular subsystem.

but it's gpio-specific, please put it there.

Quoted 7 lines
Quoted 7 lines

Documentation/admin-guide/gpio/gpio-virtuser.rst line 138

Quoted 4 lines
Documentation/admin-guide/gpio/gpio-virtuser.rst new file +4 -0
+Both attributes allow to read and set arrays of GPIO values. User must pass
+exactly the number of values that the array contains in the form of a string
+containing zeroes and ones representing inactive and active GPIO states
+respectively. In this example: ``echo 11 > values``.

sysfs is "one value per file", so why are there multiple values here?

Quoted 7 lines
Quoted 4 lines

If you want to just use this for testing, and want to put whatever you want in the files, just use debugfs, that's what it is there for, not sysfs.

Debugfs doesn't allow me to attach attributes to a particular device which is what I want here.

Yes it does, you just have to create the tree yourself. Many subsystems do this today just fine.

Please do not abuse sysfs for something that it is not designed for, please use debugfs, that is EXACTLY what it is designed for.

thanks,

greg k-h