Skip to contentSkip to conversation

iio:trigger: Introduce the use of devm_kzalloc

PATCH Applied Himangi Saraogi 4 participants 6 messages Jul 1, 2014 – Jul 7, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 iio:trigger: Introduce the use of devm_kzalloc

This patch introduces the use of the managed version of kzalloc and removes the kfrees in the probe and remove functions. More return paths are added and the labels are renamed to order them.

---
v2: add more return paths
Not compile tested.

 drivers/staging/iio/trigger/iio-trig-bfin-timer.c | 31 ++++++++---------------
 1 file changed, 11 insertions(+), 20 deletions(-)
drivers/staging/iio/trigger/iio-trig-bfin-timer.c +11 -20
index 16f1a06..a21b7c5 100644
@@ -182,45 +182,40 @@ static int iio_bfin_tmr_trigger_probe(struct platform_device *pdev)
 	unsigned int config;
 	int ret;
 
-	st = kzalloc(sizeof(*st), GFP_KERNEL);
-	if (st == NULL) {
-		ret = -ENOMEM;
-		goto out;
-	}
+	st = devm_kzalloc(&pdev->dev, sizeof(*st), GFP_KERNEL);
+	if (st == NULL)
+		return -ENOMEM;
 
 	st->irq = platform_get_irq(pdev, 0);
 	if (!st->irq) {
 		dev_err(&pdev->dev, "No IRQs specified");
-		ret = -ENODEV;
-		goto out1;
+		return -ENODEV;
 	}
 
 	ret = iio_bfin_tmr_get_number(st->irq);
 	if (ret < 0)
-		goto out1;
+		return ret;
 
 	st->timer_num = ret;
 	st->t = &iio_bfin_timer_code[st->timer_num];
 
 	st->trig = iio_trigger_alloc("bfintmr%d", st->timer_num);
-	if (!st->trig) {
-		ret = -ENOMEM;
-		goto out1;
-	}
+	if (!st->trig)
+		return -ENOMEM;
 
 	st->trig->ops = &iio_bfin_tmr_trigger_ops;
 	st->trig->dev.groups = iio_bfin_tmr_trigger_attr_groups;
 	iio_trigger_set_drvdata(st->trig, st);
 	ret = iio_trigger_register(st->trig);
 	if (ret)
-		goto out2;
+		goto out;
 
 	ret = request_irq(st->irq, iio_bfin_tmr_trigger_isr,
 			  0, st->trig->name, st);
 	if (ret) {
 		dev_err(&pdev->dev,
 			"request IRQ-%d failed", st->irq);
-		goto out4;
+		goto out1;
 	}
 
 	config = PWM_OUT | PERIOD_CNT | IRQ_ENA;
@@ -260,13 +255,10 @@ static int iio_bfin_tmr_trigger_probe(struct platform_device *pdev)
 	return 0;
 out_free_irq:
 	free_irq(st->irq, st);
-out4:
-	iio_trigger_unregister(st->trig);
-out2:
-	iio_trigger_put(st->trig);
 out1:
-	kfree(st);
+	iio_trigger_unregister(st->trig);
 out:
+	iio_trigger_put(st->trig);
 	return ret;
 }
 
@@ -280,7 +272,6 @@ static int iio_bfin_tmr_trigger_remove(struct platform_device *pdev)
 	free_irq(st->irq, st);
 	iio_trigger_unregister(st->trig);
 	iio_trigger_put(st->trig);
-	kfree(st);
 
 	return 0;
 }
Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 5 lines · Himangi Saraogi

This patch introduces the use of the managed version of kzalloc and removes the kfrees in the probe and remove functions. More return paths are added and the labels are renamed to order them.

Looks sane, but I'd like an ack or reviewed-by from someone as Analog for this one. cc'd Lars and Michael.

Quoted 90 lines

---
v2: add more return paths
Not compile tested.

  drivers/staging/iio/trigger/iio-trig-bfin-timer.c | 31 ++++++++---------------
  1 file changed, 11 insertions(+), 20 deletions(-)
