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


Groups > linux.kernel > #1573471 > unrolled thread

[PATCH 2/5] regulator: core: have regulator_dev_lookup() return ERR_PTR-encoded errors

Started byDmitry Torokhov <dmitry.torokhov@gmail.com>
First post2017-02-03 23:00 +0100
Last post2017-02-06 14:40 +0100
Articles 6 — 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 2/5] regulator: core: have regulator_dev_lookup() return ERR_PTR-encoded errors Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2017-02-03 23:00 +0100
    Re: [PATCH 2/5] regulator: core: have regulator_dev_lookup() return  ERR_PTR-encoded errors Mark Brown <broonie@kernel.org> - 2017-02-04 11:20 +0100
      [PATCH v2 2/5] regulator: core: have regulator_dev_lookup() return  ERR_PTR-encoded errors Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2017-02-04 19:20 +0100
        Re: [PATCH v2 2/5] regulator: core: have regulator_dev_lookup()  return ERR_PTR-encoded errors Mark Brown <broonie@kernel.org> - 2017-02-05 16:00 +0100
        Re: [PATCH v2 2/5] regulator: core: have regulator_dev_lookup()  return ERR_PTR-encoded errors Mark Brown <broonie@kernel.org> - 2017-02-06 00:50 +0100
        Applied "regulator: core: have regulator_dev_lookup() return ERR_PTR-encoded errors" to the regulator tree Mark Brown <broonie@kernel.org> - 2017-02-06 14:40 +0100

#1573471 — [PATCH 2/5] regulator: core: have regulator_dev_lookup() return ERR_PTR-encoded errors

FromDmitry Torokhov <dmitry.torokhov@gmail.com>
Date2017-02-03 23:00 +0100
Subject[PATCH 2/5] regulator: core: have regulator_dev_lookup() return ERR_PTR-encoded errors
Message-ID<t6U3E-7uQ-23@gated-at.bofh.it>
Instead of returning both regulator_dev structure as return value and
auxiliary error code in 'ret' argument, let's switch to using ERR_PTR
encoded values. This makes it more obvious what is going on at call sites.

Also, let's not unlock the mutex in the middle of a loop, but rather break
out and have single unlock path.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/regulator/core.c | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index b0ee068310c5..25aca2096ac9 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1455,12 +1455,14 @@ static struct regulator_dev *regulator_lookup_by_name(const char *name)
  * lookup could succeed in the future.
  *
  * If successful, returns a struct regulator_dev that corresponds to the name
- * @supply and with the embedded struct device refcount incremented by one,
- * or NULL on failure. The refcount must be dropped by calling put_device().
+ * @supply and with the embedded struct device refcount incremented by one.
+ * The refcount must be dropped by calling put_device().
+ * On failure one of the following ERR-PTR-encoded values is returned:
+ * -ENODEV if lookup fails permanently, -EPROBE_DEFER if lookup could succeed
+ * in the future.
  */
 static struct regulator_dev *regulator_dev_lookup(struct device *dev,
-						  const char *supply,
-						  int *ret)
+						  const char *supply)
 {
 	struct regulator_dev *r;
 	struct device_node *node;
@@ -1476,16 +1478,12 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev,
 			r = of_find_regulator_by_node(node);
 			if (r)
 				return r;
-			*ret = -EPROBE_DEFER;
-			return NULL;
-		} else {
+
 			/*
-			 * If we couldn't even get the node then it's
-			 * not just that the device didn't register
-			 * yet, there's no node and we'll never
-			 * succeed.
+			 * We have a node, but there is no device.
+			 * assume it has not registered yet.
 			 */
-			*ret = -ENODEV;
+			return ERR_PTR(-EPROBE_DEFER);
 		}
 	}
 
@@ -1506,13 +1504,13 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev,
 
 		if (strcmp(map->supply, supply) == 0 &&
 		    get_device(&map->regulator->dev)) {
-			mutex_unlock(&regulator_list_mutex);
-			return map->regulator;
+			r = map->regulator;
+			break;
 		}
 	}
 	mutex_unlock(&regulator_list_mutex);
 
