mbox series

[v2,0/3] Add synchronous fake device creation utility for GPIO drivers

Message ID 20250218160333.605829-1-koichiro.den@canonical.com
Headers show
Series Add synchronous fake device creation utility for GPIO drivers | expand

Message

Koichiro Den Feb. 18, 2025, 4:03 p.m. UTC
This patch series introduces a utility for some GPIO devices to reduce
code duplication. There are no functional changes.

In this series, only gpio-sim and gpio-virtuser are updated to use
dev-sync-probe, as the current gpio-aggregator does not benefit from it at
all. A follow-up patch series that introduces a configfs interface for
gpio-aggregator will convert it to use dev-sync-probe as well.

This work originated from a suggestion by Bartosz:
https://lore.kernel.org/all/CAMRc=MfcooZXBqVpbQ0ak+8LGsPDzwKSN3Zfb0eZDx1Bx4duzQ@mail.gmail.com/

N.B. this submission is based on the latest gpio/for-next as of writing:
f04867a5d0d3 ("gpio: loongson-64bit: Remove unneeded ngpio assignment").


v1->v2 changes:
  - Renamed the files (gpio-pseudo.[ch] -> dev-sync-probe.[ch]).
  - Renamed the helper functions and a struct.
  - Fixed Kconfig (correcting bool to tristate, etc.).
  - Fixed Copyright.
  - Added some missing #include.

v1: https://lore.kernel.org/all/20250217142758.540601-1-koichiro.den@canonical.com/


Koichiro Den (3):
  gpio: introduce utilities for synchronous fake device creation
  gpio: sim: convert to use dev-sync-probe utilities
  gpio: virtuser: convert to use dev-sync-probe utilities

 drivers/gpio/Kconfig          | 10 ++++
 drivers/gpio/Makefile         |  3 ++
 drivers/gpio/dev-sync-probe.c | 96 +++++++++++++++++++++++++++++++++++
 drivers/gpio/dev-sync-probe.h | 25 +++++++++
 drivers/gpio/gpio-sim.c       | 84 +++++-------------------------
 drivers/gpio/gpio-virtuser.c  | 73 ++++----------------------
 6 files changed, 156 insertions(+), 135 deletions(-)
 create mode 100644 drivers/gpio/dev-sync-probe.c
 create mode 100644 drivers/gpio/dev-sync-probe.h

Comments

Bartosz Golaszewski Feb. 20, 2025, 11:08 a.m. UTC | #1
On Tue, Feb 18, 2025 at 5:04 PM Koichiro Den <koichiro.den@canonical.com> wrote:
>
> Update gpio-sim to use the new dev-sync-probe helper functions for
> synchronized platform device creation, reducing code duplication.
>
> No functional change.
>
> Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
> ---
>  drivers/gpio/Kconfig    |  2 +
>  drivers/gpio/gpio-sim.c | 84 ++++++-----------------------------------
>  2 files changed, 14 insertions(+), 72 deletions(-)
>
> diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
> index 2e4c5f0a94f7..ba06f052b9ea 100644
> --- a/drivers/gpio/Kconfig
> +++ b/drivers/gpio/Kconfig
> @@ -1866,6 +1866,7 @@ endmenu
>  # This symbol is selected by drivers that need synchronous fake device creation
>  config DEV_SYNC_PROBE
>         tristate "Utilities for synchronous fake device creation"
> +       depends on GPIO_SIM

No, it does not. Please drop this.