drivers/staging/iio/trigger/iio-trig-bfin-timer.c +11 -20
index 16f1a06..a21b7c5 100644
@@ -182,45 +182,40 @@ static int iio_bfin_tmr_trigger_probe(struct platform_device *pdev)
  	unsigned int config;
  	int ret;
 
-	st = kzalloc(sizeof(*st), GFP_KERNEL);
-	if (st == NULL) {
-		ret = -ENOMEM;
-		goto out;
-	}
+	st = devm_kzalloc(&pdev->dev, sizeof(*st), GFP_KERNEL);
+	if (st == NULL)
+		return -ENOMEM;
 
  	st->irq = platform_get_irq(pdev, 0);
  	if (!st->irq) {
  		dev_err(&pdev->dev, "No IRQs specified");
-		ret = -ENODEV;
-		goto out1;
+		return -ENODEV;
  	}
 
  	ret = iio_bfin_tmr_get_number(st->irq);
  	if (ret < 0)
-		goto out1;
+		return ret;
 
  	st->timer_num = ret;
  	st->t = &iio_bfin_timer_code[st->timer_num];
 
  	st->trig = iio_trigger_alloc("bfintmr%d", st->timer_num);
-	if (!st->trig) {
-		ret = -ENOMEM;
-		goto out1;
-	}
+	if (!st->trig)
+		return -ENOMEM;
 
  	st->trig->ops = &iio_bfin_tmr_trigger_ops;
  	st->trig->dev.groups = iio_bfin_tmr_trigger_attr_groups;
  	iio_trigger_set_drvdata(st->trig, st);
  	ret = iio_trigger_register(st->trig);
  	if (ret)
-		goto out2;
+		goto out;
 
  	ret = request_irq(st->irq, iio_bfin_tmr_trigger_isr,
  			  0, st->trig->name, st);
  	if (ret) {
  		dev_err(&pdev->dev,
  			"request IRQ-%d failed", st->irq);
-		goto out4;
+		goto out1;
  	}
 
  	config = PWM_OUT | PERIOD_CNT | IRQ_ENA;
@@ -260,13 +255,10 @@ static int iio_bfin_tmr_trigger_probe(struct platform_device *pdev)
  	return 0;
  out_free_irq:
  	free_irq(st->irq, st);
-out4:
-	iio_trigger_unregister(st->trig);
-out2:
-	iio_trigger_put(st->trig);
  out1:
-	kfree(st);
+	iio_trigger_unregister(st->trig);
  out:
+	iio_trigger_put(st->trig);
  	return ret;
  }
 
@@ -280,7 +272,6 @@ static int iio_bfin_tmr_trigger_remove(struct platform_device *pdev)
  	free_irq(st->irq, st);
  	iio_trigger_unregister(st->trig);
  	iio_trigger_put(st->trig);
-	kfree(st);
 
  	return 0;
  }
#2 lore raw
Quoted 9 lines · Jonathan Cameron
Quoted 5 lines · Himangi Saraogi

This patch introduces the use of the managed version of kzalloc and removes the kfrees in the probe and remove functions. More return paths are added and the labels are renamed to order them.

Looks sane, but I'd like an ack or reviewed-by from someone as Analog for this one.
cc'd Lars and Michael.

Thanks.

maintainer Applied
#3 lore raw
Quoted 6 lines · Lars-Peter Clausen
Quoted 5 lines · Jonathan Cameron
Quoted 4 lines · Himangi Saraogi

This patch introduces the use of the managed version of kzalloc and removes the kfrees in the probe and remove functions. More return paths are added and the labels are renamed to order them.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Looks sane, but I'd like an ack or reviewed-by from someone as Analog for this one.
cc'd Lars and Michael.

Applied to the togreg branch of iio.git

Thanks,

Jonathan

Quoted 7 lines

Thanks.

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
In reply to Jonathan Cameron
Quoted 9 lines · Jonathan Cameron
Quoted 5 lines · Himangi Saraogi

