Skip to content

Commit

Permalink
gpio: mockup: code shrink
Browse files Browse the repository at this point in the history
Moving a couple of lines around allows us to shrink the code a bit
while keeping the same functionality.

Signed-off-by: Bartosz Golaszewski <[email protected]>
Signed-off-by: Linus Walleij <[email protected]>
  • Loading branch information
brgl authored and linusw committed Feb 6, 2017
1 parent ca40916 commit e4ba07b
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions drivers/gpio/gpio-mockup.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ static int gpio_mockup_add(struct device *dev,
const char *name, int base, int ngpio)
{
struct gpio_chip *gc = &chip->gc;
int ret;

gc->base = base;
gc->ngpio = ngpio;
Expand All @@ -107,21 +106,10 @@ static int gpio_mockup_add(struct device *dev,

chip->lines = devm_kzalloc(dev, sizeof(*chip->lines) * gc->ngpio,
GFP_KERNEL);
if (!chip->lines) {
ret = -ENOMEM;
goto err;
}

ret = devm_gpiochip_add_data(dev, &chip->gc, chip);
if (ret)
goto err;

dev_info(dev, "gpio<%d..%d> add successful!", base, base + ngpio);
return 0;
if (!chip->lines)
return -ENOMEM;

err:
dev_err(dev, "gpio<%d..%d> add failed!", base, base + ngpio);
return ret;
return devm_gpiochip_add_data(dev, &chip->gc, chip);
}

static int gpio_mockup_probe(struct platform_device *pdev)
Expand Down Expand Up @@ -164,15 +152,14 @@ static int gpio_mockup_probe(struct platform_device *pdev)
}

if (ret) {
if (base < 0)
dev_err(dev, "gpio<%d..%d> add failed\n",
base, ngpio);
else
dev_err(dev, "gpio<%d..%d> add failed\n",
base, base + ngpio);
dev_err(dev, "gpio<%d..%d> add failed\n",
base, base < 0 ? ngpio : base + ngpio);

return ret;
}

dev_info(dev, "gpio<%d..%d> add successful!",
base, base + ngpio);
}

return 0;
Expand Down

0 comments on commit e4ba07b

Please sign in to comment.