linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tony Lindgren <tony@atomide.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-omap@vger.kernel.org,
	Arthur Demchenkov <spinal.by@gmail.com>,
	Carl Philipp Klemm <philipp@uvos.xyz>,
	Merlijn Wajer <merlijn@wizzup.org>, Pavel Machek <pavel@ucw.cz>,
	ruleh <ruleh@gmx.de>, Sebastian Reichel <sre@kernel.org>
Subject: Re: [PATCH 4/4] Input: omap4-keypad - simplify probe with devm
Date: Sun, 10 Jan 2021 18:36:51 +0200	[thread overview]
Message-ID: <X/stIwdpy0OuPEs9@atomide.com> (raw)
In-Reply-To: <X/qfJKiM21uyksYl@google.com>

* Dmitry Torokhov <dmitry.torokhov@gmail.com> [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 <dmitry.torokhov@gmail.com>
> 
> Now that input core supports devres-managed input devices we can clean
> up this driver a bit.
> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

Tested-by: Tony Lindgren <tony@atomide.com>


> ---
>  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 = &pdev->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(&pdev->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(&pdev->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(&pdev->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(&pdev->dev, "can't ioremap mem resource\n");
> -		error = -ENOMEM;
> -		goto err_release_mem;
> -	}
> +	pm_runtime_enable(dev);
>  
> -	pm_runtime_enable(&pdev->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(&pdev->dev, "pm_runtime_get_sync() failed\n");
>  		pm_runtime_put_noidle(&pdev->dev);
> -	} else {
> -		error = omap4_keypad_check_revision(&pdev->dev,
> -						    keypad_data);
> -		if (!error) {
> -			/* Ensure device does not raise interrupts */
> -			omap4_keypad_stop(keypad_data);
> -		}
> -		pm_runtime_put_sync(&pdev->dev);
> +		return error;
> +	}
> +
> +	error = omap4_keypad_check_revision(&pdev->dev,
> +					    keypad_data);
> +	if (!error) {
> +		/* Ensure device does not raise interrupts */
> +		omap4_keypad_stop(keypad_data);
>  	}
> +
> +	pm_runtime_put_sync(&pdev->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 = &pdev->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,
> +					   max_keys,
> +					   sizeof(keypad_data->keymap[0]),
> +					   GFP_KERNEL);
>  	if (!keypad_data->keymap) {
> -		dev_err(&pdev->dev, "Not enough memory for keymap\n");
> -		error = -ENOMEM;
> -		goto err_free_input;
> +		dev_err(dev, "Not enough memory for keymap\n");
> +		return -ENOMEM;
>  	}
>  
>  	error = matrix_keypad_build_keymap(NULL, NULL,
>  					   keypad_data->rows, keypad_data->cols,
>  					   keypad_data->keymap, input_dev);
>  	if (error) {
> -		dev_err(&pdev->dev, "failed to build keymap\n");
> -		goto err_free_keymap;
> +		dev_err(dev, "failed to build keymap\n");
> +		return error;
>  	}
>  
> -	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(&pdev->dev, "failed to register interrupt\n");
> -		goto err_free_keymap;
> +		dev_err(dev, "failed to register interrupt\n");
> +		return error;
>  	}
>  
>  	error = input_register_device(keypad_data->input);
> -	if (error < 0) {
> -		dev_err(&pdev->dev, "failed to register input device\n");
> -		goto err_free_irq;
> +	if (error) {
> +		dev_err(dev, "failed to register input device\n");
> +		return error;
>  	}
>  
> -	device_init_wakeup(&pdev->dev, true);
> -	error = dev_pm_set_wake_irq(&pdev->dev, keypad_data->irq);
> +	device_init_wakeup(dev, true);
> +	error = dev_pm_set_wake_irq(dev, keypad_data->irq);
>  	if (error)
> -		dev_warn(&pdev->dev,
> -			 "failed to set up wakeup irq: %d\n", error);
> +		dev_warn(dev, "failed to set up wakeup irq: %d\n", error);
>  
>  	platform_set_drvdata(pdev, keypad_data);
>  
>  	return 0;
> -
> -err_free_irq:
> -	free_irq(keypad_data->irq, keypad_data);
> -err_free_keymap:
> -	kfree(keypad_data->keymap);
> -err_free_input:
> -	input_free_device(input_dev);
> -err_pm_disable:
> -	pm_runtime_disable(&pdev->dev);
> -	iounmap(keypad_data->base);
> -err_release_mem:
> -	release_mem_region(res->start, resource_size(res));
> -err_free_keypad:
> -	kfree(keypad_data);
> -	return error;
>  }
>  
>  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(&pdev->dev);
>  
> -	free_irq(keypad_data->irq, keypad_data);
> -
> -	pm_runtime_disable(&pdev->dev);
> -
> -	input_unregister_device(keypad_data->input);
> -
> -	iounmap(keypad_data->base);
> -
> -	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> -	release_mem_region(res->start, resource_size(res));
> -
> -	kfree(keypad_data->keymap);
> -	kfree(keypad_data);
> -
>  	return 0;
>  }
>  

      reply	other threads:[~2021-01-10 16:37 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-06 12:58 [PATCHv4 0/4] Lost key-up interrupt handling for omap4-keypad Tony Lindgren
2021-01-06 12:58 ` [PATCH 1/4] Input: omap4-keypad - disable unused long interrupts Tony Lindgren
2021-01-06 12:58 ` [PATCH 2/4] Input: omap4-keypad - scan keys in two phases and simplify with bitmask Tony Lindgren
2021-01-06 15:01   ` kernel test robot
2021-01-06 12:58 ` [PATCH 3/4] Input: omap4-keypad - use PM runtime to check keys for errata Tony Lindgren
2021-01-06 15:33   ` kernel test robot
2021-01-06 16:15   ` kernel test robot
2021-01-06 16:22   ` kernel test robot
2021-01-10  6:34   ` Dmitry Torokhov
2021-01-10 16:49     ` Tony Lindgren
2021-01-06 12:58 ` [PATCH 4/4] Input: omap4-keypad - simplify probe with devm Tony Lindgren
2021-01-06 13:43   ` Sebastian Reichel
2021-01-08  7:25     ` Tony Lindgren
2021-01-06 17:59   ` kernel test robot
2021-01-10  6:31   ` Dmitry Torokhov
2021-01-10 16:36     ` Tony Lindgren [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=X/stIwdpy0OuPEs9@atomide.com \
    --to=tony@atomide.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=merlijn@wizzup.org \
    --cc=pavel@ucw.cz \
    --cc=philipp@uvos.xyz \
    --cc=ruleh@gmx.de \
    --cc=spinal.by@gmail.com \
    --cc=sre@kernel.org \
    --subject='Re: [PATCH 4/4] Input: omap4-keypad - simplify probe with devm' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).