This patch introduces the use of the managed version of kzalloc and removes the kfrees in the probe and remove functions. More return paths are added and the labels are renamed to order them.

Looks sane, but I'd like an ack or reviewed-by from someone as Analog for this one.
cc'd Lars and Michael.

Should MAINTAINERS be updated somehow?

julia

Quoted 98 lines
Quoted 96 lines

---
v2: add more return paths
Not compile tested.

  drivers/staging/iio/trigger/iio-trig-bfin-timer.c | 31
++++++++---------------
  1 file changed, 11 insertions(+), 20 deletions(-)
drivers/staging/iio/trigger/iio-trig-bfin-timer.c +9 -14
index 16f1a06..a21b7c5 100644
@@ -182,45 +182,40 @@ static int iio_bfin_tmr_trigger_probe(struct
 platform_device *pdev)
  	unsigned int config;
  	int ret;
 
-	st = kzalloc(sizeof(*st), GFP_KERNEL);
-	if (st == NULL) {
-		ret = -ENOMEM;
-		goto out;
-	}
+	st = devm_kzalloc(&pdev->dev, sizeof(*st), GFP_KERNEL);
+	if (st == NULL)
+		return -ENOMEM;
 
  	st->irq = platform_get_irq(pdev, 0);
  	if (!st->irq) {
  		dev_err(&pdev->dev, "No IRQs specified");
-		ret = -ENODEV;
-		goto out1;
+		return -ENODEV;
  	}
 
  	ret = iio_bfin_tmr_get_number(st->irq);
  	if (ret < 0)
-		goto out1;
+		return ret;
 
  	st->timer_num = ret;
  	st->t = &iio_bfin_timer_code[st->timer_num];
 
  	st->trig = iio_trigger_alloc("bfintmr%d", st->timer_num);
-	if (!st->trig) {
-		ret = -ENOMEM;
-		goto out1;
-	}
+	if (!st->trig)
+		return -ENOMEM;
 
  	st->trig->ops = &iio_bfin_tmr_trigger_ops;
  	st->trig->dev.groups = iio_bfin_tmr_trigger_attr_groups;
  	iio_trigger_set_drvdata(st->trig, st);
  	ret = iio_trigger_register(st->trig);
  	if (ret)
-		goto out2;
+		goto out;
 
  	ret = request_irq(st->irq, iio_bfin_tmr_trigger_isr,
  			  0, st->trig->name, st);
  	if (ret) {
  		dev_err(&pdev->dev,
  			"request IRQ-%d failed", st->irq);
-		goto out4;
+		goto out1;
  	}
 
  	config = PWM_OUT | PERIOD_CNT | IRQ_ENA;
drivers/staging/iio/trigger/iio-trig-bfin-timer.c +2 -6
@@ -260,13 +255,10 @@ static int iio_bfin_tmr_trigger_probe(struct
 platform_device *pdev)
  	return 0;
  out_free_irq:
  	free_irq(st->irq, st);
-out4:
-	iio_trigger_unregister(st->trig);
-out2:
-	iio_trigger_put(st->trig);
  out1:
-	kfree(st);
+	iio_trigger_unregister(st->trig);
  out:
+	iio_trigger_put(st->trig);
  	return ret;
  }
@@ -280,7 +272,6 @@ static int iio_bfin_tmr_trigger_remove(struct
 platform_device *pdev)
  	free_irq(st->irq, st);
  	iio_trigger_unregister(st->trig);
  	iio_trigger_put(st->trig);
-	kfree(st);
 
  	return 0;
  }
#5 lore raw
Quoted 7 lines · Julia Lawall
Quoted 5 lines · Jonathan Cameron
Quoted 4 lines · Himangi Saraogi

This patch introduces the use of the managed version of kzalloc and removes the kfrees in the probe and remove functions. More return paths are added and the labels are renamed to order them.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Looks sane, but I'd like an ack or reviewed-by from someone as Analog for this one.
cc'd Lars and Michael.

Should MAINTAINERS be updated somehow?

julia

yea, it's been on my todo list for a while.