aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLee Jones <lee.jones@linaro.org>2013-07-19 09:19:58 -0400
committerLee Jones <lee.jones@linaro.org>2013-09-02 05:22:46 -0400
commit02a0bf6e351de6bcda4ddeeb2af34197a4e6d591 (patch)
treecb00fb213948d9e5df867dffa4543b2b8cd573f3
parentd551c4c43ccac3ef272e10ac23a64eaac16c23fd (diff)
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>
-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 b7cf98f75e7c..d5966e6b5a7d 100644
--- a/drivers/mfd/ucb1x00-core.c
+++ b/drivers/mfd/ucb1x00-core.c
@@ -393,22 +393,24 @@ static struct irq_chip ucb1x00_irqchip = {
393static int ucb1x00_add_dev(struct ucb1x00 *ucb, struct ucb1x00_driver *drv) 393static int ucb1x00_add_dev(struct ucb1x00 *ucb, struct ucb1x00_driver *drv)
394{ 394{
395 struct ucb1x00_dev *dev; 395 struct ucb1x00_dev *dev;
396 int ret = -ENOMEM; 396 int ret;
397 397
398 dev = kmalloc(sizeof(struct ucb1x00_dev), GFP_KERNEL); 398 dev = kmalloc(sizeof(struct ucb1x00_dev), GFP_KERNEL);
399 if (dev) { 399 if (!dev)
400 dev->ucb = ucb; 400 return -ENOMEM;
401 dev->drv = drv; 401
402 402 dev->ucb = ucb;
403 ret = drv->add(dev); 403 dev->drv = drv;
404 404
405 if (ret == 0) { 405 ret = drv->add(dev);
406 list_add_tail(&dev->dev_node, &ucb->devs); 406 if (ret) {
407 list_add_tail(&dev->drv_node, &drv->devs); 407 kfree(dev);
408 } else { 408 return ret;
409 kfree(dev);
410 }
411 } 409 }
410
411 list_add_tail(&dev->dev_node, &ucb->devs);
412 list_add_tail(&dev->drv_node, &drv->devs);
413
412 return ret; 414 return ret;
413} 415}
414 416