aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd
diff options
context:
space:
mode:
authorLee Jones <lee.jones@linaro.org>2013-07-19 14:19:58 +0100
committerLee Jones <lee.jones@linaro.org>2013-09-02 10:22:46 +0100
commit02a0bf6e351de6bcda4ddeeb2af34197a4e6d591 (patch)
treecb00fb213948d9e5df867dffa4543b2b8cd573f3 /drivers/mfd
parentd551c4c43ccac3ef272e10ac23a64eaac16c23fd (diff)
downloadkernel_goldelico_gta04-02a0bf6e351de6bcda4ddeeb2af34197a4e6d591.zip
kernel_goldelico_gta04-02a0bf6e351de6bcda4ddeeb2af34197a4e6d591.tar.gz
kernel_goldelico_gta04-02a0bf6e351de6bcda4ddeeb2af34197a4e6d591.tar.bz2
mfd: ucb1x00-core: Rewrite ucb1x00_add_dev()
Error handling is on-its-head in this function. After invoking a function we should examine the return code and return the error value if there was one. Instead, this function checks for success and goes onto provide functionality if success was received. Not so bad in a simple function like this, but in a more complex one this could end up drowning in curly brackets. Signed-off-by: Lee Jones <lee.jones@linaro.org>
Diffstat (limited to 'drivers/mfd')
-rw-r--r--drivers/mfd/ucb1x00-core.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/drivers/mfd/ucb1x00-core.c b/drivers/mfd/ucb1x00-core.c
index b7cf98f..d5966e6 100644
--- a/drivers/mfd/ucb1x00-core.c
+++ b/drivers/mfd/ucb1x00-core.c
@@ -393,22 +393,24 @@ static struct irq_chip ucb1x00_irqchip = {
static int ucb1x00_add_dev(struct ucb1x00 *ucb, struct ucb1x00_driver *drv)
{
struct ucb1x00_dev *dev;
- int ret = -ENOMEM;
+ int ret;
dev = kmalloc(sizeof(struct ucb1x00_dev), GFP_KERNEL);
- if (dev) {
- dev->ucb = ucb;
- dev->drv = drv;
-
- ret = drv->add(dev);
-
- if (ret == 0) {
- list_add_tail(&dev->dev_node, &ucb->devs);
- list_add_tail(&dev->drv_node, &drv->devs);
- } else {
- kfree(dev);
- }
+ if (!dev)
+ return -ENOMEM;
+
+ dev->ucb = ucb;
+ dev->drv = drv;
+
+ ret = drv->add(dev);
+ if (ret) {
+ kfree(dev);
+ return ret;
}
+
+ list_add_tail(&dev->dev_node, &ucb->devs);
+ list_add_tail(&dev->drv_node, &drv->devs);
+
return ret;
}