Skip to contentSkip to conversation

mrf24j40: added device managed APIs

PATCH In review Varka Bhadram 2 participants 3 messages May 29, 2014

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

PATCH v3 1/1 mrf24j40: added device managed APIs

changes since v2:
1. removed unwanted label implementation.

When we use devm_* APIs ,probe() failed also the memory will be freed automatically. Thanks to Alex

-Varka Bhadram

---
 drivers/net/ieee802154/mrf24j40.c |   30 ++++++++++++------------------
 1 file changed, 12 insertions(+), 18 deletions(-)
drivers/net/ieee802154/mrf24j40.c +12 -18
index 78a6552..f2b1345 100644
@@ -618,12 +618,12 @@ static int mrf24j40_probe(struct spi_device *spi)
 
 	printk(KERN_INFO "mrf24j40: probe(). IRQ: %d\n", spi->irq);
 
-	devrec = kzalloc(sizeof(struct mrf24j40), GFP_KERNEL);
+	devrec = devm_kzalloc(&spi->dev, sizeof(struct mrf24j40), GFP_KERNEL);
 	if (!devrec)
-		goto err_devrec;
-	devrec->buf = kzalloc(3, GFP_KERNEL);
+		goto err_ret;
+	devrec->buf = devm_kzalloc(&spi->dev, 3, GFP_KERNEL);
 	if (!devrec->buf)
-		goto err_buf;
+		goto err_ret;
 
 	spi->mode = SPI_MODE_0; /* TODO: Is this appropriate for right here? */
 	if (spi->max_speed_hz > MAX_SPI_SPEED_HZ)
@@ -676,12 +676,13 @@ static int mrf24j40_probe(struct spi_device *spi)
 	val &= ~0x3; /* Clear RX mode (normal) */
 	write_short_reg(devrec, REG_RXMCR, val);
 
-	ret = request_threaded_irq(spi->irq,
-				   NULL,
-				   mrf24j40_isr,
-				   IRQF_TRIGGER_LOW|IRQF_ONESHOT,
-				   dev_name(&spi->dev),
-				   devrec);
+	ret = devm_request_threaded_irq(&spi->dev,
+					spi->irq,
+					NULL,
+					mrf24j40_isr,
+					IRQF_TRIGGER_LOW|IRQF_ONESHOT,
+					dev_name(&spi->dev),
+					devrec);
 
 	if (ret) {
 		dev_err(printdev(devrec), "Unable to get IRQ");
@@ -696,10 +697,7 @@ err_read_reg:
 err_register_device:
 	ieee802154_free_device(devrec->dev);
 err_alloc_dev:
-	kfree(devrec->buf);
-err_buf:
-	kfree(devrec);
-err_devrec:
+err_ret:
 	return ret;
 }
 
@@ -709,15 +707,11 @@ static int mrf24j40_remove(struct spi_device *spi)
 
 	dev_dbg(printdev(devrec), "remove\n");
 
-	free_irq(spi->irq, devrec);
 	ieee802154_unregister_device(devrec->dev);
 	ieee802154_free_device(devrec->dev);
 	/* TODO: Will ieee802154_free_device() wait until ->xmit() is
 	 * complete? */
 
-	/* Clean up the SPI stuff. */
-	kfree(devrec->buf);
-	kfree(devrec);
 	return 0;
 }
 
Signature · 1 line
1.7.9.5
maintainer
#1 lore raw

Hi Varka,

Quoted 9 lines · Varka Bhadram

changes since v2:
1. removed unwanted label implementation.

When we use devm_* APIs ,probe() failed also the memory will be freed automatically. Thanks to Alex

-Varka Bhadram

you should provide a "well" commit msg here. No emotional comments and remove your signature.

Look in linux tree and run "git log" for other commit messages.

Quoted 2 lines

---

if you want to thanks somebody here and tell about the changes since v2 you can put it here, after the "---". This will be ignored while applying your patch.

drivers/net/ieee802154/mrf24j40.c

Quoted 7 lines
 drivers/net/ieee802154/mrf24j40.c |   30 ++++++++++++------------------
 1 file changed, 12 insertions(+), 18 deletions(-)
drivers/net/ieee802154/mrf24j40.c +0 -0
index 78a6552..f2b1345 100644

- Alex

maintainer
#2 lore raw
In reply to Varka Bhadram

Hi Varka,

Quoted 56 lines · Varka Bhadram

changes since v2:
1. removed unwanted label implementation.

When we use devm_* APIs ,probe() failed also the memory will be freed automatically. Thanks to Alex

-Varka Bhadram

---
 drivers/net/ieee802154/mrf24j40.c |   30 ++++++++++++------------------
 1 file changed, 12 insertions(+), 18 deletions(-)
drivers/net/ieee802154/mrf24j40.c +11 -10
index 78a6552..f2b1345 100644
@@ -618,12 +618,12 @@ static int mrf24j40_probe(struct spi_device *spi)
 
 	printk(KERN_INFO "mrf24j40: probe(). IRQ: %d\n", spi->irq);
 
-	devrec = kzalloc(sizeof(struct mrf24j40), GFP_KERNEL);
+	devrec = devm_kzalloc(&spi->dev, sizeof(struct mrf24j40), GFP_KERNEL);
 	if (!devrec)
-		goto err_devrec;
-	devrec->buf = kzalloc(3, GFP_KERNEL);
+		goto err_ret;
+	devrec->buf = devm_kzalloc(&spi->dev, 3, GFP_KERNEL);
 	if (!devrec->buf)
-		goto err_buf;
+		goto err_ret;
 
 	spi->mode = SPI_MODE_0; /* TODO: Is this appropriate for right here? */
 	if (spi->max_speed_hz > MAX_SPI_SPEED_HZ)
@@ -676,12 +676,13 @@ static int mrf24j40_probe(struct spi_device *spi)
 	val &= ~0x3; /* Clear RX mode (normal) */
 	write_short_reg(devrec, REG_RXMCR, val);
 
-	ret = request_threaded_irq(spi->irq,
-				   NULL,
-				   mrf24j40_isr,
-				   IRQF_TRIGGER_LOW|IRQF_ONESHOT,
-				   dev_name(&spi->dev),
-				   devrec);
+	ret = devm_request_threaded_irq(&spi->dev,
+					spi->irq,
+					NULL,
+					mrf24j40_isr,
+					IRQF_TRIGGER_LOW|IRQF_ONESHOT,
+					dev_name(&spi->dev),
+					devrec);
 
 	if (ret) {
 		dev_err(printdev(devrec), "Unable to get IRQ");

drivers/net/ieee802154/mrf24j40.c err_read_reg: · line 702

Quoted 10 lines
drivers/net/ieee802154/mrf24j40.c +1 -4
@@ -696,10 +697,7 @@ err_read_reg:
 err_register_device:
 	ieee802154_free_device(devrec->dev);
 err_alloc_dev:
-	kfree(devrec->buf);
-err_buf:
-	kfree(devrec);
-err_devrec:
+err_ret:
 	return ret;
 }

another point is that you have now two labels for the same jump point.

err_alloc_dev:
err_ret:

- Alex