From: qiwuchen55@gmail.com
To: jacek.anaszewski@gmail.com, pavel@ucw.cz, dmurphy@ti.com
Cc: linux-leds@vger.kernel.org, chenqiwu <chenqiwu@xiaomi.com>
Subject: [PATCH] leds: leds-nic78bx: handle error checking and error processing
Date: Fri, 14 Feb 2020 23:58:36 +0800 [thread overview]
Message-ID: <1581695916-16708-1-git-send-email-qiwuchen55@gmail.com> (raw)
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
next reply other threads:[~2020-02-14 17:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-14 15:58 qiwuchen55 [this message]
2020-04-27 9:56 ` [PATCH] leds: leds-nic78bx: handle error checking and error processing Pavel Machek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1581695916-16708-1-git-send-email-qiwuchen55@gmail.com \
--to=qiwuchen55@gmail.com \
--cc=chenqiwu@xiaomi.com \
--cc=dmurphy@ti.com \
--cc=jacek.anaszewski@gmail.com \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@ucw.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.