Skip to contentSkip to conversation

serial: mxs-auart: Remove unneeded goto label

PATCH New Fabio Estevam 1 participant 4 messages Nov 27, 2014

Subsystems (2)
lore
Share & tools
lore

Fabio Estevam

author reviewer
#0 lore raw

PATCH 1/4 serial: mxs-auart: Remove unneeded goto label

From: Fabio Estevam <[email protected]>

Instead of jumping to the 'out' label, let's return the error immediately, which makes the code shorter and cleaner.

---
 drivers/tty/serial/mxs-auart.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/tty/serial/mxs-auart.c +2 -5
index ec553f8..a9e7fa6 100644
@@ -1232,10 +1232,8 @@ static int mxs_auart_probe(struct platform_device *pdev)
 	struct resource *r;
 
 	s = kzalloc(sizeof(struct mxs_auart_port), GFP_KERNEL);
-	if (!s) {
-		ret = -ENOMEM;
-		goto out;
-	}
+	if (!s)
+		return -ENOMEM;
 
 	ret = serial_mxs_probe_dt(s, pdev);
 	if (ret > 0)
@@ -1314,7 +1312,6 @@ out_free_clk:
 	clk_put(s->clk);
 out_free:
 	kfree(s);
-out:
 	return ret;
 }
 
Signature · 1 line
1.9.1
author reviewer
#1 lore raw

PATCH 2/4 serial: mxs-auart: Use devm_kzalloc()

From: Fabio Estevam <[email protected]>

By using devm_kzalloc() we can have a shorter and cleaner code.

---
 drivers/tty/serial/mxs-auart.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/tty/serial/mxs-auart.c +4 -9
index a9e7fa6..0b5f0ea 100644
@@ -1231,7 +1231,7 @@ static int mxs_auart_probe(struct platform_device *pdev)
 	int ret = 0;
 	struct resource *r;
 
-	s = kzalloc(sizeof(struct mxs_auart_port), GFP_KERNEL);
+	s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL);
 	if (!s)
 		return -ENOMEM;
 
@@ -1239,7 +1239,7 @@ static int mxs_auart_probe(struct platform_device *pdev)
 	if (ret > 0)
 		s->port.line = pdev->id < 0 ? 0 : pdev->id;
 	else if (ret < 0)
-		goto out_free;
+		return ret;
 
 	if (of_id) {
 		pdev->id_entry = of_id->data;
@@ -1247,10 +1247,8 @@ static int mxs_auart_probe(struct platform_device *pdev)
 	}
 
 	s->clk = clk_get(&pdev->dev, NULL);
-	if (IS_ERR(s->clk)) {
-		ret = PTR_ERR(s->clk);
-		goto out_free;
-	}
+	if (IS_ERR(s->clk))
+		return PTR_ERR(s->clk);
 
 	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!r) {
@@ -1310,8 +1308,6 @@ out_free_irq:
 	free_irq(s->irq, s);
 out_free_clk:
 	clk_put(s->clk);
-out_free:
-	kfree(s);
 	return ret;
 }
 
@@ -1326,7 +1322,6 @@ static int mxs_auart_remove(struct platform_device *pdev)
 	mxs_auart_free_gpio_irq(s);
 	clk_put(s->clk);
 	free_irq(s->irq, s);
-	kfree(s);
 
 	return 0;
 }
Signature · 1 line
1.9.1
author reviewer
#2 lore raw

PATCH 3/4 serial: mxs-auart: Use devm_clk_get()

In reply to Fabio Estevam

From: Fabio Estevam <[email protected]>

By using devm_clk_get() we can have a shorter and cleaner code.

---
 drivers/tty/serial/mxs-auart.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/tty/serial/mxs-auart.c +5 -9
index 0b5f0ea..9309082 100644
@@ -1246,15 +1246,14 @@ static int mxs_auart_probe(struct platform_device *pdev)
 		s->devtype = pdev->id_entry->driver_data;
 	}
 
-	s->clk = clk_get(&pdev->dev, NULL);
+	s->clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(s->clk))
 		return PTR_ERR(s->clk);
 
 	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!r) {
-		ret = -ENXIO;
-		goto out_free_clk;
-	}
+	if (!r)
+		return -ENXIO;
+
 
 	s->port.mapbase = r->start;
 	s->port.membase = ioremap(r->start, resource_size(r));
@@ -1271,7 +1270,7 @@ static int mxs_auart_probe(struct platform_device *pdev)
 	s->port.irq = s->irq;
 	ret = request_irq(s->irq, mxs_auart_irq_handle, 0, dev_name(&pdev->dev), s);
 	if (ret)
-		goto out_free_clk;
+		return ret;
 
 	platform_set_drvdata(pdev, s);
 
@@ -1306,8 +1305,6 @@ out_free_gpio_irq:
 out_free_irq:
 	auart_port[pdev->id] = NULL;
 	free_irq(s->irq, s);
-out_free_clk:
-	clk_put(s->clk);
 	return ret;
 }
 
@@ -1320,7 +1317,6 @@ static int mxs_auart_remove(struct platform_device *pdev)
 	auart_port[pdev->id] = NULL;
 
 	mxs_auart_free_gpio_irq(s);
-	clk_put(s->clk);
 	free_irq(s->irq, s);
 
 	return 0;
Signature · 1 line
1.9.1
author reviewer
#3 lore raw

PATCH 4/4 serial: mxs-auart: Use devm_request_irq()

In reply to Fabio Estevam

From: Fabio Estevam <[email protected]>

By using devm_request_irq() we can have a shorter and cleaner code.

---
 drivers/tty/serial/mxs-auart.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/tty/serial/mxs-auart.c +3 -7
index 9309082..1e9fb37 100644
@@ -1268,7 +1268,8 @@ static int mxs_auart_probe(struct platform_device *pdev)
 
 	s->irq = platform_get_irq(pdev, 0);
 	s->port.irq = s->irq;
-	ret = request_irq(s->irq, mxs_auart_irq_handle, 0, dev_name(&pdev->dev), s);
+	ret = devm_request_irq(&pdev->dev, s->irq, mxs_auart_irq_handle, 0,
+			       dev_name(&pdev->dev), s);
 	if (ret)
 		return ret;
 
@@ -1283,7 +1284,7 @@ static int mxs_auart_probe(struct platform_device *pdev)
 	 */
 	ret = mxs_auart_request_gpio_irq(s);
 	if (ret)
-		goto out_free_irq;
+		return ret;
 
 	auart_port[s->port.line] = s;
 
@@ -1302,9 +1303,7 @@ static int mxs_auart_probe(struct platform_device *pdev)
 
 out_free_gpio_irq:
 	mxs_auart_free_gpio_irq(s);
-out_free_irq:
 	auart_port[pdev->id] = NULL;
-	free_irq(s->irq, s);
 	return ret;
 }
 
@@ -1313,11 +1312,8 @@ static int mxs_auart_remove(struct platform_device *pdev)
 	struct mxs_auart_port *s = platform_get_drvdata(pdev);
 
 	uart_remove_one_port(&auart_driver, &s->port);
-
 	auart_port[pdev->id] = NULL;
-
 	mxs_auart_free_gpio_irq(s);
-	free_irq(s->irq, s);
 
 	return 0;
 }
Signature · 1 line
1.9.1