diff mbox series

[6/8] Input: sh-keysc - convert to use devm_* api

Message ID 20230714080611.81302-6-frank.li@vivo.com (mailing list archive)
State New, archived
Headers show
Series [1/8] Input: lm8333 - convert to use devm_* api | expand

Commit Message

Yangtao Li July 14, 2023, 8:06 a.m. UTC
Use devm_* api to simplify code, this makes it unnecessary to explicitly
release resources.

Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
 drivers/input/keyboard/sh_keysc.c | 50 +++++++++----------------------
 1 file changed, 14 insertions(+), 36 deletions(-)

Comments

Dmitry Torokhov July 24, 2023, 5:39 a.m. UTC | #1
On Fri, Jul 14, 2023 at 04:06:09PM +0800, Yangtao Li wrote:
> Use devm_* api to simplify code, this makes it unnecessary to explicitly
> release resources.

I'd like to see a more complete conversion that results in
sh_keysc_remove() being completely removed.

Thanks.
diff mbox series

Patch

diff --git a/drivers/input/keyboard/sh_keysc.c b/drivers/input/keyboard/sh_keysc.c
index 2c00320f739f..388fb87f9e56 100644
--- a/drivers/input/keyboard/sh_keysc.c
+++ b/drivers/input/keyboard/sh_keysc.c
@@ -160,6 +160,7 @@  static irqreturn_t sh_keysc_isr(int irq, void *dev_id)
 
 static int sh_keysc_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	struct sh_keysc_priv *priv;
 	struct sh_keysc_info *pdata;
 	struct resource *res;
@@ -169,44 +170,39 @@  static int sh_keysc_probe(struct platform_device *pdev)
 
 	if (!dev_get_platdata(&pdev->dev)) {
 		dev_err(&pdev->dev, "no platform data defined\n");
-		error = -EINVAL;
-		goto err0;
+		return -EINVAL;
 	}
 
-	error = -ENXIO;
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (res == NULL) {
 		dev_err(&pdev->dev, "failed to get I/O memory\n");
-		goto err0;
+		return -ENXIO;
 	}
 
 	irq = platform_get_irq(pdev, 0);
 	if (irq < 0)
-		goto err0;
+		return irq;
 
-	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
 	if (priv == NULL) {
 		dev_err(&pdev->dev, "failed to allocate driver data\n");
-		error = -ENOMEM;
-		goto err0;
+		return -ENOMEM;
 	}
 
 	platform_set_drvdata(pdev, priv);
 	memcpy(&priv->pdata, dev_get_platdata(&pdev->dev), sizeof(priv->pdata));
 	pdata = &priv->pdata;
 
-	priv->iomem_base = ioremap(res->start, resource_size(res));
+	priv->iomem_base = devm_ioremap(dev, res->start, resource_size(res));
 	if (priv->iomem_base == NULL) {
 		dev_err(&pdev->dev, "failed to remap I/O memory\n");
-		error = -ENXIO;
-		goto err1;
+		return -ENXIO;
 	}
 
-	priv->input = input_allocate_device();
+	priv->input = devm_input_allocate_device(dev);
 	if (!priv->input) {
 		dev_err(&pdev->dev, "failed to allocate input device\n");
-		error = -ENOMEM;
-		goto err2;
+		return -ENOMEM;
 	}
 
 	input = priv->input;
@@ -225,11 +221,11 @@  static int sh_keysc_probe(struct platform_device *pdev)
 	input->keycodesize = sizeof(pdata->keycodes[0]);
 	input->keycodemax = ARRAY_SIZE(pdata->keycodes);
 
-	error = request_threaded_irq(irq, NULL, sh_keysc_isr, IRQF_ONESHOT,
-				     dev_name(&pdev->dev), pdev);
+	error = devm_request_threaded_irq(dev, irq, NULL, sh_keysc_isr, IRQF_ONESHOT,
+					  dev_name(&pdev->dev), pdev);
 	if (error) {
 		dev_err(&pdev->dev, "failed to request IRQ\n");
-		goto err3;
+		return error;
 	}
 
 	for (i = 0; i < SH_KEYSC_MAXKEYS; i++)
@@ -239,7 +235,7 @@  static int sh_keysc_probe(struct platform_device *pdev)
 	error = input_register_device(input);
 	if (error) {
 		dev_err(&pdev->dev, "failed to register input device\n");
-		goto err4;
+		return error;
 	}
 
 	pm_runtime_enable(&pdev->dev);
@@ -252,17 +248,6 @@  static int sh_keysc_probe(struct platform_device *pdev)
 	device_init_wakeup(&pdev->dev, 1);
 
 	return 0;
-
- err4:
-	free_irq(irq, pdev);
- err3:
-	input_free_device(input);
- err2:
-	iounmap(priv->iomem_base);
- err1:
-	kfree(priv);
- err0:
-	return error;
 }
 
 static int sh_keysc_remove(struct platform_device *pdev)
@@ -270,16 +255,9 @@  static int sh_keysc_remove(struct platform_device *pdev)
 	struct sh_keysc_priv *priv = platform_get_drvdata(pdev);
 
 	sh_keysc_write(priv, KYCR2, KYCR2_IRQ_DISABLED);
-
-	input_unregister_device(priv->input);
-	free_irq(platform_get_irq(pdev, 0), pdev);
-	iounmap(priv->iomem_base);
-
 	pm_runtime_put_sync(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
 
-	kfree(priv);
-
 	return 0;
 }