-	return NULL;
+	return r ? r : ERR_PTR(-ENODEV);
 }
 
 static int regulator_resolve_supply(struct regulator_dev *rdev)
@@ -1529,8 +1527,10 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
 	if (rdev->supply)
 		return 0;
 
-	r = regulator_dev_lookup(dev, rdev->supply_name, &ret);
-	if (!r) {
+	r = regulator_dev_lookup(dev, rdev->supply_name);
+	if (IS_ERR(r)) {
+		ret = PTR_ERR(r);
+
 		if (ret == -ENODEV) {
 			/*
 			 * No supply was specified for this regulator and
@@ -1596,10 +1596,11 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
 	if (dev)
 		devname = dev_name(dev);
 
-	rdev = regulator_dev_lookup(dev, id, &ret);
-	if (rdev)
+	rdev = regulator_dev_lookup(dev, id);
+	if (!IS_ERR(rdev))
 		goto found;
 
+	ret = PTR_ERR(rdev);
 	regulator = ERR_PTR(ret);
 
 	/*
-- 
2.11.0.483.g087da7b7c-goog

[toc] | [next] | [standalone]


#1573635 — Re: [PATCH 2/5] regulator: core: have regulator_dev_lookup() return ERR_PTR-encoded errors

FromMark Brown <broonie@kernel.org>
Date2017-02-04 11:20 +0100
SubjectRe: [PATCH 2/5] regulator: core: have regulator_dev_lookup() return ERR_PTR-encoded errors
Message-ID<t75BM-7td-13@gated-at.bofh.it>
In reply to#1573471

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

On Fri, Feb 03, 2017 at 01:56:01PM -0800, Dmitry Torokhov wrote:

> -	return NULL;
> +	return r ? r : ERR_PTR(-ENODEV);
>  }

Please write normal conditional statements to keep the code legible.

[toc] | [prev] | [next] | [standalone]


#1573724 — [PATCH v2 2/5] regulator: core: have regulator_dev_lookup() return ERR_PTR-encoded errors

FromDmitry Torokhov <dmitry.torokhov@gmail.com>
Date2017-02-04 19:20 +0100
Subject[PATCH v2 2/5] regulator: core: have regulator_dev_lookup() return ERR_PTR-encoded errors
Message-ID<t7d6h-4jT-3@gated-at.bofh.it>
In reply to#1573635
Instead of returning both regulator_dev structure as return value and
auxiliary error code in 'ret' argument, let's switch to using ERR_PTR
encoded values. This makes it more obvious what is going on at call sites.

Also, let's not unlock the mutex in the middle of a loop, but rather break
out and have single unlock path.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---

V2: replaced "return r ? r : ERR_PTR(-ENODEV);" with expanded "if"
statement.

 drivers/regulator/core.c |   42 +++++++++++++++++++++++-------------------
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index b0ee068310c5..a39268bcab56 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1455,12 +1455,14 @@ static struct regulator_dev *regulator_lookup_by_name(const char *name)
  * lookup could succeed in the future.
  *
  * If successful, returns a struct regulator_dev that corresponds to the name
- * @supply and with the embedded struct device refcount incremented by one,
- * or NULL on failure. The refcount must be dropped by calling put_device().
+ * @supply and with the embedded struct device refcount incremented by one.
+ * The refcount must be dropped by calling put_device().
+ * On failure one of the following ERR-PTR-encoded values is returned:
+ * -ENODEV if lookup fails permanently, -EPROBE_DEFER if lookup could succeed
+ * in the future.
  */
 static struct regulator_dev *regulator_dev_lookup(struct device *dev,
-						  const char *supply,
-						  int *ret)
+						  const char *supply)
 {
 	struct regulator_dev *r;
 	struct device_node *node;
@@ -1476,16 +1478,12 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev,
 			r = of_find_regulator_by_node(node);
 			if (r)
 				return r;
-			*ret = -EPROBE_DEFER;
-			return NULL;
-		} else {
+
 			/*
-			 * If we couldn't even get the node then it's
-			 * not just that the device didn't register
-			 * yet, there's no node and we'll never
-			 * succeed.
+			 * We have a node, but there is no device.
+			 * assume it has not registered yet.
 			 */
-			*ret = -ENODEV;
+			return ERR_PTR(-EPROBE_DEFER);
 		}
 	}
 
@@ -1506,13 +1504,16 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev,
 
 		if (strcmp(map->supply, supply) == 0 &&
 		    get_device(&map->regulator->dev)) {
-			mutex_unlock(&regulator_list_mutex);
-			return map->regulator;
+			r = map->regulator;
+			break;
 		}
 	}
 	mutex_unlock(&regulator_list_mutex);
 
