* [PATCH] input: misc: soc_button_array: use platform_device_register_resndata()
@ 2019-07-29 14:26 Enrico Weigelt, metux IT consult
2019-07-29 17:23 ` Dmitry Torokhov
0 siblings, 1 reply; 3+ messages in thread
From: Enrico Weigelt, metux IT consult @ 2019-07-29 14:26 UTC (permalink / raw)
To: linux-kernel; +Cc: dmitry.torokhov, linux-input
From: Enrico Weigelt <info@metux.net>
The registration of gpio-keys device can be written much shorter
by using the platform_device_register_resndata() helper.
Signed-off-by: Enrico Weigelt <info@metux.net>
---
drivers/input/misc/soc_button_array.c | 24 ++++++++++--------------
1 file changed, 10 insertions(+), 14 deletions(-)
diff --git a/drivers/input/misc/soc_button_array.c b/drivers/input/misc/soc_button_array.c
index 5e59f8e5..f5e148b 100644
--- a/drivers/input/misc/soc_button_array.c
+++ b/drivers/input/misc/soc_button_array.c
@@ -110,25 +110,21 @@ static int soc_button_lookup_gpio(struct device *dev, int acpi_index)
gpio_keys_pdata->nbuttons = n_buttons;
gpio_keys_pdata->rep = autorepeat;
- pd = platform_device_alloc("gpio-keys", PLATFORM_DEVID_AUTO);
- if (!pd) {
- error = -ENOMEM;
+ pd = platform_device_register_resndata(NULL,
+ "gpio-keys",
+ PLATFORM_DEVID_AUTO,
+ NULL,
+ 0,
+ gpio_keys_pdata,
+ sizeof(*gpio_keys_pdata));
+
+ if (IS_ERR(pd)) {
+ dev_err(&pdev->dev, "failed registering gpio-keys: %ld\n", PTR_ERR(pd));
goto err_free_mem;
}
- error = platform_device_add_data(pd, gpio_keys_pdata,
- sizeof(*gpio_keys_pdata));
- if (error)
- goto err_free_pdev;
-
- error = platform_device_add(pd);
- if (error)
- goto err_free_pdev;
-
return pd;
-err_free_pdev:
- platform_device_put(pd);
err_free_mem:
devm_kfree(&pdev->dev, gpio_keys_pdata);
return ERR_PTR(error);
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] input: misc: soc_button_array: use platform_device_register_resndata()
2019-07-29 14:26 [PATCH] input: misc: soc_button_array: use platform_device_register_resndata() Enrico Weigelt, metux IT consult
@ 2019-07-29 17:23 ` Dmitry Torokhov
2019-08-20 11:16 ` Enrico Weigelt, metux IT consult
0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Torokhov @ 2019-07-29 17:23 UTC (permalink / raw)
To: Enrico Weigelt, metux IT consult; +Cc: linux-kernel, linux-input
On Mon, Jul 29, 2019 at 04:26:12PM +0200, Enrico Weigelt, metux IT consult wrote:
> From: Enrico Weigelt <info@metux.net>
>
> The registration of gpio-keys device can be written much shorter
> by using the platform_device_register_resndata() helper.
>
> Signed-off-by: Enrico Weigelt <info@metux.net>
> ---
> drivers/input/misc/soc_button_array.c | 24 ++++++++++--------------
> 1 file changed, 10 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/input/misc/soc_button_array.c b/drivers/input/misc/soc_button_array.c
> index 5e59f8e5..f5e148b 100644
> --- a/drivers/input/misc/soc_button_array.c
> +++ b/drivers/input/misc/soc_button_array.c
> @@ -110,25 +110,21 @@ static int soc_button_lookup_gpio(struct device *dev, int acpi_index)
> gpio_keys_pdata->nbuttons = n_buttons;
> gpio_keys_pdata->rep = autorepeat;
>
> - pd = platform_device_alloc("gpio-keys", PLATFORM_DEVID_AUTO);
> - if (!pd) {
> - error = -ENOMEM;
> + pd = platform_device_register_resndata(NULL,
I wonder if we should pass &pdev->dev instead of NULL here to form
proper device hierarchy, now that we have this option.
> + "gpio-keys",
> + PLATFORM_DEVID_AUTO,
> + NULL,
> + 0,
> + gpio_keys_pdata,
> + sizeof(*gpio_keys_pdata));
> +
> + if (IS_ERR(pd)) {
> + dev_err(&pdev->dev, "failed registering gpio-keys: %ld\n", PTR_ERR(pd));
> goto err_free_mem;
Since you did not assign 'error' value here this goto will result in the
function returning 0 even if platform_device_register_resndata() failed.
I'd doing:
pd = platform_device_register_resndata(NULL, ...);
error = PTR_ERR_OR_ZERO(pd);
if (error) {
dev_err(...);
goto err_free_mem;
}
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] input: misc: soc_button_array: use platform_device_register_resndata()
2019-07-29 17:23 ` Dmitry Torokhov
@ 2019-08-20 11:16 ` Enrico Weigelt, metux IT consult
0 siblings, 0 replies; 3+ messages in thread
From: Enrico Weigelt, metux IT consult @ 2019-08-20 11:16 UTC (permalink / raw)
To: Dmitry Torokhov, Enrico Weigelt, metux IT consult
Cc: linux-kernel, linux-input
On 29.07.19 19:23, Dmitry Torokhov wrote:
Hi,
> I wonder if we should pass &pdev->dev instead of NULL here to form
> proper device hierarchy, now that we have this option.
good point, thanks, fixed in v2.
>> + "gpio-keys",
>> + PLATFORM_DEVID_AUTO,
>> + NULL,
>> + 0,
>> + gpio_keys_pdata,
>> + sizeof(*gpio_keys_pdata));
>> +
>> + if (IS_ERR(pd)) {
>> + dev_err(&pdev->dev, "failed registering gpio-keys: %ld\n", PTR_ERR(pd));
>> goto err_free_mem;
>
> Since you did not assign 'error' value here this goto will result in the
> function returning 0 even if platform_device_register_resndata() failed.
Uh, thanks. IMHO it's even worse: 'error' could be uninitialized.
I'm sending v2 separately.
Thanks for your review.
--mtx
--
Enrico Weigelt, metux IT consult
Free software and Linux embedded engineering
info@metux.net -- +49-151-27565287
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-08-20 11:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-29 14:26 [PATCH] input: misc: soc_button_array: use platform_device_register_resndata() Enrico Weigelt, metux IT consult
2019-07-29 17:23 ` Dmitry Torokhov
2019-08-20 11:16 ` Enrico Weigelt, metux IT consult
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).