linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] managed resources for ili210x
@ 2017-11-11  5:02 Andi Shyti
  2017-11-11  5:02 ` [PATCH 1/2] Input: ili210x - use managed allocated resources Andi Shyti
  2017-11-11  5:02 ` [PATCH 2/2] Input: ili210x - use separate error handling for different allocators Andi Shyti
  0 siblings, 2 replies; 3+ messages in thread
From: Andi Shyti @ 2017-11-11  5:02 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input, linux-kernel, Andi Shyti, Andi Shyti

Hi Dmitry,

this is another patch of my series for switching the
touchscreen drivers to to the managed resource allocators.

The second patch is very trivial and perhaps bothering only me,
feel free to ignore.

Thanks,
Andi

Andi Shyti (2):
  Input: ili210x - use managed allocated resources
  Input: ili210x - use separate error handling for different allocators

 drivers/input/touchscreen/ili210x.c | 39 +++++++++++++------------------------
 1 file changed, 14 insertions(+), 25 deletions(-)

-- 
2.15.0

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

* [PATCH 1/2] Input: ili210x - use managed allocated resources
  2017-11-11  5:02 [PATCH 0/2] managed resources for ili210x Andi Shyti
@ 2017-11-11  5:02 ` Andi Shyti
  2017-11-11  5:02 ` [PATCH 2/2] Input: ili210x - use separate error handling for different allocators Andi Shyti
  1 sibling, 0 replies; 3+ messages in thread
From: Andi Shyti @ 2017-11-11  5:02 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input, linux-kernel, Andi Shyti, Andi Shyti

Use managed allocated resources to simplify error handling during
probing.

Adjust goto labels and remove function accordingly.

Signed-off-by: Andi Shyti <andi@etezian.org>
---
 drivers/input/touchscreen/ili210x.c | 36 +++++++++++-------------------------
 1 file changed, 11 insertions(+), 25 deletions(-)

diff --git a/drivers/input/touchscreen/ili210x.c b/drivers/input/touchscreen/ili210x.c
index 6f76eeedf465..da868b1d0e83 100644
--- a/drivers/input/touchscreen/ili210x.c
+++ b/drivers/input/touchscreen/ili210x.c
@@ -224,12 +224,10 @@ static int ili210x_i2c_probe(struct i2c_client *client,
 	xmax = panel.finger_max.x_low | (panel.finger_max.x_high << 8);
 	ymax = panel.finger_max.y_low | (panel.finger_max.y_high << 8);
 
-	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
-	input = input_allocate_device();
-	if (!priv || !input) {
-		error = -ENOMEM;
-		goto err_free_mem;
-	}
+	priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL);
+	input = devm_input_allocate_device(&client->dev);
+	if (!priv || !input)
+		return -ENOMEM;
 
 	priv->client = client;
 	priv->input = input;
@@ -258,25 +256,26 @@ static int ili210x_i2c_probe(struct i2c_client *client,
 
 	i2c_set_clientdata(client, priv);
 
-	error = request_irq(client->irq, ili210x_irq, pdata->irq_flags,
-			    client->name, priv);
+	error = devm_request_irq(&client->dev, client->irq,
+				 ili210x_irq, pdata->irq_flags,
+				 client->name, priv);
 	if (error) {
 		dev_err(dev, "Unable to request touchscreen IRQ, err: %d\n",
 			error);
-		goto err_free_mem;
+		return error;
 	}
 
-	error = sysfs_create_group(&dev->kobj, &ili210x_attr_group);
+	error = devm_device_add_group(&client->dev, &ili210x_attr_group);
 	if (error) {
 		dev_err(dev, "Unable to create sysfs attributes, err: %d\n",
 			error);
-		goto err_free_irq;
+		return error;
 	}
 
 	error = input_register_device(priv->input);
 	if (error) {
 		dev_err(dev, "Cannot register input device, err: %d\n", error);
-		goto err_remove_sysfs;
+		return error;
 	}
 
 	device_init_wakeup(dev, 1);
@@ -286,26 +285,13 @@ static int ili210x_i2c_probe(struct i2c_client *client,
 		client->irq, firmware.id, firmware.major, firmware.minor);
 
 	return 0;
-
-err_remove_sysfs:
-	sysfs_remove_group(&dev->kobj, &ili210x_attr_group);
-err_free_irq:
-	free_irq(client->irq, priv);
-err_free_mem:
-	input_free_device(input);
-	kfree(priv);
-	return error;
 }
 
 static int ili210x_i2c_remove(struct i2c_client *client)
 {
 	struct ili210x *priv = i2c_get_clientdata(client);
 
-	sysfs_remove_group(&client->dev.kobj, &ili210x_attr_group);
-	free_irq(priv->client->irq, priv);
 	cancel_delayed_work_sync(&priv->dwork);
-	input_unregister_device(priv->input);
-	kfree(priv);
 
 	return 0;
 }
-- 
2.15.0

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

* [PATCH 2/2] Input: ili210x - use separate error handling for different allocators
  2017-11-11  5:02 [PATCH 0/2] managed resources for ili210x Andi Shyti
  2017-11-11  5:02 ` [PATCH 1/2] Input: ili210x - use managed allocated resources Andi Shyti
@ 2017-11-11  5:02 ` Andi Shyti
  1 sibling, 0 replies; 3+ messages in thread
From: Andi Shyti @ 2017-11-11  5:02 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input, linux-kernel, Andi Shyti, Andi Shyti

Split the error between devm_kzalloc and
devm_input_allocate_device, there is no need to call the second
allocator if the first has failed. Besides this doesn't provide
practical advantages.

Signed-off-by: Andi Shyti <andi@etezian.org>
---
 drivers/input/touchscreen/ili210x.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/input/touchscreen/ili210x.c b/drivers/input/touchscreen/ili210x.c
index da868b1d0e83..9344c4436430 100644
--- a/drivers/input/touchscreen/ili210x.c
+++ b/drivers/input/touchscreen/ili210x.c
@@ -225,8 +225,11 @@ static int ili210x_i2c_probe(struct i2c_client *client,
 	ymax = panel.finger_max.y_low | (panel.finger_max.y_high << 8);
 
 	priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
 	input = devm_input_allocate_device(&client->dev);
-	if (!priv || !input)
+	if (!input)
 		return -ENOMEM;
 
 	priv->client = client;
-- 
2.15.0

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

end of thread, other threads:[~2017-11-11  5:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-11  5:02 [PATCH 0/2] managed resources for ili210x Andi Shyti
2017-11-11  5:02 ` [PATCH 1/2] Input: ili210x - use managed allocated resources Andi Shyti
2017-11-11  5:02 ` [PATCH 2/2] Input: ili210x - use separate error handling for different allocators Andi Shyti

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