Skip to content

Commit

Permalink
mfd: ucb1x00-core: Rewrite ucb1x00_add_dev()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Lee Jones committed Sep 2, 2013
1 parent d551c4c commit 02a0bf6
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions drivers/mfd/ucb1x00-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 02a0bf6

Please sign in to comment.