>         help
>           Common helper functions for drivers that need synchronous fake
>           device creation.
> @@ -1916,6 +1917,7 @@ config GPIO_SIM
>         tristate "GPIO Simulator Module"
>         select IRQ_SIM
>         select CONFIGFS_FS
> +       select DEV_SYNC_PROBE
>         help
>           This enables the GPIO simulator - a configfs-based GPIO testing
>           driver.
> diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
> index a086087ada17..d1cdea450937 100644
> --- a/drivers/gpio/gpio-sim.c
> +++ b/drivers/gpio/gpio-sim.c
> @@ -10,7 +10,6 @@
>  #include <linux/array_size.h>
>  #include <linux/bitmap.h>
>  #include <linux/cleanup.h>
> -#include <linux/completion.h>
>  #include <linux/configfs.h>
>  #include <linux/device.h>
>  #include <linux/err.h>
> @@ -37,6 +36,8 @@
>  #include <linux/sysfs.h>
>  #include <linux/types.h>
>
> +#include "dev-sync-probe.h"
> +
>  #define GPIO_SIM_NGPIO_MAX     1024
>  #define GPIO_SIM_PROP_MAX      4 /* Max 3 properties + sentinel. */
>  #define GPIO_SIM_NUM_ATTRS     3 /* value, pull and sentinel */
> @@ -541,14 +542,9 @@ static struct platform_driver gpio_sim_driver = {
>  };
>
>  struct gpio_sim_device {
> +       struct dev_sync_probe_data data;

Maybe something more indicative of the purpose? probe_data? sync_probe_data?

Bart
Koichiro Den Feb. 20, 2025, 1:09 p.m. UTC | #2
On Thu, Feb 20, 2025 at 12:08:18PM GMT, Bartosz Golaszewski wrote:
> On Tue, Feb 18, 2025 at 5:04 PM Koichiro Den <koichiro.den@canonical.com> wrote:
> >
> > Update gpio-sim to use the new dev-sync-probe helper functions for
> > synchronized platform device creation, reducing code duplication.
> >
> > No functional change.
> >
> > Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
> > ---
> >  drivers/gpio/Kconfig    |  2 +
> >  drivers/gpio/gpio-sim.c | 84 ++++++-----------------------------------
> >  2 files changed, 14 insertions(+), 72 deletions(-)
> >
> > diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
> > index 2e4c5f0a94f7..ba06f052b9ea 100644
> > --- a/drivers/gpio/Kconfig
> > +++ b/drivers/gpio/Kconfig
> > @@ -1866,6 +1866,7 @@ endmenu
> >  # This symbol is selected by drivers that need synchronous fake device creation
> >  config DEV_SYNC_PROBE
> >         tristate "Utilities for synchronous fake device creation"
> > +       depends on GPIO_SIM
> 
> No, it does not. Please drop this.

I'll hide the config as you pointed out, and drop this while at it. Thanks.

> 
> >         help
> >           Common helper functions for drivers that need synchronous fake
> >           device creation.
> > @@ -1916,6 +1917,7 @@ config GPIO_SIM
> >         tristate "GPIO Simulator Module"
> >         select IRQ_SIM
> >         select CONFIGFS_FS
> > +       select DEV_SYNC_PROBE
> >         help
> >           This enables the GPIO simulator - a configfs-based GPIO testing
> >           driver.
> > diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
> > index a086087ada17..d1cdea450937 100644
> > --- a/drivers/gpio/gpio-sim.c
> > +++ b/drivers/gpio/gpio-sim.c
> > @@ -10,7 +10,6 @@
> >  #include <linux/array_size.h>
> >  #include <linux/bitmap.h>
> >  #include <linux/cleanup.h>
> > -#include <linux/completion.h>
> >  #include <linux/configfs.h>
> >  #include <linux/device.h>
> >  #include <linux/err.h>
> > @@ -37,6 +36,8 @@
> >  #include <linux/sysfs.h>
> >  #include <linux/types.h>
> >
> > +#include "dev-sync-probe.h"
> > +
> >  #define GPIO_SIM_NGPIO_MAX     1024
> >  #define GPIO_SIM_PROP_MAX      4 /* Max 3 properties + sentinel. */
> >  #define GPIO_SIM_NUM_ATTRS     3 /* value, pull and sentinel */
> > @@ -541,14 +542,9 @@ static struct platform_driver gpio_sim_driver = {
> >  };
> >
> >  struct gpio_sim_device {
> > +       struct dev_sync_probe_data data;
> 
> Maybe something more indicative of the purpose? probe_data? sync_probe_data?

Hm, right. I'll go with probe_data. Thanks!

> 
> Bart