Linux-LEDs Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] leds: leds-nic78bx: handle error checking and error processing
@ 2020-02-14 15:58 qiwuchen55
  0 siblings, 0 replies; only message in thread
From: qiwuchen55 @ 2020-02-14 15:58 UTC (permalink / raw)
  To: jacek.anaszewski, pavel, dmurphy; +Cc: linux-leds, chenqiwu

From: chenqiwu <chenqiwu@xiaomi.com>

Add error checking and error processing for led probe.

Signed-off-by: chenqiwu <chenqiwu@xiaomi.com>
---
 drivers/leds/leds-nic78bx.c | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/drivers/leds/leds-nic78bx.c b/drivers/leds/leds-nic78bx.c
index f196f52..cc5adf8 100644
--- a/drivers/leds/leds-nic78bx.c
+++ b/drivers/leds/leds-nic78bx.c
@@ -129,24 +129,24 @@ static int nic78bx_probe(struct platform_device *pdev)
 	if (!led_data)
 		return -ENOMEM;
 
-	led_data->pdev = pdev;
-	platform_set_drvdata(pdev, led_data);
-
 	io_rc = platform_get_resource(pdev, IORESOURCE_IO, 0);
 	if (!io_rc) {
+		ret = -EINVAL;
 		dev_err(dev, "missing IO resources\n");
-		return -EINVAL;
+		goto err_get_res;
 	}
 
 	if (resource_size(io_rc) < NIC78BX_USER_LED_IO_SIZE) {
 		dev_err(dev, "IO region too small\n");
-		return -EINVAL;
+		ret = -EINVAL;
+		goto err_res_size;
 	}
 
 	if (!devm_request_region(dev, io_rc->start, resource_size(io_rc),
 				 KBUILD_MODNAME)) {
+		ret = -EBUSY;
 		dev_err(dev, "failed to get IO region\n");
-		return -EBUSY;
+		goto err_request_region;
 	}
 
 	led_data->io_base = io_rc->start;
@@ -157,13 +157,27 @@ static int nic78bx_probe(struct platform_device *pdev)
 
 		ret = devm_led_classdev_register(dev, &nic78bx_leds[i].cdev);
 		if (ret)
-			return ret;
+			goto err_led_classdev_register;
 	}
 
 	/* Unlock LED register */
 	outb(NIC78BX_UNLOCK_VALUE,
 	     led_data->io_base + NIC78BX_LOCK_REG_OFFSET);
 
+	led_data->pdev = pdev;
+	platform_set_drvdata(pdev, led_data);
+	return 0;
+
+err_led_classdev_register:
+	i -= 1;
+	while (i >= 0)
+		devm_led_classdev_unregister(dev, &nic78bx_leds[i--].cdev);
+	devm_release_region(dev, io_rc->start, resource_size(io_rc));
+err_request_region:
+err_res_size:
+	release_resource(io_rc);
+err_get_res:
+	devm_kfree(dev, led_data);
 	return ret;
 }
 
@@ -171,6 +185,9 @@ static int nic78bx_remove(struct platform_device *pdev)
 {
 	struct nic78bx_led_data *led_data = platform_get_drvdata(pdev);
 
+	if (IS_ERR_OR_NULL(led_data))
+		return PTR_ERR(led_data);
+
 	/* Lock LED register */
 	outb(NIC78BX_LOCK_VALUE,
 	     led_data->io_base + NIC78BX_LOCK_REG_OFFSET);
-- 
1.9.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-14 15:58 [PATCH] leds: leds-nic78bx: handle error checking and error processing qiwuchen55

Linux-LEDs Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-leds/0 linux-leds/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-leds linux-leds/ https://lore.kernel.org/linux-leds \
		linux-leds@vger.kernel.org
	public-inbox-index linux-leds

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-leds


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git