All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Input: mma8450 - convert to using managed resources
@ 2015-02-26  1:48 Dmitry Torokhov
       [not found] ` <CAGX7z0w4dES=DsSJ-7sqYTjkeWZhGZVCN_mJ=Y+cLU74g+e9=w@mail.gmail.com>
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Torokhov @ 2015-02-26  1:48 UTC (permalink / raw)
  To: linux-input; +Cc: Stefan Sauer, linux-kernel

This simplifies error handling and device removal code. Also let's
get rid of setting driver's owner since i2c core does it for us.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---

Note that the following removal was intentional as
devm_input_allocate_polled_device() does this for us:

-	idev->input->dev.parent = &c->dev;


 drivers/input/misc/mma8450.c | 35 ++++++++---------------------------
 1 file changed, 8 insertions(+), 27 deletions(-)

diff --git a/drivers/input/misc/mma8450.c b/drivers/input/misc/mma8450.c
index 9822877..19c7357 100644
--- a/drivers/input/misc/mma8450.c
+++ b/drivers/input/misc/mma8450.c
@@ -174,12 +174,13 @@ static int mma8450_probe(struct i2c_client *c,
 	struct mma8450 *m;
 	int err;
 
-	m = kzalloc(sizeof(struct mma8450), GFP_KERNEL);
-	idev = input_allocate_polled_device();
-	if (!m || !idev) {
-		err = -ENOMEM;
-		goto err_free_mem;
-	}
+	m = devm_kzalloc(&c->dev, sizeof(*m), GFP_KERNEL);
+	if (!m)
+		return -ENOMEM;
+
+	idev = devm_input_allocate_polled_device(&c->dev);
+	if (!idev)
+		return -ENOMEM;
 
 	m->client = c;
 	m->idev = idev;
@@ -187,7 +188,6 @@ static int mma8450_probe(struct i2c_client *c,
 	idev->private		= m;
 	idev->input->name	= MMA8450_DRV_NAME;
 	idev->input->id.bustype	= BUS_I2C;
-	idev->input->dev.parent = &c->dev;
 	idev->poll		= mma8450_poll;
 	idev->poll_interval	= POLL_INTERVAL;
 	idev->poll_interval_max	= POLL_INTERVAL_MAX;
@@ -202,29 +202,12 @@ static int mma8450_probe(struct i2c_client *c,
 	err = input_register_polled_device(idev);
 	if (err) {
 		dev_err(&c->dev, "failed to register polled input device\n");
-		goto err_free_mem;
+		return err;
 	}
 
 	i2c_set_clientdata(c, m);
 
 	return 0;
-
-err_free_mem:
-	input_free_polled_device(idev);
-	kfree(m);
-	return err;
-}
-
-static int mma8450_remove(struct i2c_client *c)
-{
-	struct mma8450 *m = i2c_get_clientdata(c);
-	struct input_polled_dev *idev = m->idev;
-
-	input_unregister_polled_device(idev);
-	input_free_polled_device(idev);
-	kfree(m);
-
-	return 0;
 }
 
 static const struct i2c_device_id mma8450_id[] = {
@@ -242,11 +225,9 @@ MODULE_DEVICE_TABLE(of, mma8450_dt_ids);
 static struct i2c_driver mma8450_driver = {
 	.driver = {
 		.name	= MMA8450_DRV_NAME,
-		.owner	= THIS_MODULE,
 		.of_match_table = mma8450_dt_ids,
 	},
 	.probe		= mma8450_probe,
-	.remove		= mma8450_remove,
 	.id_table	= mma8450_id,
 };
 
-- 
2.2.0.rc0.207.ga3a616c


-- 
Dmitry

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Input: mma8450 - convert to using managed resources
       [not found] ` <CAGX7z0w4dES=DsSJ-7sqYTjkeWZhGZVCN_mJ=Y+cLU74g+e9=w@mail.gmail.com>
