lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 24 Aug 2015 20:05:30 +0800
From:	Peng Fan <van.freenix@...il.com>
To:	linus.walleij@...aro.org, gnurou@...il.com
Cc:	linux-gpio@...r.kernel.org, linux-kernel@...r.kernel.org,
	van.freenix@...il.com
Subject: [PATCH] gpio: gpiolib: use devm_* API to simplify driver code

Use devm_* API to simplify driver code.

Signed-off-by: Peng Fan <van.freenix@...il.com>
Cc: Linus Walleij <linus.walleij@...aro.org>
Cc: Alexandre Courbot <gnurou@...il.com>
---
 drivers/gpio/gpiolib.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 6bc612b..f9470b0 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -243,7 +243,8 @@ int gpiochip_add(struct gpio_chip *chip)
 	int		base = chip->base;
 	struct gpio_desc *descs;
 
-	descs = kcalloc(chip->ngpio, sizeof(descs[0]), GFP_KERNEL);
+	descs = devm_kcalloc(chip->dev, chip->ngpio, sizeof(descs[0]),
+			     GFP_KERNEL);
 	if (!descs)
 		return -ENOMEM;
 
@@ -254,7 +255,7 @@ int gpiochip_add(struct gpio_chip *chip)
 		if (base < 0) {
 			status = base;
 			spin_unlock_irqrestore(&gpio_lock, flags);
-			goto err_free_descs;
+			goto err_descs;
 		}
 		chip->base = base;
 	}
@@ -262,7 +263,7 @@ int gpiochip_add(struct gpio_chip *chip)
 	status = gpiochip_add_to_list(chip);
 	if (status) {
 		spin_unlock_irqrestore(&gpio_lock, flags);
-		goto err_free_descs;
+		goto err_descs;
 	}
 
 	for (id = 0; id < chip->ngpio; id++) {
@@ -308,9 +309,7 @@ err_remove_chip:
 	list_del(&chip->list);
 	spin_unlock_irqrestore(&gpio_lock, flags);
 	chip->desc = NULL;
-err_free_descs:
-	kfree(descs);
-
+err_descs:
 	/* failures here can mean systems won't boot... */
 	pr_err("%s: GPIOs %d..%d (%s) failed to register\n", __func__,
 		chip->base, chip->base + chip->ngpio - 1,
-- 
1.8.4.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