Re: [PATCH 4/4] Input: omap4-keypad - simplify probe with devm
* Dmitry Torokhov [210110 06:31]: > I do not quite like that we need to keep this in remove(). I had the > patch below for quite some time, could you please try it? Yes seems to work nice :) > Input: omap4-keypad - switch to use managed resources > > From: Dmitry Torokhov > > Now that input core supports devres-managed input devices we can clean > up this driver a bit. > > Signed-off-by: Dmitry Torokhov Tested-by: Tony Lindgren > --- > drivers/input/keyboard/omap4-keypad.c | 139 > + > 1 file changed, 55 insertions(+), 84 deletions(-) > > diff --git a/drivers/input/keyboard/omap4-keypad.c > b/drivers/input/keyboard/omap4-keypad.c > index b17ac2a295b9..d36774a55a10 100644 > --- a/drivers/input/keyboard/omap4-keypad.c > +++ b/drivers/input/keyboard/omap4-keypad.c > @@ -252,8 +252,14 @@ static int omap4_keypad_check_revision(struct device > *dev, > return 0; > } > > +static void omap4_disable_pm(void *d) > +{ > + pm_runtime_disable(d); > +} > + > static int omap4_keypad_probe(struct platform_device *pdev) > { > + struct device *dev = >dev; > struct omap4_keypad *keypad_data; > struct input_dev *input_dev; > struct resource *res; > @@ -271,33 +277,30 @@ static int omap4_keypad_probe(struct platform_device > *pdev) > if (irq < 0) > return irq; > > - keypad_data = kzalloc(sizeof(struct omap4_keypad), GFP_KERNEL); > + keypad_data = devm_kzalloc(dev, sizeof(struct omap4_keypad), > +GFP_KERNEL); > if (!keypad_data) { > - dev_err(>dev, "keypad_data memory allocation failed\n"); > + dev_err(dev, "keypad_data memory allocation failed\n"); > return -ENOMEM; > } > > keypad_data->irq = irq; > > - error = omap4_keypad_parse_dt(>dev, keypad_data); > + error = omap4_keypad_parse_dt(dev, keypad_data); > if (error) > - goto err_free_keypad; > + return error; > > - res = request_mem_region(res->start, resource_size(res), pdev->name); > - if (!res) { > - dev_err(>dev, "can't request mem region\n"); > - error = -EBUSY; > - goto err_free_keypad; > - } > + keypad_data->base = devm_ioremap_resource(dev, res); > + if (IS_ERR(keypad_data->base)) > + return PTR_ERR(keypad_data->base); > > - keypad_data->base = ioremap(res->start, resource_size(res)); > - if (!keypad_data->base) { > - dev_err(>dev, "can't ioremap mem resource\n"); > - error = -ENOMEM; > - goto err_release_mem; > - } > + pm_runtime_enable(dev); > > - pm_runtime_enable(>dev); > + error = devm_add_action_or_reset(dev, omap4_disable_pm, dev); > + if (error) { > + dev_err(dev, "unable to register cleanup action\n"); > + return error; > + } > > /* >* Enable clocks for the keypad module so that we can read > @@ -307,27 +310,26 @@ static int omap4_keypad_probe(struct platform_device > *pdev) > if (error) { > dev_err(>dev, "pm_runtime_get_sync() failed\n"); > pm_runtime_put_noidle(>dev); > - } else { > - error = omap4_keypad_check_revision(>dev, > - keypad_data); > - if (!error) { > - /* Ensure device does not raise interrupts */ > - omap4_keypad_stop(keypad_data); > - } > - pm_runtime_put_sync(>dev); > + return error; > + } > + > + error = omap4_keypad_check_revision(>dev, > + keypad_data); > + if (!error) { > + /* Ensure device does not raise interrupts */ > + omap4_keypad_stop(keypad_data); > } > + > + pm_runtime_put_sync(>dev); > if (error) > - goto err_pm_disable; > + return error; > > /* input device allocation */ > - keypad_data->input = input_dev = input_allocate_device(); > - if (!input_dev) { > - error = -ENOMEM; > - goto err_pm_disable; > - } > + keypad_data->input = input_dev = devm_input_allocate_device(dev); > + if (!input_dev) > + return -ENOMEM; > > input_dev->name = pdev->name; > - input_dev->dev.parent = >dev; > input_dev->id.bustype = BUS_HOST; > input_dev->id.vendor = 0x0001; > input_dev->id.product = 0x0001; > @@ -344,84 +346,53 @@ static int omap4_keypad_probe(struct platform_device > *pdev) > > keypad_data->row_shift = get_count_order(keypad_data->cols); > max_keys = keypad_data->rows << keypad_data->row_shift; > - keypad_data->keymap = kcalloc(max_keys, > - sizeof(keypad_data->keymap[0]), > - GFP_KERNEL); > + keypad_data->keymap = devm_kcalloc(dev, > +
Re: [PATCH 4/4] Input: omap4-keypad - simplify probe with devm
Hi Tony, On Wed, Jan 06, 2021 at 02:58:22PM +0200, Tony Lindgren wrote: > static int omap4_keypad_remove(struct platform_device *pdev) > { > struct omap4_keypad *keypad_data = platform_get_drvdata(pdev); > - struct resource *res; > > dev_pm_clear_wake_irq(>dev); > - > - free_irq(keypad_data->irq, keypad_data); > - > pm_runtime_dont_use_autosuspend(>dev); > pm_runtime_disable(>dev); I do not quite like that we need to keep this in remove(). I had the patch below for quite some time, could you please try it? Thanks! -- Dmitry Input: omap4-keypad - switch to use managed resources From: Dmitry Torokhov Now that input core supports devres-managed input devices we can clean up this driver a bit. Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/omap4-keypad.c | 139 + 1 file changed, 55 insertions(+), 84 deletions(-) diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c index b17ac2a295b9..d36774a55a10 100644 --- a/drivers/input/keyboard/omap4-keypad.c +++ b/drivers/input/keyboard/omap4-keypad.c @@ -252,8 +252,14 @@ static int omap4_keypad_check_revision(struct device *dev, return 0; } +static void omap4_disable_pm(void *d) +{ + pm_runtime_disable(d); +} + static int omap4_keypad_probe(struct platform_device *pdev) { + struct device *dev = >dev; struct omap4_keypad *keypad_data; struct input_dev *input_dev; struct resource *res; @@ -271,33 +277,30 @@ static int omap4_keypad_probe(struct platform_device *pdev) if (irq < 0) return irq; - keypad_data = kzalloc(sizeof(struct omap4_keypad), GFP_KERNEL); + keypad_data = devm_kzalloc(dev, sizeof(struct omap4_keypad), + GFP_KERNEL); if (!keypad_data) { - dev_err(>dev, "keypad_data memory allocation failed\n"); + dev_err(dev, "keypad_data memory allocation failed\n"); return -ENOMEM; } keypad_data->irq = irq; - error = omap4_keypad_parse_dt(>dev, keypad_data); + error = omap4_keypad_parse_dt(dev, keypad_data); if (error) - goto err_free_keypad; + return error; - res = request_mem_region(res->start, resource_size(res), pdev->name); - if (!res) { - dev_err(>dev, "can't request mem region\n"); - error = -EBUSY; - goto err_free_keypad; - } + keypad_data->base = devm_ioremap_resource(dev, res); + if (IS_ERR(keypad_data->base)) + return PTR_ERR(keypad_data->base); - keypad_data->base = ioremap(res->start, resource_size(res)); - if (!keypad_data->base) { - dev_err(>dev, "can't ioremap mem resource\n"); - error = -ENOMEM; - goto err_release_mem; - } + pm_runtime_enable(dev); - pm_runtime_enable(>dev); + error = devm_add_action_or_reset(dev, omap4_disable_pm, dev); + if (error) { + dev_err(dev, "unable to register cleanup action\n"); + return error; + } /* * Enable clocks for the keypad module so that we can read @@ -307,27 +310,26 @@ static int omap4_keypad_probe(struct platform_device *pdev) if (error) { dev_err(>dev, "pm_runtime_get_sync() failed\n"); pm_runtime_put_noidle(>dev); - } else { - error = omap4_keypad_check_revision(>dev, - keypad_data); - if (!error) { - /* Ensure device does not raise interrupts */ - omap4_keypad_stop(keypad_data); - } - pm_runtime_put_sync(>dev); + return error; + } + + error = omap4_keypad_check_revision(>dev, + keypad_data); + if (!error) { + /* Ensure device does not raise interrupts */ + omap4_keypad_stop(keypad_data); } + + pm_runtime_put_sync(>dev); if (error) - goto err_pm_disable; + return error; /* input device allocation */ - keypad_data->input = input_dev = input_allocate_device(); - if (!input_dev) { - error = -ENOMEM; - goto err_pm_disable; - } + keypad_data->input = input_dev = devm_input_allocate_device(dev); + if (!input_dev) + return -ENOMEM; input_dev->name = pdev->name; - input_dev->dev.parent = >dev; input_dev->id.bustype = BUS_HOST; input_dev->id.vendor = 0x0001; input_dev->id.product = 0x0001; @@ -344,84 +346,53 @@ static int omap4_keypad_probe(struct platform_device *pdev) keypad_data->row_shift = get_count_order(keypad_data->cols); max_keys =
Re: [PATCH 4/4] Input: omap4-keypad - simplify probe with devm
* Sebastian Reichel [210106 13:44]: > On Wed, Jan 06, 2021 at 02:58:22PM +0200, Tony Lindgren wrote: > > - struct resource *res; > > > > dev_pm_clear_wake_irq(>dev); > > - > > - free_irq(keypad_data->irq, keypad_data); > > - > > pm_runtime_dont_use_autosuspend(>dev); > > pm_runtime_disable(>dev); > > - > > input_unregister_device(keypad_data->input); > > not needed: > > * devm_input_allocate_device - allocate managed input device > * @dev: device owning the input device being created > * > * Returns prepared struct input_dev or %NULL. > * > * Managed input devices do not need to be explicitly unregistered or > * freed as it will be done automatically when owner device unbinds from > * its driver (or binding fails). [...] OK thanks will drop and fix up the reported autobuild warnings and repost. Looks like also the OMAP4_KEYPAD_AUTOIDLE_MS value of 50 is too long, I recently changed it from 30 but now have seen few stuck last pressed keys. Regards, Tony
Re: [PATCH 4/4] Input: omap4-keypad - simplify probe with devm
Hi Tony, I love your patch! Yet something to improve: [auto build test ERROR on input/next] [also build test ERROR on linus/master v5.11-rc2 next-20210104] [cannot apply to hid/for-next linux/master] [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] url: https://github.com/0day-ci/linux/commits/Tony-Lindgren/Lost-key-up-interrupt-handling-for-omap4-keypad/20210106-210045 base: https://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git next config: s390-randconfig-r024-20210106 (attached as .config) compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 5c951623bc8965fa1e89660f2f5f4a2944e4981a) reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # install s390 cross compiling tool for clang build # apt-get install binutils-s390x-linux-gnu # https://github.com/0day-ci/linux/commit/f42e31515b38ac05424768b08a12316f301cfd1a git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Tony-Lindgren/Lost-key-up-interrupt-handling-for-omap4-keypad/20210106-210045 git checkout f42e31515b38ac05424768b08a12316f301cfd1a # save the attached .config to linux build tree COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=s390 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot All errors (new ones prefixed by >>): dma-crossbar.c:(.text+0x344): undefined reference to `devm_platform_ioremap_resource' s390x-linux-gnu-ld: dma-crossbar.c:(.text+0x48a): undefined reference to `devm_platform_ioremap_resource' s390x-linux-gnu-ld: drivers/dma/xilinx/xilinx_dpdma.o: in function `xilinx_dpdma_probe': xilinx_dpdma.c:(.text+0x6e): undefined reference to `devm_platform_ioremap_resource' s390x-linux-gnu-ld: drivers/soc/aspeed/aspeed-lpc-ctrl.o: in function `aspeed_lpc_ctrl_probe': aspeed-lpc-ctrl.c:(.text+0x72): undefined reference to `of_address_to_resource' s390x-linux-gnu-ld: aspeed-lpc-ctrl.c:(.text+0xd6): undefined reference to `of_address_to_resource' s390x-linux-gnu-ld: drivers/soc/fsl/dpaa2-console.o: in function `dpaa2_console_probe': dpaa2-console.c:(.text+0x30): undefined reference to `of_address_to_resource' s390x-linux-gnu-ld: drivers/soc/fsl/dpaa2-console.o: in function `dpaa2_mc_console_open': dpaa2-console.c:(.text+0x34e): undefined reference to `ioremap' s390x-linux-gnu-ld: dpaa2-console.c:(.text+0x37c): undefined reference to `iounmap' s390x-linux-gnu-ld: dpaa2-console.c:(.text+0x394): undefined reference to `ioremap' s390x-linux-gnu-ld: dpaa2-console.c:(.text+0x498): undefined reference to `iounmap' s390x-linux-gnu-ld: drivers/soc/fsl/dpaa2-console.o: in function `dpaa2_console_close': dpaa2-console.c:(.text+0x4e8): undefined reference to `iounmap' s390x-linux-gnu-ld: drivers/soc/fsl/dpaa2-console.o: in function `dpaa2_aiop_console_open': dpaa2-console.c:(.text+0x56e): undefined reference to `ioremap' s390x-linux-gnu-ld: dpaa2-console.c:(.text+0x59c): undefined reference to `iounmap' s390x-linux-gnu-ld: dpaa2-console.c:(.text+0x5b4): undefined reference to `ioremap' s390x-linux-gnu-ld: dpaa2-console.c:(.text+0x6b2): undefined reference to `iounmap' s390x-linux-gnu-ld: drivers/soc/imx/soc-imx8m.o: in function `imx8mq_soc_revision': soc-imx8m.c:(.init.text+0x1f0): undefined reference to `of_iomap' s390x-linux-gnu-ld: soc-imx8m.c:(.init.text+0x232): undefined reference to `iounmap' s390x-linux-gnu-ld: drivers/soc/imx/soc-imx8m.o: in function `imx8mm_soc_revision': soc-imx8m.c:(.init.text+0x2aa): undefined reference to `of_iomap' s390x-linux-gnu-ld: soc-imx8m.c:(.init.text+0x2bc): undefined reference to `iounmap' s390x-linux-gnu-ld: drivers/soc/imx/soc-imx8m.o: in function `imx8mm_soc_uid': soc-imx8m.c:(.init.text+0x33a): undefined reference to `of_iomap' s390x-linux-gnu-ld: soc-imx8m.c:(.init.text+0x366): undefined reference to `iounmap' s390x-linux-gnu-ld: drivers/soc/mediatek/mtk-pmic-wrap.o: in function `pwrap_probe': mtk-pmic-wrap.c:(.text+0xb0): undefined reference to `devm_ioremap_resource' s390x-linux-gnu-ld: mtk-pmic-wrap.c:(.text+0x140): undefined reference to `devm_ioremap_resource' s390x-linux-gnu-ld: drivers/soc/amlogic/meson-canvas.o: in function `meson_canvas_probe': meson-canvas.c:(.text+0x42a): undefined reference to `devm_ioremap_resource' s390x-linux-gnu-ld: drivers/soc/amlogic/meson-clk-measure.o: in function `meson_msr_probe': meson-clk-measure.c:(.text+0x8e): undefined reference to `devm_ioremap_resource' s390x-linux-gnu-ld: drivers/soc/qcom/qcom-geni-se.o: in function `geni_se_probe': qcom-geni-se.c:(.text+0xc90):
Re: [PATCH 4/4] Input: omap4-keypad - simplify probe with devm
Hi Tony, On Wed, Jan 06, 2021 at 02:58:22PM +0200, Tony Lindgren wrote: > Simplify probe with devm. [...] > /* input device allocation */ > - keypad_data->input = input_dev = input_allocate_device(); > + keypad_data->input = input_dev = devm_input_allocate_device(>dev); > if (!input_dev) { > error = -ENOMEM; > goto err_pm_disable; [...] > static int omap4_keypad_remove(struct platform_device *pdev) > { > struct omap4_keypad *keypad_data = platform_get_drvdata(pdev); > - struct resource *res; > > dev_pm_clear_wake_irq(>dev); > - > - free_irq(keypad_data->irq, keypad_data); > - > pm_runtime_dont_use_autosuspend(>dev); > pm_runtime_disable(>dev); > - > input_unregister_device(keypad_data->input); not needed: * devm_input_allocate_device - allocate managed input device * @dev: device owning the input device being created * * Returns prepared struct input_dev or %NULL. * * Managed input devices do not need to be explicitly unregistered or * freed as it will be done automatically when owner device unbinds from * its driver (or binding fails). [...] -- Sebastian signature.asc Description: PGP signature
[PATCH 4/4] Input: omap4-keypad - simplify probe with devm
Simplify probe with devm. Cc: Arthur Demchenkov Cc: Carl Philipp Klemm Cc: Merlijn Wajer Cc: Pavel Machek Cc: ruleh Cc: Sebastian Reichel Signed-off-by: Tony Lindgren --- drivers/input/keyboard/omap4-keypad.c | 81 ++- 1 file changed, 30 insertions(+), 51 deletions(-) diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c --- a/drivers/input/keyboard/omap4-keypad.c +++ b/drivers/input/keyboard/omap4-keypad.c @@ -341,7 +341,8 @@ static int omap4_keypad_probe(struct platform_device *pdev) if (irq < 0) return irq; - keypad_data = kzalloc(sizeof(struct omap4_keypad), GFP_KERNEL); + keypad_data = devm_kzalloc(>dev, sizeof(struct omap4_keypad), + GFP_KERNEL); if (!keypad_data) { dev_err(>dev, "keypad_data memory allocation failed\n"); return -ENOMEM; @@ -352,20 +353,20 @@ static int omap4_keypad_probe(struct platform_device *pdev) error = omap4_keypad_parse_dt(>dev, keypad_data); if (error) - goto err_free_keypad; + return error; - res = request_mem_region(res->start, resource_size(res), pdev->name); + res = devm_request_mem_region(>dev, res->start, + resource_size(res), pdev->name); if (!res) { dev_err(>dev, "can't request mem region\n"); - error = -EBUSY; - goto err_free_keypad; + return -EBUSY; } - keypad_data->base = ioremap(res->start, resource_size(res)); + keypad_data->base = devm_ioremap(>dev, res->start, +resource_size(res)); if (!keypad_data->base) { dev_err(>dev, "can't ioremap mem resource\n"); - error = -ENOMEM; - goto err_release_mem; + return -ENOMEM; } pm_runtime_use_autosuspend(>dev); @@ -379,20 +380,19 @@ static int omap4_keypad_probe(struct platform_device *pdev) error = pm_runtime_get_sync(>dev); if (error) { dev_err(>dev, "pm_runtime_get_sync() failed\n"); - pm_runtime_put_noidle(>dev); - } else { - error = omap4_keypad_check_revision(>dev, - keypad_data); - if (!error) { - /* Ensure device does not raise interrupts */ - omap4_keypad_stop(keypad_data); - } + return error; } + + error = omap4_keypad_check_revision(>dev, + keypad_data); if (error) goto err_pm_disable; + /* Ensure device does not raise interrupts */ + omap4_keypad_stop(keypad_data); + /* input device allocation */ - keypad_data->input = input_dev = input_allocate_device(); + keypad_data->input = input_dev = devm_input_allocate_device(>dev); if (!input_dev) { error = -ENOMEM; goto err_pm_disable; @@ -416,13 +416,13 @@ static int omap4_keypad_probe(struct platform_device *pdev) keypad_data->row_shift = get_count_order(keypad_data->cols); max_keys = keypad_data->rows << keypad_data->row_shift; - keypad_data->keymap = kcalloc(max_keys, - sizeof(keypad_data->keymap[0]), - GFP_KERNEL); + keypad_data->keymap = devm_kcalloc(>dev, max_keys, + sizeof(keypad_data->keymap[0]), + GFP_KERNEL); if (!keypad_data->keymap) { dev_err(>dev, "Not enough memory for keymap\n"); error = -ENOMEM; - goto err_free_input; + goto err_pm_disable; } error = matrix_keypad_build_keymap(NULL, NULL, @@ -430,21 +430,23 @@ static int omap4_keypad_probe(struct platform_device *pdev) keypad_data->keymap, input_dev); if (error) { dev_err(>dev, "failed to build keymap\n"); - goto err_free_keymap; + goto err_pm_disable; } - error = request_threaded_irq(keypad_data->irq, omap4_keypad_irq_handler, -omap4_keypad_irq_thread_fn, IRQF_ONESHOT, -"omap4-keypad", keypad_data); + error = devm_request_threaded_irq(>dev, keypad_data->irq, + omap4_keypad_irq_handler, + omap4_keypad_irq_thread_fn, + IRQF_ONESHOT, "omap4-keypad", + keypad_data); if (error) { dev_err(>dev, "failed to register interrupt\n"); -