Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1345329 > unrolled thread

[PATCH 5/7] regulator: act8865: Pass of_node via act8865_regulator_data

Started byMaarten ter Huurne <maarten@treewalker.org>
First post2016-02-28 17:00 +0100
Last post2016-02-29 12:40 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 5/7] regulator: act8865: Pass of_node via act8865_regulator_data Maarten ter Huurne <maarten@treewalker.org> - 2016-02-28 17:00 +0100
    Re: [PATCH 5/7] regulator: act8865: Pass of_node via  act8865_regulator_data Mark Brown <broonie@kernel.org> - 2016-02-29 12:40 +0100

#1345329 — [PATCH 5/7] regulator: act8865: Pass of_node via act8865_regulator_data

FromMaarten ter Huurne <maarten@treewalker.org>
Date2016-02-28 17:00 +0100
Subject[PATCH 5/7] regulator: act8865: Pass of_node via act8865_regulator_data
Message-ID<r7bVg-4Ib-11@gated-at.bofh.it>
This makes the code easier to read and it avoids a dynamic memory
allocation.

Note that the "too many regulators" error handler was broken prior
to its removal in this commit, since it dereferenced pdata, which
can be NULL in the non-DT case.

Signed-off-by: Maarten ter Huurne <maarten@treewalker.org>
---
 drivers/regulator/act8865-regulator.c | 42 +++++++++++++----------------------
 include/linux/regulator/act8865.h     |  2 ++
 2 files changed, 18 insertions(+), 26 deletions(-)

