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-prev] [thread-next>] [day] [month] [year] [list]
Message-id: <1465465471-28740-3-git-send-email-k.kozlowski@samsung.com>
Date:	Thu, 09 Jun 2016 11:44:19 +0200
From:	Krzysztof Kozlowski <k.kozlowski@...sung.com>
To:	Ulf Hansson <ulf.hansson@...aro.org>,
	Rob Herring <robh+dt@...nel.org>,
	Pawel Moll <pawel.moll@....com>,
	Mark Rutland <mark.rutland@....com>,
	Ian Campbell <ijc+devicetree@...lion.org.uk>,
	Kumar Gala <galak@...eaurora.org>,
	Krzysztof Kozlowski <k.kozlowski@...sung.com>,
	Sebastian Reichel <sre@...nel.org>,
	Dmitry Eremin-Solenikov <dbaryshkov@...il.com>,
	David Woodhouse <dwmw2@...radead.org>,
	Liam Girdwood <lgirdwood@...il.com>,
	Mark Brown <broonie@...nel.org>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Hans de Goede <hdegoede@...hat.com>,
	Jean-Christophe Plagniol-Villard <plagnioj@...osoft.com>,
	Tomi Valkeinen <tomi.valkeinen@...com>,
	Heiko Stuebner <heiko@...ech.de>, linux-mmc@...r.kernel.org,
	devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
	linux-arm-kernel@...ts.infradead.org,
	linux-samsung-soc@...r.kernel.org, linux-pm@...r.kernel.org,
	linux-usb@...r.kernel.org, linux-fbdev@...r.kernel.org,
	hzpeterchen@...il.com
Cc:	Bartlomiej Zolnierkiewicz <b.zolnierkie@...sung.com>
Subject: [RFC v4 02/14] simplefb: Use new devm_of_regulator_all_get helper and
 bulk API

Switch from manual way of getting all regulators to usage of
devm_of_regulator_all_get().  Additionally use the regulator bulk API
which changes the logic in case of failure of regulator enable.  Before
if regulator_enable() returned error for one regulator, rest of them
were still enabled.  The bulk API does everything atomically.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@...sung.com>

---

Not tested.
---
 drivers/video/fbdev/simplefb.c | 71 +++++++++---------------------------------
 1 file changed, 14 insertions(+), 57 deletions(-)

diff --git a/drivers/video/fbdev/simplefb.c b/drivers/video/fbdev/simplefb.c
index e9cf19977285..897b95efa40d 100644
--- a/drivers/video/fbdev/simplefb.c
+++ b/drivers/video/fbdev/simplefb.c
@@ -32,6 +32,7 @@
 #include <linux/of_platform.h>
 #include <linux/parser.h>
 #include <linux/regulator/consumer.h>
+#include <linux/regulator/of_regulator.h>
 
 static struct fb_fix_screeninfo simplefb_fix = {
 	.id		= "simple",
@@ -178,8 +179,8 @@ struct simplefb_par {
 	struct clk **clks;
 #endif
 #if defined CONFIG_OF && defined CONFIG_REGULATOR
-	u32 regulator_count;
-	struct regulator **regulators;
+	unsigned int regulator_count;
+	struct regulator_bulk_data *regulators;
 #endif
 };
 
@@ -278,8 +279,6 @@ static void simplefb_clocks_destroy(struct simplefb_par *par) { }
 
 #if defined CONFIG_OF && defined CONFIG_REGULATOR
 
-#define SUPPLY_SUFFIX "-supply"
-
 /*
  * Regulator handling code.
  *
@@ -303,61 +302,23 @@ static int simplefb_regulators_init(struct simplefb_par *par,
 	struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
-	struct property *prop;
-	struct regulator *regulator;
-	const char *p;
-	int count = 0, i = 0, ret;
+	int ret;
 
 	if (dev_get_platdata(&pdev->dev) || !np)
 		return 0;
 
-	/* Count the number of regulator supplies */
-	for_each_property_of_node(np, prop) {
-		p = strstr(prop->name, SUPPLY_SUFFIX);
-		if (p && p != prop->name)
-			count++;
-	}
-
-	if (!count)
+	ret = devm_of_regulator_all_get(&pdev->dev, &par->regulator_count, &par->regulators);
+	if (ret)
+		return ret;
+	else if (!par->regulator_count)
 		return 0;
 
-	par->regulators = devm_kcalloc(&pdev->dev, count,
-				       sizeof(struct regulator *), GFP_KERNEL);
-	if (!par->regulators)
-		return -ENOMEM;
-
-	/* Get all the regulators */
-	for_each_property_of_node(np, prop) {
-		char name[32]; /* 32 is max size of property name */
-
-		p = strstr(prop->name, SUPPLY_SUFFIX);
-		if (!p || p == prop->name)
-			continue;
-
-		strlcpy(name, prop->name,
-			strlen(prop->name) - strlen(SUPPLY_SUFFIX) + 1);
-		regulator = devm_regulator_get_optional(&pdev->dev, name);
-		if (IS_ERR(regulator)) {
-			if (PTR_ERR(regulator) == -EPROBE_DEFER)
-				return -EPROBE_DEFER;
-			dev_err(&pdev->dev, "regulator %s not found: %ld\n",
-				name, PTR_ERR(regulator));
-			continue;
-		}
-		par->regulators[i++] = regulator;
-	}
-	par->regulator_count = i;
-
 	/* Enable all the regulators */
-	for (i = 0; i < par->regulator_count; i++) {
-		ret = regulator_enable(par->regulators[i]);
-		if (ret) {
-			dev_err(&pdev->dev,
-				"failed to enable regulator %d: %d\n",
-				i, ret);
-			devm_regulator_put(par->regulators[i]);
-			par->regulators[i] = NULL;
-		}
+	ret = regulator_bulk_enable(par->regulator_count, par->regulators);
+	if (ret) {
+		dev_err(&pdev->dev,
+			"failed to enable regulators: %d\n", ret);
+		return ret;
 	}
 
 	return 0;
@@ -365,14 +326,10 @@ static int simplefb_regulators_init(struct simplefb_par *par,
 
 static void simplefb_regulators_destroy(struct simplefb_par *par)
 {
-	int i;
-
 	if (!par->regulators)
 		return;
 
-	for (i = 0; i < par->regulator_count; i++)
-		if (par->regulators[i])
-			regulator_disable(par->regulators[i]);
+	regulator_bulk_disable(par->regulator_count, par->regulators);
 }
 #else
 static int simplefb_regulators_init(struct simplefb_par *par,
-- 
1.9.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