From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: "Paweł Chmiel" <pawel.mikolaj.chmiel@gmail.com>
Cc: robh+dt@kernel.org, mark.rutland@arm.com, xc-racer2@live.ca,
devicetree@vger.kernel.org, linux-input@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/5] input: misc: bma150: Use managed resources helpers
Date: Wed, 6 Feb 2019 10:52:55 -0800 [thread overview]
Message-ID: <20190206185255.GC174258@dtor-ws> (raw)
In-Reply-To: <20190202151806.9064-3-pawel.mikolaj.chmiel@gmail.com>
On Sat, Feb 02, 2019 at 04:18:03PM +0100, Paweł Chmiel wrote:
> From: Jonathan Bakker <xc-racer2@live.ca>
>
> The driver can be cleaned up by using managed resource helpers
>
> Changes from v1:
> - Correct devm input unregistering
>
> Signed-off-by: Jonathan Bakker <xc-racer2@live.ca>
> Signed-off-by: Paweł Chmiel <pawel.mikolaj.chmiel@gmail.com>
Applied, thank you.
> ---
> drivers/input/misc/bma150.c | 44 ++++++++++---------------------------
> 1 file changed, 12 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/input/misc/bma150.c b/drivers/input/misc/bma150.c
> index 1efcfdf9f8a8..79acaaf86b7e 100644
> --- a/drivers/input/misc/bma150.c
> +++ b/drivers/input/misc/bma150.c
> @@ -471,7 +471,7 @@ static int bma150_register_input_device(struct bma150_data *bma150)
> struct input_dev *idev;
> int error;
>
> - idev = input_allocate_device();
> + idev = devm_input_allocate_device(&bma150->client->dev);
> if (!idev)
> return -ENOMEM;
>
> @@ -482,10 +482,8 @@ static int bma150_register_input_device(struct bma150_data *bma150)
> input_set_drvdata(idev, bma150);
>
> error = input_register_device(idev);
> - if (error) {
> - input_free_device(idev);
> + if (error)
> return error;
> - }
>
> bma150->input = idev;
> return 0;
> @@ -496,7 +494,7 @@ static int bma150_register_polled_device(struct bma150_data *bma150)
> struct input_polled_dev *ipoll_dev;
> int error;
>
> - ipoll_dev = input_allocate_polled_device();
> + ipoll_dev = devm_input_allocate_polled_device(&bma150->client->dev);
> if (!ipoll_dev)
> return -ENOMEM;
>
> @@ -511,10 +509,8 @@ static int bma150_register_polled_device(struct bma150_data *bma150)
> bma150_init_input_device(bma150, ipoll_dev->input);
>
> error = input_register_polled_device(ipoll_dev);
> - if (error) {
> - input_free_polled_device(ipoll_dev);
> + if (error)
> return error;
> - }
>
> bma150->input_polled = ipoll_dev;
> bma150->input = ipoll_dev->input;
> @@ -543,7 +539,8 @@ static int bma150_probe(struct i2c_client *client,
> return -EINVAL;
> }
>
> - bma150 = kzalloc(sizeof(struct bma150_data), GFP_KERNEL);
> + bma150 = devm_kzalloc(&client->dev, sizeof(struct bma150_data),
> + GFP_KERNEL);
> if (!bma150)
> return -ENOMEM;
>
> @@ -556,7 +553,7 @@ static int bma150_probe(struct i2c_client *client,
> dev_err(&client->dev,
> "IRQ GPIO conf. error %d, error %d\n",
> client->irq, error);
> - goto err_free_mem;
> + return error;
> }
> }
> cfg = &pdata->cfg;
> @@ -566,14 +563,14 @@ static int bma150_probe(struct i2c_client *client,
>
> error = bma150_initialize(bma150, cfg);
> if (error)
> - goto err_free_mem;
> + return error;
>
> if (client->irq > 0) {
> error = bma150_register_input_device(bma150);
> if (error)
> - goto err_free_mem;
> + return error;
>
> - error = request_threaded_irq(client->irq,
> + error = devm_request_threaded_irq(&client->dev, client->irq,
> NULL, bma150_irq_thread,
> IRQF_TRIGGER_RISING | IRQF_ONESHOT,
> BMA150_DRIVER, bma150);
> @@ -581,13 +578,12 @@ static int bma150_probe(struct i2c_client *client,
> dev_err(&client->dev,
> "irq request failed %d, error %d\n",
> client->irq, error);
> - input_unregister_device(bma150->input);
> - goto err_free_mem;
> + return error;
> }
> } else {
> error = bma150_register_polled_device(bma150);
> if (error)
> - goto err_free_mem;
> + return error;
> }
>
> i2c_set_clientdata(client, bma150);
> @@ -595,28 +591,12 @@ static int bma150_probe(struct i2c_client *client,
> pm_runtime_enable(&client->dev);
>
> return 0;
> -
> -err_free_mem:
> - kfree(bma150);
> - return error;
> }
>
> static int bma150_remove(struct i2c_client *client)
> {
> - struct bma150_data *bma150 = i2c_get_clientdata(client);
> -
> pm_runtime_disable(&client->dev);
>
> - if (client->irq > 0) {
> - free_irq(client->irq, bma150);
> - input_unregister_device(bma150->input);
> - } else {
> - input_unregister_polled_device(bma150->input_polled);
> - input_free_polled_device(bma150->input_polled);
> - }
> -
> - kfree(bma150);
> -
> return 0;
> }
>
> --
> 2.17.1
>
--
Dmitry
next prev parent reply other threads:[~2019-02-06 18:53 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-02 15:18 [PATCH v2 0/5] input: misc: bma150: Add support for device tree Paweł Chmiel
2019-02-02 15:18 ` [PATCH v2 1/5] dt-bindings: input: Add binding for bma150 sensor Paweł Chmiel
2019-02-18 19:18 ` Rob Herring
2019-02-18 22:17 ` Jonathan Bakker
2019-02-02 15:18 ` [PATCH v2 2/5] input: misc: bma150: Use managed resources helpers Paweł Chmiel
2019-02-06 18:52 ` Dmitry Torokhov [this message]
2019-02-02 15:18 ` [PATCH v2 3/5] input: misc: bma150: Add support for device tree Paweł Chmiel
2019-02-02 15:18 ` [PATCH v2 4/5] input: misc: bma150: Drop platform data Paweł Chmiel
2019-02-02 15:18 ` [PATCH v2 5/5] input: misc: bma150: Register input device after setting private data Paweł Chmiel
2019-02-06 18:53 ` Dmitry Torokhov
2019-02-06 19:23 ` Dmitry Torokhov
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=20190206185255.GC174258@dtor-ws \
--to=dmitry.torokhov@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=pawel.mikolaj.chmiel@gmail.com \
--cc=robh+dt@kernel.org \
--cc=xc-racer2@live.ca \
/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).