@ 2015-02-26 12:12     ` Stefan Sauer
  0 siblings, 0 replies; 3+ messages in thread
From: Stefan Sauer @ 2015-02-26 12:12 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input, linux-kernel

Thanks, tested it and confirming it works them same.

On Thu, Feb 26, 2015 at 1:11 PM, Stefan Sauer <ensonic@google.com> wrote:
> Thanks, tested it and confirming it works them same.
>
> On Thu, Feb 26, 2015 at 2:48 AM, Dmitry Torokhov <dmitry.torokhov@gmail.com>
> wrote:
>>
>> This simplifies error handling and device removal code. Also let's
>> get rid of setting driver's owner since i2c core does it for us.
>>
>> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
>> ---
>>
>> Note that the following removal was intentional as
>> devm_input_allocate_polled_device() does this for us:
>>
>> -       idev->input->dev.parent = &c->dev;
>>
>>
>>  drivers/input/misc/mma8450.c | 35 ++++++++---------------------------
>>  1 file changed, 8 insertions(+), 27 deletions(-)
>>
>> diff --git a/drivers/input/misc/mma8450.c b/drivers/input/misc/mma8450.c
>> index 9822877..19c7357 100644
>> --- a/drivers/input/misc/mma8450.c
>> +++ b/drivers/input/misc/mma8450.c
>> @@ -174,12 +174,13 @@ static int mma8450_probe(struct i2c_client *c,
>>         struct mma8450 *m;
>>         int err;
>>
>> -       m = kzalloc(sizeof(struct mma8450), GFP_KERNEL);
>> -       idev = input_allocate_polled_device();
>> -       if (!m || !idev) {
>> -               err = -ENOMEM;
>> -               goto err_free_mem;
>> -       }
>> +       m = devm_kzalloc(&c->dev, sizeof(*m), GFP_KERNEL);
>> +       if (!m)
>> +               return -ENOMEM;
>> +
>> +       idev = devm_input_allocate_polled_device(&c->dev);
>> +       if (!idev)
>> +               return -ENOMEM;
>>
>>         m->client = c;
>>         m->idev = idev;
>> @@ -187,7 +188,6 @@ static int mma8450_probe(struct i2c_client *c,
>>         idev->private           = m;
>>         idev->input->name       = MMA8450_DRV_NAME;
>>         idev->input->id.bustype = BUS_I2C;
>> -       idev->input->dev.parent = &c->dev;
>>         idev->poll              = mma8450_poll;
>>         idev->poll_interval     = POLL_INTERVAL;
>>         idev->poll_interval_max = POLL_INTERVAL_MAX;
>> @@ -202,29 +202,12 @@ static int mma8450_probe(struct i2c_client *c,
>>         err = input_register_polled_device(idev);
>>         if (err) {
>>                 dev_err(&c->dev, "failed to register polled input
>> device\n");
>> -               goto err_free_mem;
>> +               return err;
>>         }
>>
>>         i2c_set_clientdata(c, m);
>>
>>         return 0;
>> -
>> -err_free_mem:
>> -       input_free_polled_device(idev);
>> -       kfree(m);
>> -       return err;
>> -}
>> -
>> -static int mma8450_remove(struct i2c_client *c)
>> -{
>> -       struct mma8450 *m = i2c_get_clientdata(c);
>> -       struct input_polled_dev *idev = m->idev;
>> -
>> -       input_unregister_polled_device(idev);
>> -       input_free_polled_device(idev);
>> -       kfree(m);
>> -
>> -       return 0;
>>  }
>>
>>  static const struct i2c_device_id mma8450_id[] = {
>> @@ -242,11 +225,9 @@ MODULE_DEVICE_TABLE(of, mma8450_dt_ids);
>>  static struct i2c_driver mma8450_driver = {
>>         .driver = {
>>                 .name   = MMA8450_DRV_NAME,
>> -               .owner  = THIS_MODULE,
>>                 .of_match_table = mma8450_dt_ids,
>>         },
>>         .probe          = mma8450_probe,
>> -       .remove         = mma8450_remove,
>>         .id_table       = mma8450_id,
>>  };
>>
>> --
>> 2.2.0.rc0.207.ga3a616c
>>
>>
>> --
>> Dmitry
>
>
>
>
> --
> Stefan Sauer | Software Engineer | ensonic@google.com
>
> Google Germany GmbH | Maximilianstrasse 11-15 | 80539 München | Germany
> Registergericht und -nummer: Hamburg, HRB 86891
> Sitz der Gesellschaft: Hamburg
> Geschäftsführer: Graham Law, Christine Elizabeth Flores



-- 
Stefan Sauer | Software Engineer | ensonic@google.com

Google Germany GmbH | Maximilianstrasse 11-15 | 80539 München | Germany
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Graham Law, Christine Elizabeth Flores

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Input: mma8450 - convert to using managed resources
@ 2015-02-26 12:12     ` Stefan Sauer
  0 siblings, 0 replies; 3+ messages in thread
From: Stefan Sauer @ 2015-02-26 12:12 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input, linux-kernel

Thanks, tested it and confirming it works them same.