diff --git a/drivers/regulator/act8865-regulator.c b/drivers/regulator/act8865-regulator.c
index 0d1b235..cdfe082 100644
--- a/drivers/regulator/act8865-regulator.c
+++ b/drivers/regulator/act8865-regulator.c
@@ -368,7 +368,6 @@ static struct of_regulator_match act8600_matches[] = {
 };
 
 static int act8865_pdata_from_dt(struct device *dev,
-				 struct device_node **of_node,
 				 struct act8865_platform_data *pdata,
 				 unsigned long type)
 {
@@ -419,7 +418,7 @@ static int act8865_pdata_from_dt(struct device *dev,
 		regulator->id = i;
 		regulator->name = matches[i].name;
 		regulator->init_data = matches[i].init_data;
-		of_node[i] = matches[i].of_node;
+		regulator->of_node = matches[i].of_node;
 		regulator++;
 	}
 
@@ -427,7 +426,6 @@ static int act8865_pdata_from_dt(struct device *dev,
 }
 #else
 static inline int act8865_pdata_from_dt(struct device *dev,
-					struct device_node **of_node,
 					struct act8865_platform_data *pdata,
 					unsigned long type)
 {
@@ -435,8 +433,8 @@ static inline int act8865_pdata_from_dt(struct device *dev,
 }
 #endif
 
-static struct regulator_init_data
-*act8865_get_init_data(int id, struct act8865_platform_data *pdata)
+static struct act8865_regulator_data *act8865_get_regulator_data(
+		int id, struct act8865_platform_data *pdata)
 {
 	int i;
 
@@ -445,7 +443,7 @@ static struct regulator_init_data
 
 	for (i = 0; i < pdata->num_regulators; i++) {
 		if (pdata->regulators[i].id == id)
-			return pdata->regulators[i].init_data;
+			return &pdata->regulators[i];
 	}
 
 	return NULL;
@@ -467,7 +465,6 @@ static int act8865_pmic_probe(struct i2c_client *client,
 	const struct regulator_desc *regulators;
 	struct act8865_platform_data pdata_of, *pdata;
 	struct device *dev = &client->dev;
-	struct device_node **of_node;
 	int i, ret, num_regulators;
 	struct act8865 *act8865;
 	struct regmap_config regmap_config = {
@@ -531,25 +528,14 @@ static int act8865_pmic_probe(struct i2c_client *client,
 		return -EINVAL;
 	}
 
-	of_node = devm_kzalloc(dev, sizeof(struct device_node *) *
-			       num_regulators, GFP_KERNEL);
-	if (!of_node)
-		return -ENOMEM;
-
 	if (dev->of_node && !pdata) {
-		ret = act8865_pdata_from_dt(dev, of_node, &pdata_of, type);
+		ret = act8865_pdata_from_dt(dev, &pdata_of, type);
 		if (ret < 0)
 			return ret;
 
 		pdata = &pdata_of;
 	}
 
-	if (pdata->num_regulators > num_regulators) {
-		dev_err(dev, "too many regulators: %d\n",
-			pdata->num_regulators);
-		return -EINVAL;
-	}
-
 	act8865 = devm_kzalloc(dev, sizeof(struct act8865), GFP_KERNEL);
 	if (!act8865)
 		return -ENOMEM;
@@ -575,14 +561,19 @@ static int act8865_pmic_probe(struct i2c_client *client,
 	/* Finally register devices */
 	for (i = 0; i < num_regulators; i++) {
 		const struct regulator_desc *desc = &regulators[i];
-		struct regulator_config config = { };
+		struct regulator_config config = {
+			.dev = dev,
+			.regmap = act8865->regmap,
+			.driver_data = act8865,
+		};
+		struct act8865_regulator_data *rdata;
 		struct regulator_dev *rdev;
 
-		config.dev = dev;
-		config.init_data = act8865_get_init_data(desc->id, pdata);
-		config.of_node = of_node[i];
-		config.driver_data = act8865;
-		config.regmap = act8865->regmap;
+		rdata = act8865_get_regulator_data(desc->id, pdata);
+		if (rdata) {
+			config.init_data = rdata->init_data;
+			config.of_node = rdata->of_node;
+		}
 
 		rdev = devm_regulator_register(dev, desc, &config);
 		if (IS_ERR(rdev)) {
@@ -592,7 +583,6 @@ static int act8865_pmic_probe(struct i2c_client *client,
 	}
 
 	i2c_set_clientdata(client, act8865);
-	devm_kfree(dev, of_node);
 
 	return 0;
 }
diff --git a/include/linux/regulator/act8865.h b/include/linux/regulator/act8865.h
index 2eb3860..113d861 100644
--- a/include/linux/regulator/act8865.h
+++ b/include/linux/regulator/act8865.h
@@ -69,11 +69,13 @@ enum {
  * @id: regulator id
  * @name: regulator name
  * @init_data: regulator init data
+ * @of_node: device tree node (optional)
  */
 struct act8865_regulator_data {
 	int id;
 	const char *name;
 	struct regulator_init_data *init_data;
+	struct device_node *of_node;
 };
 
 /**
-- 
2.6.2

[toc] | [next] | [standalone]


#1345722 — Re: [PATCH 5/7] regulator: act8865: Pass of_node via act8865_regulator_data

FromMark Brown <broonie@kernel.org>
Date2016-02-29 12:40 +0100
SubjectRe: [PATCH 5/7] regulator: act8865: Pass of_node via act8865_regulator_data
Message-ID<r7ulb-2qo-3@gated-at.bofh.it>
In reply to#1345329

[Multipart message — attachments visible in raw view] — view raw

On Sun, Feb 28, 2016 at 04:53:27PM +0100, Maarten ter Huurne wrote:

> +		struct regulator_config config = {
> +			.dev = dev,
> +			.regmap = act8865->regmap,
> +			.driver_data = act8865,
> +		};
> +		struct act8865_regulator_data *rdata;
>  		struct regulator_dev *rdev;
>  
> -		config.dev = dev;
> -		config.init_data = act8865_get_init_data(desc->id, pdata);
> -		config.of_node = of_node[i];
> -		config.driver_data = act8865;
> -		config.regmap = act8865->regmap;

This appears to be doing some unrelated refectoring of the code which
should be in a separate commit to make review clearer.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web