-	return NULL;
+	if (r)
+		return r;
+
+	return ERR_PTR(-ENODEV);
 }
 
 static int regulator_resolve_supply(struct regulator_dev *rdev)
@@ -1529,8 +1530,10 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
 	if (rdev->supply)
 		return 0;
 
-	r = regulator_dev_lookup(dev, rdev->supply_name, &ret);
-	if (!r) {
+	r = regulator_dev_lookup(dev, rdev->supply_name);
+	if (IS_ERR(r)) {
+		ret = PTR_ERR(r);
+
 		if (ret == -ENODEV) {
 			/*
 			 * No supply was specified for this regulator and
@@ -1596,10 +1599,11 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
 	if (dev)
 		devname = dev_name(dev);
 
-	rdev = regulator_dev_lookup(dev, id, &ret);
-	if (rdev)
+	rdev = regulator_dev_lookup(dev, id);
+	if (!IS_ERR(rdev))
 		goto found;
 
+	ret = PTR_ERR(rdev);
 	regulator = ERR_PTR(ret);
 
 	/*

[toc] | [prev] | [next] | [standalone]


#1573884 — Re: [PATCH v2 2/5] regulator: core: have regulator_dev_lookup() return ERR_PTR-encoded errors

FromMark Brown <broonie@kernel.org>
Date2017-02-05 16:00 +0100
SubjectRe: [PATCH v2 2/5] regulator: core: have regulator_dev_lookup() return ERR_PTR-encoded errors
Message-ID<t7wsi-eB-11@gated-at.bofh.it>
In reply to#1573724

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

On Sat, Feb 04, 2017 at 10:19:21AM -0800, Dmitry Torokhov wrote:

> V2: replaced "return r ? r : ERR_PTR(-ENODEV);" with expanded "if"
> statement.

Please don't send new versions of patches as replies into the middle of
existing patch serieses, especially not by replying to individual
patches and even especially when bits of the earlier series have been
applied.  This just makes everything much more difficult to follow -
looking at an archive of the list it's hard to tell what the current
version of the series is and if old bits of the series aren't there the
numbering within the series you posted gets broken as there are missing
patches.

[toc] | [prev] | [next] | [standalone]


#1574310 — Re: [PATCH v2 2/5] regulator: core: have regulator_dev_lookup() return ERR_PTR-encoded errors

FromMark Brown <broonie@kernel.org>
Date2017-02-06 00:50 +0100
SubjectRe: [PATCH v2 2/5] regulator: core: have regulator_dev_lookup() return ERR_PTR-encoded errors
Message-ID<t7EJb-5x1-11@gated-at.bofh.it>
In reply to#1573724

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

On Sat, Feb 04, 2017 at 10:19:21AM -0800, Dmitry Torokhov wrote:
> Instead of returning both regulator_dev structure as return value and
> auxiliary error code in 'ret' argument, let's switch to using ERR_PTR
> encoded values. This makes it more obvious what is going on at call sites.

I did apply this but GNOME has decided to try to force gnome-keyring's
SSH agent on us with renewed force so until I fix that I can't use the
key on my smartcard to 2FA or push to kernel.org :/  It'll appear some
time tomorrow hopefully.

[toc] | [prev] | [next] | [standalone]


#1574716 — Applied "regulator: core: have regulator_dev_lookup() return ERR_PTR-encoded errors" to the regulator tree

FromMark Brown <broonie@kernel.org>
Date2017-02-06 14:40 +0100
SubjectApplied "regulator: core: have regulator_dev_lookup() return ERR_PTR-encoded errors" to the regulator tree
Message-ID<t7RGt-5x6-91@gated-at.bofh.it>
In reply to#1573724
The patch

   regulator: core: have regulator_dev_lookup() return ERR_PTR-encoded errors

has been applied to the regulator tree at

   git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

From 163478dae0b6ce2437488e54012705b53ef43f3d Mon Sep 17 00:00:00 2001
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Date: Sat, 4 Feb 2017 10:19:21 -0800
Subject: [PATCH] regulator: core: have regulator_dev_lookup() return
 ERR_PTR-encoded errors

Instead of returning both regulator_dev structure as return value and
auxiliary error code in 'ret' argument, let's switch to using ERR_PTR
encoded values. This makes it more obvious what is going on at call sites.

Also, let's not unlock the mutex in the middle of a loop, but rather break
out and have single unlock path.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 drivers/regulator/core.c | 42 +++++++++++++++++++++++-------------------
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 867756651544..3e246c82939d 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1455,12 +1455,14 @@ static struct regulator_dev *regulator_lookup_by_name(const char *name)
  * lookup could succeed in the future.
  *
  * If successful, returns a struct regulator_dev that corresponds to the name
- * @supply and with the embedded struct device refcount incremented by one,
- * or NULL on failure. The refcount must be dropped by calling put_device().
+ * @supply and with the embedded struct device refcount incremented by one.
+ * The refcount must be dropped by calling put_device().
+ * On failure one of the following ERR-PTR-encoded values is returned:
+ * -ENODEV if lookup fails permanently, -EPROBE_DEFER if lookup could succeed
+ * in the future.
  */
 static struct regulator_dev *regulator_dev_lookup(struct device *dev,
-						  const char *supply,
-						  int *ret)
+						  const char *supply)
 {
 	struct regulator_dev *r;
 	struct device_node *node;
@@ -1476,16 +1478,12 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev,
 			r = of_find_regulator_by_node(node);
 			if (r)
 				return r;
-			*ret = -EPROBE_DEFER;
-			return NULL;
-		} else {
+
 			/*
-			 * If we couldn't even get the node then it's
-			 * not just that the device didn't register
-			 * yet, there's no node and we'll never
-			 * succeed.
+			 * We have a node, but there is no device.
+			 * assume it has not registered yet.
 			 */
-			*ret = -ENODEV;
+			return ERR_PTR(-EPROBE_DEFER);
 		}
 	}
 
@@ -1506,13 +1504,16 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev,
 
 		if (strcmp(map->supply, supply) == 0 &&
 		    get_device(&map->regulator->dev)) {
-			mutex_unlock(&regulator_list_mutex);
-			return map->regulator;
+			r = map->regulator;
+			break;
 		}
 	}
 	mutex_unlock(&regulator_list_mutex);
 
-	return NULL;
+	if (r)
+		return r;
+
+	return ERR_PTR(-ENODEV);
 }
 
 static int regulator_resolve_supply(struct regulator_dev *rdev)
@@ -1529,8 +1530,10 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
 	if (rdev->supply)
 		return 0;
 
-	r = regulator_dev_lookup(dev, rdev->supply_name, &ret);
-	if (!r) {
+	r = regulator_dev_lookup(dev, rdev->supply_name);
+	if (IS_ERR(r)) {
+		ret = PTR_ERR(r);
+
 		if (ret == -ENODEV) {
 			/*
 			 * No supply was specified for this regulator and
@@ -1601,10 +1604,11 @@ struct regulator *_regulator_get(struct device *dev, const char *id,
 	if (dev)
 		devname = dev_name(dev);
 
-	rdev = regulator_dev_lookup(dev, id, &ret);
-	if (rdev)
+	rdev = regulator_dev_lookup(dev, id);
+	if (!IS_ERR(rdev))
 		goto found;
 
+	ret = PTR_ERR(rdev);
 	regulator = ERR_PTR(ret);
 
 	/*
-- 
2.11.0

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web