On Thu, Feb 26, 2015 at 1:11 PM, Stefan Sauer <ensonic@google.com> wrote:
> Thanks, tested it and confirming it works them same.
>
> On Thu, Feb 26, 2015 at 2:48 AM, Dmitry Torokhov <dmitry.torokhov@gmail.com>
> wrote:
>>
>> This simplifies error handling and device removal code. Also let's
>> get rid of setting driver's owner since i2c core does it for us.
>>
>> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
>> ---
>>
>> Note that the following removal was intentional as
>> devm_input_allocate_polled_device() does this for us:
>>
>> -       idev->input->dev.parent = &c->dev;
>>
>>
>>  drivers/input/misc/mma8450.c | 35 ++++++++---------------------------
>>  1 file changed, 8 insertions(+), 27 deletions(-)
>>
>> diff --git a/drivers/input/misc/mma8450.c b/drivers/input/misc/mma8450.c
>> index 9822877..19c7357 100644
>> --- a/drivers/input/misc/mma8450.c
>> +++ b/drivers/input/misc/mma8450.c
>> @@ -174,12 +174,13 @@ static int mma8450_probe(struct i2c_client *c,
>>         struct mma8450 *m;
>>         int err;
>>
>> -       m = kzalloc(sizeof(struct mma8450), GFP_KERNEL);
>> -       idev = input_allocate_polled_device();
>> -       if (!m || !idev) {
>> -               err = -ENOMEM;
>> -               goto err_free_mem;
>> -       }
>> +       m = devm_kzalloc(&c->dev, sizeof(*m), GFP_KERNEL);
>> +       if (!m)
>> +               return -ENOMEM;
>> +
>> +       idev = devm_input_allocate_polled_device(&c->dev);
>> +       if (!idev)
>> +               return -ENOMEM;
>>
>>         m->client = c;
>>         m->idev = idev;
>> @@ -187,7 +188,6 @@ static int mma8450_probe(struct i2c_client *c,
>>         idev->private           = m;
>>         idev->input->name       = MMA8450_DRV_NAME;
>>         idev->input->id.bustype = BUS_I2C;
>> -       idev->input->dev.parent = &c->dev;
>>         idev->poll              = mma8450_poll;
>>         idev->poll_interval     = POLL_INTERVAL;
>>         idev->poll_interval_max = POLL_INTERVAL_MAX;
>> @@ -202,29 +202,12 @@ static int mma8450_probe(struct i2c_client *c,
>>         err = input_register_polled_device(idev);
>>         if (err) {
>>                 dev_err(&c->dev, "failed to register polled input
>> device\n");
>> -               goto err_free_mem;
>> +               return err;
>>         }
>>
>>         i2c_set_clientdata(c, m);
>>
>>         return 0;
>> -
>> -err_free_mem:
>> -       input_free_polled_device(idev);
>> -       kfree(m);
>> -       return err;
>> -}
>> -
>> -static int mma8450_remove(struct i2c_client *c)
>> -{
>> -       struct mma8450 *m = i2c_get_clientdata(c);
>> -       struct input_polled_dev *idev = m->idev;
>> -
>> -       input_unregister_polled_device(idev);
>> -       input_free_polled_device(idev);
>> -       kfree(m);
>> -
>> -       return 0;
>>  }
>>
>>  static const struct i2c_device_id mma8450_id[] = {
>> @@ -242,11 +225,9 @@ MODULE_DEVICE_TABLE(of, mma8450_dt_ids);
>>  static struct i2c_driver mma8450_driver = {
>>         .driver = {
>>                 .name   = MMA8450_DRV_NAME,
>> -               .owner  = THIS_MODULE,
>>                 .of_match_table = mma8450_dt_ids,
>>         },
>>         .probe          = mma8450_probe,
>> -       .remove         = mma8450_remove,
>>         .id_table       = mma8450_id,
>>  };
>>
>> --
>> 2.2.0.rc0.207.ga3a616c
>>
>>
>> --
>> Dmitry
>
>
>
>
> --
> Stefan Sauer | Software Engineer | ensonic@google.com
>
> Google Germany GmbH | Maximilianstrasse 11-15 | 80539 München | Germany
> Registergericht und -nummer: Hamburg, HRB 86891
> Sitz der Gesellschaft: Hamburg
> Geschäftsführer: Graham Law, Christine Elizabeth Flores



-- 
Stefan Sauer | Software Engineer | ensonic@google.com

Google Germany GmbH | Maximilianstrasse 11-15 | 80539 München | Germany
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Graham Law, Christine Elizabeth Flores
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-02-26 12:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-26  1:48 [PATCH] Input: mma8450 - convert to using managed resources Dmitry Torokhov
     [not found] ` <CAGX7z0w4dES=DsSJ-7sqYTjkeWZhGZVCN_mJ=Y+cLU74g+e9=w@mail.gmail.com>
2015-02-26 12:12   ` Stefan Sauer
2015-02-26 12:12     ` Stefan Sauer

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.