* [PATCH v1 0/5] Input: gpio_decoder - update driver to use modern APIs
@ 2025-11-12 19:13 Andy Shevchenko
2025-11-12 19:13 ` [PATCH v1 1/5] Input: gpio_decoder - make use of device properties Andy Shevchenko
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: Andy Shevchenko @ 2025-11-12 19:13 UTC (permalink / raw)
To: Andy Shevchenko, linux-input, linux-kernel; +Cc: Dmitry Torokhov
Update gpio_decoder driver to use modern in-kernel APIs.
Andy Shevchenko (5):
Input: gpio_decoder - make use of device properties
Input: gpio_decoder - unify messages with help of dev_err_probe()
Input: gpio_decoder - replace custom loop by
gpiod_get_array_value_cansleep()
Input: gpio_decoder - make use of the macros from bits.h
Input: gpio_decoder - don't use "proxy" headers
drivers/input/misc/gpio_decoder.c | 72 ++++++++++++++-----------------
1 file changed, 33 insertions(+), 39 deletions(-)
--
2.50.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v1 1/5] Input: gpio_decoder - make use of device properties
2025-11-12 19:13 [PATCH v1 0/5] Input: gpio_decoder - update driver to use modern APIs Andy Shevchenko
@ 2025-11-12 19:13 ` Andy Shevchenko
2025-11-12 19:13 ` [PATCH v1 2/5] Input: gpio_decoder - unify messages with help of dev_err_probe() Andy Shevchenko
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2025-11-12 19:13 UTC (permalink / raw)
To: Andy Shevchenko, linux-input, linux-kernel; +Cc: Dmitry Torokhov
Convert the module to be property provider agnostic and allow
it to be used on non-OF platforms.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/input/misc/gpio_decoder.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/input/misc/gpio_decoder.c b/drivers/input/misc/gpio_decoder.c
index ee668eba302f..459abc749a49 100644
--- a/drivers/input/misc/gpio_decoder.c
+++ b/drivers/input/misc/gpio_decoder.c
@@ -10,9 +10,10 @@
#include <linux/gpio/consumer.h>
#include <linux/input.h>
#include <linux/kernel.h>
+#include <linux/mod_devicetable.h>
#include <linux/module.h>
-#include <linux/of.h>
#include <linux/platform_device.h>
+#include <linux/property.h>
struct gpio_decoder {
struct gpio_descs *input_gpios;
@@ -110,19 +111,17 @@ static int gpio_decoder_probe(struct platform_device *pdev)
return 0;
}
-#ifdef CONFIG_OF
static const struct of_device_id gpio_decoder_of_match[] = {
{ .compatible = "gpio-decoder", },
- { },
+ { }
};
MODULE_DEVICE_TABLE(of, gpio_decoder_of_match);
-#endif
static struct platform_driver gpio_decoder_driver = {
.probe = gpio_decoder_probe,
.driver = {
.name = "gpio-decoder",
- .of_match_table = of_match_ptr(gpio_decoder_of_match),
+ .of_match_table = gpio_decoder_of_match,
}
};
module_platform_driver(gpio_decoder_driver);
--
2.50.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v1 2/5] Input: gpio_decoder - unify messages with help of dev_err_probe()
2025-11-12 19:13 [PATCH v1 0/5] Input: gpio_decoder - update driver to use modern APIs Andy Shevchenko
2025-11-12 19:13 ` [PATCH v1 1/5] Input: gpio_decoder - make use of device properties Andy Shevchenko
@ 2025-11-12 19:13 ` Andy Shevchenko
2025-11-12 19:13 ` [PATCH v1 3/5] Input: gpio_decoder - replace custom loop by gpiod_get_array_value_cansleep() Andy Shevchenko
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2025-11-12 19:13 UTC (permalink / raw)
To: Andy Shevchenko, linux-input, linux-kernel; +Cc: Dmitry Torokhov
Unify error messages that might appear during probe phase by
switching to use dev_err_probe().
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/input/misc/gpio_decoder.c | 26 ++++++++++----------------
1 file changed, 10 insertions(+), 16 deletions(-)
diff --git a/drivers/input/misc/gpio_decoder.c b/drivers/input/misc/gpio_decoder.c
index 459abc749a49..a2ae400790f9 100644
--- a/drivers/input/misc/gpio_decoder.c
+++ b/drivers/input/misc/gpio_decoder.c
@@ -7,6 +7,7 @@
*/
#include <linux/device.h>
+#include <linux/err.h>
#include <linux/gpio/consumer.h>
#include <linux/input.h>
#include <linux/kernel.h>
@@ -73,15 +74,12 @@ static int gpio_decoder_probe(struct platform_device *pdev)
device_property_read_u32(dev, "linux,axis", &decoder->axis);
decoder->input_gpios = devm_gpiod_get_array(dev, NULL, GPIOD_IN);
- if (IS_ERR(decoder->input_gpios)) {
- dev_err(dev, "unable to acquire input gpios\n");
- return PTR_ERR(decoder->input_gpios);
- }
+ if (IS_ERR(decoder->input_gpios))
+ return dev_err_probe(dev, PTR_ERR(decoder->input_gpios),
+ "unable to acquire input gpios\n");
- if (decoder->input_gpios->ndescs < 2) {
- dev_err(dev, "not enough gpios found\n");
- return -EINVAL;
- }
+ if (decoder->input_gpios->ndescs < 2)
+ return dev_err_probe(dev, -EINVAL, "not enough gpios found\n");
if (device_property_read_u32(dev, "decoder-max-value", &max))
max = (1U << decoder->input_gpios->ndescs) - 1;
@@ -97,16 +95,12 @@ static int gpio_decoder_probe(struct platform_device *pdev)
input_set_abs_params(input, decoder->axis, 0, max, 0, 0);
err = input_setup_polling(input, gpio_decoder_poll_gpios);
- if (err) {
- dev_err(dev, "failed to set up polling\n");
- return err;
- }
+ if (err)
+ return dev_err_probe(dev, err, "failed to set up polling\n");
err = input_register_device(input);
- if (err) {
- dev_err(dev, "failed to register input device\n");
- return err;
- }
+ if (err)
+ return dev_err_probe(dev, err, "failed to register input device\n");
return 0;
}
--
2.50.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v1 3/5] Input: gpio_decoder - replace custom loop by gpiod_get_array_value_cansleep()
2025-11-12 19:13 [PATCH v1 0/5] Input: gpio_decoder - update driver to use modern APIs Andy Shevchenko
2025-11-12 19:13 ` [PATCH v1 1/5] Input: gpio_decoder - make use of device properties Andy Shevchenko
2025-11-12 19:13 ` [PATCH v1 2/5] Input: gpio_decoder - unify messages with help of dev_err_probe() Andy Shevchenko
@ 2025-11-12 19:13 ` Andy Shevchenko
2025-11-13 10:47 ` kernel test robot
2025-11-13 12:15 ` kernel test robot
2025-11-12 19:13 ` [PATCH v1 4/5] Input: gpio_decoder - make use of the macros from bits.h Andy Shevchenko
2025-11-12 19:13 ` [PATCH v1 5/5] Input: gpio_decoder - don't use "proxy" headers Andy Shevchenko
4 siblings, 2 replies; 8+ messages in thread
From: Andy Shevchenko @ 2025-11-12 19:13 UTC (permalink / raw)
To: Andy Shevchenko, linux-input, linux-kernel; +Cc: Dmitry Torokhov
There is a custom loop that repeats parts of gpiod_get_array_value_cansleep().
Use that in conjunction with bitmap API to make code shorter and easier to
follow.
With this done, add an upper check for amount of GPIOs given based on
the driver's code.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/input/misc/gpio_decoder.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/drivers/input/misc/gpio_decoder.c b/drivers/input/misc/gpio_decoder.c
index a2ae400790f9..8c07f7ff66e5 100644
--- a/drivers/input/misc/gpio_decoder.c
+++ b/drivers/input/misc/gpio_decoder.c
@@ -6,11 +6,13 @@
* encoded numeric value into an input event.
*/
+#include <linux/bitmap.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/gpio/consumer.h>
#include <linux/input.h>
#include <linux/kernel.h>
+#include <linux/minmax.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/platform_device.h>
@@ -26,23 +28,18 @@ struct gpio_decoder {
static int gpio_decoder_get_gpios_state(struct gpio_decoder *decoder)
{
struct gpio_descs *gpios = decoder->input_gpios;
- unsigned int ret = 0;
- int i, val;
+ DECLARE_BITMAP(values, 32);
+ unsigned int size;
+ int err;
- for (i = 0; i < gpios->ndescs; i++) {
- val = gpiod_get_value_cansleep(gpios->desc[i]);
- if (val < 0) {
- dev_err(decoder->dev,
- "Error reading gpio %d: %d\n",
- desc_to_gpio(gpios->desc[i]), val);
- return val;
- }
-
- val = !!val;
- ret = (ret << 1) | val;
+ size = min(gpios->ndescs, 32U);
+ err = gpiod_get_array_value_cansleep(size, gpios->desc, gpios->info, values);
+ if (err) {
+ dev_err(decoder->dev, "Error reading GPIO: %d\n", val);
+ return err;
}
- return ret;
+ return bitmap_read(values, 0, size);
}
static void gpio_decoder_poll_gpios(struct input_dev *input)
@@ -81,6 +78,9 @@ static int gpio_decoder_probe(struct platform_device *pdev)
if (decoder->input_gpios->ndescs < 2)
return dev_err_probe(dev, -EINVAL, "not enough gpios found\n");
+ if (decoder->input_gpios->ndescs > 31)
+ return dev_err_probe(dev, -EINVAL, "too many gpios found\n");
+
if (device_property_read_u32(dev, "decoder-max-value", &max))
max = (1U << decoder->input_gpios->ndescs) - 1;
--
2.50.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v1 4/5] Input: gpio_decoder - make use of the macros from bits.h
2025-11-12 19:13 [PATCH v1 0/5] Input: gpio_decoder - update driver to use modern APIs Andy Shevchenko
` (2 preceding siblings ...)
2025-11-12 19:13 ` [PATCH v1 3/5] Input: gpio_decoder - replace custom loop by gpiod_get_array_value_cansleep() Andy Shevchenko
@ 2025-11-12 19:13 ` Andy Shevchenko
2025-11-12 19:13 ` [PATCH v1 5/5] Input: gpio_decoder - don't use "proxy" headers Andy Shevchenko
4 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2025-11-12 19:13 UTC (permalink / raw)
To: Andy Shevchenko, linux-input, linux-kernel; +Cc: Dmitry Torokhov
Make use of BIT() where it makes sense.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/input/misc/gpio_decoder.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/input/misc/gpio_decoder.c b/drivers/input/misc/gpio_decoder.c
index 8c07f7ff66e5..299f16d3bf4d 100644
--- a/drivers/input/misc/gpio_decoder.c
+++ b/drivers/input/misc/gpio_decoder.c
@@ -60,7 +60,7 @@ static int gpio_decoder_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev;
struct gpio_decoder *decoder;
struct input_dev *input;
- u32 max;
+ u32 max;
int err;
decoder = devm_kzalloc(dev, sizeof(*decoder), GFP_KERNEL);
@@ -82,7 +82,7 @@ static int gpio_decoder_probe(struct platform_device *pdev)
return dev_err_probe(dev, -EINVAL, "too many gpios found\n");
if (device_property_read_u32(dev, "decoder-max-value", &max))
- max = (1U << decoder->input_gpios->ndescs) - 1;
+ max = BIT(decoder->input_gpios->ndescs) - 1;
input = devm_input_allocate_device(dev);
if (!input)
--
2.50.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v1 5/5] Input: gpio_decoder - don't use "proxy" headers
2025-11-12 19:13 [PATCH v1 0/5] Input: gpio_decoder - update driver to use modern APIs Andy Shevchenko
` (3 preceding siblings ...)
2025-11-12 19:13 ` [PATCH v1 4/5] Input: gpio_decoder - make use of the macros from bits.h Andy Shevchenko
@ 2025-11-12 19:13 ` Andy Shevchenko
4 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2025-11-12 19:13 UTC (permalink / raw)
To: Andy Shevchenko, linux-input, linux-kernel; +Cc: Dmitry Torokhov
Update header inclusions to follow IWYU (Include What You Use)
principle.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/input/misc/gpio_decoder.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/input/misc/gpio_decoder.c b/drivers/input/misc/gpio_decoder.c
index 299f16d3bf4d..5fe56ae58183 100644
--- a/drivers/input/misc/gpio_decoder.c
+++ b/drivers/input/misc/gpio_decoder.c
@@ -7,16 +7,17 @@
*/
#include <linux/bitmap.h>
-#include <linux/device.h>
+#include <linux/dev_printk.h>
+#include <linux/device/devres.h>
#include <linux/err.h>
#include <linux/gpio/consumer.h>
#include <linux/input.h>
-#include <linux/kernel.h>
#include <linux/minmax.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/property.h>
+#include <linux/types.h>
struct gpio_decoder {
struct gpio_descs *input_gpios;
--
2.50.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v1 3/5] Input: gpio_decoder - replace custom loop by gpiod_get_array_value_cansleep()
2025-11-12 19:13 ` [PATCH v1 3/5] Input: gpio_decoder - replace custom loop by gpiod_get_array_value_cansleep() Andy Shevchenko
@ 2025-11-13 10:47 ` kernel test robot
2025-11-13 12:15 ` kernel test robot
1 sibling, 0 replies; 8+ messages in thread
From: kernel test robot @ 2025-11-13 10:47 UTC (permalink / raw)
To: Andy Shevchenko, linux-input, linux-kernel; +Cc: oe-kbuild-all, Dmitry Torokhov
Hi Andy,
kernel test robot noticed the following build errors:
[auto build test ERROR on dtor-input/next]
[also build test ERROR on dtor-input/for-linus hid/for-next linus/master v6.18-rc5 next-20251113]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/Input-gpio_decoder-make-use-of-device-properties/20251113-032111
base: https://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git next
patch link: https://lore.kernel.org/r/20251112191412.2088105-4-andriy.shevchenko%40linux.intel.com
patch subject: [PATCH v1 3/5] Input: gpio_decoder - replace custom loop by gpiod_get_array_value_cansleep()
config: x86_64-buildonly-randconfig-004-20251113 (https://download.01.org/0day-ci/archive/20251113/202511131832.JljMfKrW-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251113/202511131832.JljMfKrW-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202511131832.JljMfKrW-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from include/linux/device.h:15,
from drivers/input/misc/gpio_decoder.c:10:
drivers/input/misc/gpio_decoder.c: In function 'gpio_decoder_get_gpios_state':
>> drivers/input/misc/gpio_decoder.c:38:67: error: 'val' undeclared (first use in this function)
38 | dev_err(decoder->dev, "Error reading GPIO: %d\n", val);
| ^~~
include/linux/dev_printk.h:110:37: note: in definition of macro 'dev_printk_index_wrap'
110 | _p_func(dev, fmt, ##__VA_ARGS__); \
| ^~~~~~~~~~~
drivers/input/misc/gpio_decoder.c:38:17: note: in expansion of macro 'dev_err'
38 | dev_err(decoder->dev, "Error reading GPIO: %d\n", val);
| ^~~~~~~
drivers/input/misc/gpio_decoder.c:38:67: note: each undeclared identifier is reported only once for each function it appears in
38 | dev_err(decoder->dev, "Error reading GPIO: %d\n", val);
| ^~~
include/linux/dev_printk.h:110:37: note: in definition of macro 'dev_printk_index_wrap'
110 | _p_func(dev, fmt, ##__VA_ARGS__); \
| ^~~~~~~~~~~
drivers/input/misc/gpio_decoder.c:38:17: note: in expansion of macro 'dev_err'
38 | dev_err(decoder->dev, "Error reading GPIO: %d\n", val);
| ^~~~~~~
vim +/val +38 drivers/input/misc/gpio_decoder.c
27
28 static int gpio_decoder_get_gpios_state(struct gpio_decoder *decoder)
29 {
30 struct gpio_descs *gpios = decoder->input_gpios;
31 DECLARE_BITMAP(values, 32);
32 unsigned int size;
33 int err;
34
35 size = min(gpios->ndescs, 32U);
36 err = gpiod_get_array_value_cansleep(size, gpios->desc, gpios->info, values);
37 if (err) {
> 38 dev_err(decoder->dev, "Error reading GPIO: %d\n", val);
39 return err;
40 }
41
42 return bitmap_read(values, 0, size);
43 }
44
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v1 3/5] Input: gpio_decoder - replace custom loop by gpiod_get_array_value_cansleep()
2025-11-12 19:13 ` [PATCH v1 3/5] Input: gpio_decoder - replace custom loop by gpiod_get_array_value_cansleep() Andy Shevchenko
2025-11-13 10:47 ` kernel test robot
@ 2025-11-13 12:15 ` kernel test robot
1 sibling, 0 replies; 8+ messages in thread
From: kernel test robot @ 2025-11-13 12:15 UTC (permalink / raw)
To: Andy Shevchenko, linux-input, linux-kernel
Cc: llvm, oe-kbuild-all, Dmitry Torokhov
Hi Andy,
kernel test robot noticed the following build errors:
[auto build test ERROR on dtor-input/next]
[also build test ERROR on dtor-input/for-linus hid/for-next linus/master v6.18-rc5 next-20251113]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/Input-gpio_decoder-make-use-of-device-properties/20251113-032111
base: https://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git next
patch link: https://lore.kernel.org/r/20251112191412.2088105-4-andriy.shevchenko%40linux.intel.com
patch subject: [PATCH v1 3/5] Input: gpio_decoder - replace custom loop by gpiod_get_array_value_cansleep()
config: x86_64-buildonly-randconfig-002-20251113 (https://download.01.org/0day-ci/archive/20251113/202511131958.6ItfY60O-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251113/202511131958.6ItfY60O-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202511131958.6ItfY60O-lkp@intel.com/
All errors (new ones prefixed by >>):
>> drivers/input/misc/gpio_decoder.c:38:53: error: use of undeclared identifier 'val'
38 | dev_err(decoder->dev, "Error reading GPIO: %d\n", val);
| ^
1 error generated.
vim +/val +38 drivers/input/misc/gpio_decoder.c
27
28 static int gpio_decoder_get_gpios_state(struct gpio_decoder *decoder)
29 {
30 struct gpio_descs *gpios = decoder->input_gpios;
31 DECLARE_BITMAP(values, 32);
32 unsigned int size;
33 int err;
34
35 size = min(gpios->ndescs, 32U);
36 err = gpiod_get_array_value_cansleep(size, gpios->desc, gpios->info, values);
37 if (err) {
> 38 dev_err(decoder->dev, "Error reading GPIO: %d\n", val);
39 return err;
40 }
41
42 return bitmap_read(values, 0, size);
43 }
44
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-11-13 12:16 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-12 19:13 [PATCH v1 0/5] Input: gpio_decoder - update driver to use modern APIs Andy Shevchenko
2025-11-12 19:13 ` [PATCH v1 1/5] Input: gpio_decoder - make use of device properties Andy Shevchenko
2025-11-12 19:13 ` [PATCH v1 2/5] Input: gpio_decoder - unify messages with help of dev_err_probe() Andy Shevchenko
2025-11-12 19:13 ` [PATCH v1 3/5] Input: gpio_decoder - replace custom loop by gpiod_get_array_value_cansleep() Andy Shevchenko
2025-11-13 10:47 ` kernel test robot
2025-11-13 12:15 ` kernel test robot
2025-11-12 19:13 ` [PATCH v1 4/5] Input: gpio_decoder - make use of the macros from bits.h Andy Shevchenko
2025-11-12 19:13 ` [PATCH v1 5/5] Input: gpio_decoder - don't use "proxy" headers Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).