From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Sonic Zhang <sonic.adi@gmail.com>
Cc: linux-input@vger.kernel.org,
Michael Hennerich <michael.hennerich@analog.com>,
adi-buildroot-devel@lists.sourceforge.net,
Sonic Zhang <sonic.zhang@analog.com>
Subject: Re: [PATCH] bfin_rotary: convert to use managed resources
Date: Wed, 4 Feb 2015 11:56:40 -0800 [thread overview]
Message-ID: <20150204195640.GE15782@dtor-ws> (raw)
In-Reply-To: <1423036686-31891-3-git-send-email-sonic.adi@gmail.com>
On Wed, Feb 04, 2015 at 03:58:06PM +0800, Sonic Zhang wrote:
> From: Sonic Zhang <sonic.zhang@analog.com>
>
> - remap rotary register physical address into kernel space in probe
> - replace kzalloc with devm_kzalloc
> - replace request_irq with devm_request_irq
> - remove memory free and irq free from the device remove function
> - use devm_input_allocate_device
>
> Signed-off-by: Sonic Zhang <sonic.zhang@analog.com>
> ---
> arch/blackfin/mach-bf527/boards/ad7160eval.c | 5 ++
> arch/blackfin/mach-bf527/boards/ezkit.c | 5 ++
> arch/blackfin/mach-bf548/boards/ezkit.c | 5 ++
> arch/blackfin/mach-bf609/boards/ezkit.c | 5 ++
> drivers/input/misc/bfin_rotary.c | 64 ++++++++++++++------------
> 5 files changed, 54 insertions(+), 30 deletions(-)
>
> diff --git a/arch/blackfin/mach-bf527/boards/ad7160eval.c b/arch/blackfin/mach-bf527/boards/ad7160eval.c
> index 029a050..68f2a8a 100644
> --- a/arch/blackfin/mach-bf527/boards/ad7160eval.c
> +++ b/arch/blackfin/mach-bf527/boards/ad7160eval.c
> @@ -688,6 +688,11 @@ static struct bfin_rotary_platform_data bfin_rotary_data = {
>
> static struct resource bfin_rotary_resources[] = {
> {
> + .start = CNT_CONFIG,
> + .end = CNT_CONFIG + 0xff,
> + .flags = IORESOURCE_MEM,
> + },
> + {
> .start = IRQ_CNT,
> .end = IRQ_CNT,
> .flags = IORESOURCE_IRQ,
> diff --git a/arch/blackfin/mach-bf527/boards/ezkit.c b/arch/blackfin/mach-bf527/boards/ezkit.c
> index cc80c5b..d4219e8 100644
> --- a/arch/blackfin/mach-bf527/boards/ezkit.c
> +++ b/arch/blackfin/mach-bf527/boards/ezkit.c
> @@ -1114,6 +1114,11 @@ static struct bfin_rotary_platform_data bfin_rotary_data = {
>
> static struct resource bfin_rotary_resources[] = {
> {
> + .start = CNT_CONFIG,
> + .end = CNT_CONFIG + 0xff,
> + .flags = IORESOURCE_MEM,
> + },
> + {
> .start = IRQ_CNT,
> .end = IRQ_CNT,
> .flags = IORESOURCE_IRQ,
> diff --git a/arch/blackfin/mach-bf548/boards/ezkit.c b/arch/blackfin/mach-bf548/boards/ezkit.c
> index 8f70f83..4204b98 100644
> --- a/arch/blackfin/mach-bf548/boards/ezkit.c
> +++ b/arch/blackfin/mach-bf548/boards/ezkit.c
> @@ -173,6 +173,11 @@ static struct bfin_rotary_platform_data bfin_rotary_data = {
>
> static struct resource bfin_rotary_resources[] = {
> {
> + .start = CNT_CONFIG,
> + .end = CNT_CONFIG + 0xff,
> + .flags = IORESOURCE_MEM,
> + },
> + {
> .start = IRQ_CNT,
> .end = IRQ_CNT,
> .flags = IORESOURCE_IRQ,
> diff --git a/arch/blackfin/mach-bf609/boards/ezkit.c b/arch/blackfin/mach-bf609/boards/ezkit.c
> index f9dc64d..7f9fc27 100644
> --- a/arch/blackfin/mach-bf609/boards/ezkit.c
> +++ b/arch/blackfin/mach-bf609/boards/ezkit.c
> @@ -88,6 +88,11 @@ static struct bfin_rotary_platform_data bfin_rotary_data = {
>
> static struct resource bfin_rotary_resources[] = {
> {
> + .start = CNT_CONFIG,
> + .end = CNT_CONFIG + 0xff,
> + .flags = IORESOURCE_MEM,
> + },
> + {
> .start = IRQ_CNT,
> .end = IRQ_CNT,
> .flags = IORESOURCE_IRQ,
> diff --git a/drivers/input/misc/bfin_rotary.c b/drivers/input/misc/bfin_rotary.c
> index defddca..3bc0018 100644
> --- a/drivers/input/misc/bfin_rotary.c
> +++ b/drivers/input/misc/bfin_rotary.c
> @@ -95,11 +95,38 @@ static irqreturn_t bfin_rotary_isr(int irq, void *dev_id)
>
> static int bfin_rotary_probe(struct platform_device *pdev)
> {
> + struct device *dev = &pdev->dev;
> struct bfin_rotary_platform_data *pdata = dev_get_platdata(&pdev->dev);
> struct bfin_rot *rotary;
> + struct resource *res;
> struct input_dev *input;
> int error;
>
> + rotary = devm_kzalloc(dev, sizeof(struct bfin_rot), GFP_KERNEL);
> + if (!rotary) {
> + dev_err(dev, "fail to malloc bfin_rot\n");
> + return -ENOMEM;
> + }
> +
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + rotary->base = devm_ioremap_resource(dev, res);
> + if (IS_ERR(rotary->base))
> + return PTR_ERR(rotary->base);
> +
> + rotary->irq = platform_get_irq(pdev, 0);
> + if (rotary->irq < 0) {
> + dev_err(dev, "No rotary IRQ specified\n");
> + return -ENOENT;
> + }
> +
> + error = devm_request_irq(dev, rotary->irq, bfin_rotary_isr,
> + 0, dev_name(&pdev->dev), pdev);
> + if (error) {
> + dev_err(dev, "unable to claim irq %d; error %d\n",
> + rotary->irq, error);
> + return error;
> + }
> +
> /* Basic validation */
> if ((pdata->rotary_up_key && !pdata->rotary_down_key) ||
> (!pdata->rotary_up_key && pdata->rotary_down_key)) {
> @@ -108,15 +135,14 @@ static int bfin_rotary_probe(struct platform_device *pdev)
>
> error = peripheral_request_list(pdata->pin_list, dev_name(&pdev->dev));
> if (error) {
> - dev_err(&pdev->dev, "requesting peripherals failed\n");
> + dev_err(dev, "requesting peripherals failed\n");
> return error;
> }
>
> - rotary = kzalloc(sizeof(struct bfin_rot), GFP_KERNEL);
> - input = input_allocate_device();
> - if (!rotary || !input) {
> + input = devm_input_allocate_device(dev);
> + if (!input) {
> error = -ENOMEM;
> - goto out1;
> + goto out;
> }
>
> rotary->input = input;
> @@ -126,10 +152,6 @@ static int bfin_rotary_probe(struct platform_device *pdev)
> rotary->button_key = pdata->rotary_button_key;
> rotary->rel_code = pdata->rotary_rel_code;
>
> - error = rotary->irq = platform_get_irq(pdev, 0);
> - if (error < 0)
> - goto out1;
> -
> input->name = pdev->name;
> input->phys = "bfin-rotary/input0";
> input->dev.parent = &pdev->dev;
> @@ -155,20 +177,10 @@ static int bfin_rotary_probe(struct platform_device *pdev)
> __set_bit(rotary->button_key, input->keybit);
> }
>
> - error = request_irq(rotary->irq, bfin_rotary_isr,
> - 0, dev_name(&pdev->dev), pdev);
> - if (error) {
> - dev_err(&pdev->dev,
> - "unable to claim irq %d; error %d\n",
> - rotary->irq, error);
> - goto out1;
> - }
> -
> error = input_register_device(input);
> if (error) {
> - dev_err(&pdev->dev,
> - "unable to register input device (%d)\n", error);
> - goto out2;
> + dev_err(dev, "unable to register input device (%d)\n", error);
> + goto out;
> }
>
> if (pdata->rotary_button_key)
> @@ -193,11 +205,7 @@ static int bfin_rotary_probe(struct platform_device *pdev)
>
> return 0;
>
> -out2:
> - free_irq(rotary->irq, pdev);
> -out1:
> - input_free_device(input);
> - kfree(rotary);
> +out:
> peripheral_free_list(per_cnt);
>
> return error;
> @@ -211,12 +219,8 @@ static int bfin_rotary_remove(struct platform_device *pdev)
> writew(0, rotary->base + CNT_CONFIG_OFF);
> writew(0, rotary->base + CNT_IMASK_OFF);
>
> - free_irq(rotary->irq, pdev);
> - input_unregister_device(rotary->input);
> peripheral_free_list(pdata->pin_list);
This causes pins be freed while interrupt is still active. I suggest you
use devm_add_action() to integrate freeing of pins into the rest of
devm* unwind sequence.
>
> - kfree(rotary);
> -
> return 0;
> }
>
> --
> 1.7.9.5
>
Thanks.
--
Dmitry
next prev parent reply other threads:[~2015-02-04 19:56 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-04 7:58 [PATCH v3 2/3] bfin_rotary: Move peripheral pinmux definition into platform data of bf527 Sonic Zhang
2015-02-04 7:58 ` [PATCH v3 3/3] bfin_rotary: replace bfin specific MMR function with generic IO function Sonic Zhang
2015-02-04 19:46 ` Dmitry Torokhov
2015-02-04 7:58 ` [PATCH] bfin_rotary: convert to use managed resources Sonic Zhang
2015-02-04 19:56 ` Dmitry Torokhov [this message]
2015-02-04 19:44 ` [PATCH v3 2/3] bfin_rotary: Move peripheral pinmux definition into platform data of bf527 Dmitry Torokhov
2015-02-05 5:13 ` Sonic Zhang
2015-02-05 7:39 ` Sonic Zhang
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=20150204195640.GE15782@dtor-ws \
--to=dmitry.torokhov@gmail.com \
--cc=adi-buildroot-devel@lists.sourceforge.net \
--cc=linux-input@vger.kernel.org \
--cc=michael.hennerich@analog.com \
--cc=sonic.adi@gmail.com \
--cc=sonic.zhang@analog.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 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).