All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tobias Klauser <tklauser@distanz.ch>
To: Pramod Gurav <pramod.gurav@smartplayin.com>
Cc: linux-kernel@vger.kernel.org,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	linux-input@vger.kernel.org
Subject: Re: [PATCH] Input: opencores-kbd: Switch to using managed resources
Date: Tue, 7 Oct 2014 15:33:22 +0200	[thread overview]
Message-ID: <20141007133322.GL3279@distanz.ch> (raw)
In-Reply-To: <1412681501-28072-1-git-send-email-pramod.gurav@smartplayin.com>

On 2014-10-07 at 13:31:41 +0200, Pramod Gurav <pramod.gurav@smartplayin.com> wrote:
> This change switch to managed resources to simplifies error handling
> and module unloading and does away with platform_driver remove function.
> 
> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> Cc: linux-input@vger.kernel.org
> Signed-off-by: Pramod Gurav <pramod.gurav@smartplayin.com>
> ---
>  drivers/input/keyboard/opencores-kbd.c |   54 ++++++++------------------------
>  1 file changed, 13 insertions(+), 41 deletions(-)
> 
> diff --git a/drivers/input/keyboard/opencores-kbd.c b/drivers/input/keyboard/opencores-kbd.c
> index 7b9b441..ecacb87 100644
> --- a/drivers/input/keyboard/opencores-kbd.c
> +++ b/drivers/input/keyboard/opencores-kbd.c
> @@ -56,27 +56,27 @@ static int opencores_kbd_probe(struct platform_device *pdev)
>  		return -EINVAL;
>  	}
>  
> -	opencores_kbd = kzalloc(sizeof(*opencores_kbd), GFP_KERNEL);
> -	input = input_allocate_device();
> +	opencores_kbd = devm_kzalloc(&pdev->dev, sizeof(*opencores_kbd),
> +				     GFP_KERNEL);
> +	input = devm_input_allocate_device(&pdev->dev);
>  	if (!opencores_kbd || !input) {
>  		dev_err(&pdev->dev, "failed to allocate device structures\n");
> -		error = -ENOMEM;
> -		goto err_free_mem;
> +		return -ENOMEM;
>  	}
>  
>  	opencores_kbd->addr_res = res;
> -	res = request_mem_region(res->start, resource_size(res), pdev->name);
> +	res = devm_request_mem_region(&pdev->dev, res->start,
> +				      resource_size(res), pdev->name);
>  	if (!res) {
>  		dev_err(&pdev->dev, "failed to request I/O memory\n");
> -		error = -EBUSY;
> -		goto err_free_mem;
> +		return -EBUSY;
>  	}
>  
> -	opencores_kbd->addr = ioremap(res->start, resource_size(res));
> +	opencores_kbd->addr = devm_ioremap(&pdev->dev, res->start,
> +					   resource_size(res));

You could use devm_ioremap_resource() here and get rid of the call to
devm_request_mem_region() and the check for !res above, i.e. something
like:

	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	[...]
	opencores_kbd->addr = devm_ioremap_resource(&pdev->dev, res);
	if (!opencores_kbd->addr) {
		dev_err(&pdev->dev, "failed to remap I/O memory\n");
		return -ENXIO;
	}

>  	if (!opencores_kbd->addr) {
>  		dev_err(&pdev->dev, "failed to remap I/O memory\n");
> -		error = -ENXIO;
> -		goto err_rel_mem;
> +		return -ENXIO;
>  	}
>  
>  	opencores_kbd->input = input;
> @@ -109,54 +109,26 @@ static int opencores_kbd_probe(struct platform_device *pdev)
>  	}
>  	__clear_bit(KEY_RESERVED, input->keybit);
>  
> -	error = request_irq(irq, &opencores_kbd_isr,
> +	error = devm_request_irq(&pdev->dev, irq, &opencores_kbd_isr,
>  			    IRQF_TRIGGER_RISING, pdev->name, opencores_kbd);

The second line should be aligned to the opening parenthesis:

	error = devm_request_irq(&pdev->dev, irq, &opencores_kbd_isr,
				 IRQF_TRIGGER_RISING, pdev->name, opencores_kbd);

  reply	other threads:[~2014-10-07 13:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-07 11:31 [PATCH] Input: opencores-kbd: Switch to using managed resources Pramod Gurav
2014-10-07 13:33 ` Tobias Klauser [this message]
2014-10-07 16:17   ` Dmitry Torokhov
2014-10-08  7:09     ` Tobias Klauser

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=20141007133322.GL3279@distanz.ch \
    --to=tklauser@distanz.ch \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pramod.gurav@smartplayin.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.