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


Groups > linux.kernel > #1216925 > unrolled thread

[PATCH] reset: Fix of_reset_control_get() for consistent return values

Started byAlban Bedel <albeu@free.fr>
First post2015-09-01 17:30 +0200
Last post2015-09-03 11:50 +0200
Articles 4 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] reset: Fix of_reset_control_get() for consistent return values Alban Bedel <albeu@free.fr> - 2015-09-01 17:30 +0200
    Re: [PATCH] reset: Fix of_reset_control_get() for consistent return  values Philipp Zabel <p.zabel@pengutronix.de> - 2015-09-02 17:10 +0200
      Re: [PATCH] reset: Fix of_reset_control_get() for consistent return  values Alban <albeu@free.fr> - 2015-09-02 18:40 +0200
        Re: [PATCH] reset: Fix of_reset_control_get() for consistent return  values Philipp Zabel <p.zabel@pengutronix.de> - 2015-09-03 11:50 +0200

#1216925 — [PATCH] reset: Fix of_reset_control_get() for consistent return values

FromAlban Bedel <albeu@free.fr>
Date2015-09-01 17:30 +0200
Subject[PATCH] reset: Fix of_reset_control_get() for consistent return values
Message-ID<q3VFv-23x-3@gated-at.bofh.it>
When of_reset_control_get() is called without connection ID it returns
-ENOENT when the 'resets' property doesn't exists or is an empty entry.
However when a connection ID is given it returns -EINVAL when the 'resets'
property doesn't exists or the requested name can't be found. This is
because the error code returned by of_property_match_string() is just
passed down as an index to of_parse_phandle_with_args(), which then
returns -EINVAL.

To get a consistent return value with both code paths we must return
-ENOENT when of_property_match_string() fails.

Signed-off-by: Alban Bedel <albeu@free.fr>
---
 drivers/reset/core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index 3cbc764..fd6ac9b 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -265,9 +265,12 @@ struct reset_control *of_reset_control_get(struct device_node *node,
 	int rstc_id;
 	int ret;
 
-	if (id)
+	if (id) {
 		index = of_property_match_string(node,
 						 "reset-names", id);
+		if (index < 0)
+			return ERR_PTR(-ENOENT);
+	}
 	ret = of_parse_phandle_with_args(node, "resets", "#reset-cells",
 					 index, &args);
 	if (ret)
-- 
2.0.0

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

[toc] | [next] | [standalone]


#1217686 — Re: [PATCH] reset: Fix of_reset_control_get() for consistent return values

FromPhilipp Zabel <p.zabel@pengutronix.de>
Date2015-09-02 17:10 +0200
SubjectRe: [PATCH] reset: Fix of_reset_control_get() for consistent return values
Message-ID<q4hPI-bE-15@gated-at.bofh.it>
In reply to#1216925
Hi Alban,

Am Dienstag, den 01.09.2015, 17:28 +0200 schrieb Alban Bedel:
> When of_reset_control_get() is called without connection ID it returns
> -ENOENT when the 'resets' property doesn't exists or is an empty entry.
> However when a connection ID is given it returns -EINVAL when the 'resets'
> property doesn't exists or the requested name can't be found. This is
> because the error code returned by of_property_match_string() is just
> passed down as an index to of_parse_phandle_with_args(), which then
> returns -EINVAL.

Is that true? As far as I can see, since commit bd69f73f2c81
("of: Create function for counting number of phandles in a property")
it returns the (positive) number of entries if index is negative and the
'resets' property exists and parses correctly (before it would return
-ENOENT). If there are parsing errors, it can also return -EINVAL.

regards
Philipp

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

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


#1217740 — Re: [PATCH] reset: Fix of_reset_control_get() for consistent return values

FromAlban <albeu@free.fr>
Date2015-09-02 18:40 +0200
SubjectRe: [PATCH] reset: Fix of_reset_control_get() for consistent return values
Message-ID<q4jeO-24Q-21@gated-at.bofh.it>
In reply to#1217686
On Wed, 02 Sep 2015 17:09:52 +0200
Philipp Zabel <p.zabel@pengutronix.de> wrote:

> Hi Alban,
> 
> Am Dienstag, den 01.09.2015, 17:28 +0200 schrieb Alban Bedel:
> > When of_reset_control_get() is called without connection ID it returns
> > -ENOENT when the 'resets' property doesn't exists or is an empty entry.
> > However when a connection ID is given it returns -EINVAL when the 'resets'
> > property doesn't exists or the requested name can't be found. This is
> > because the error code returned by of_property_match_string() is just
> > passed down as an index to of_parse_phandle_with_args(), which then
> > returns -EINVAL.
> 
> Is that true? As far as I can see, since commit bd69f73f2c81
> ("of: Create function for counting number of phandles in a property")
> it returns the (positive) number of entries if index is negative and the
> 'resets' property exists and parses correctly (before it would return
> -ENOENT). If there are parsing errors, it can also return -EINVAL.

That's no really the case. If the property doesn't exists, or the
requested index is out of range, of_parse_phandle_with_args() always
return -ENOENT. This is important for optional properties.

However if the index is negative it always return -EINVAL,
independently of the property existence. And here it is what happen
when of_property_match_string() fails, leading to this inconsistence.

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

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


#1218131 — Re: [PATCH] reset: Fix of_reset_control_get() for consistent return values

FromPhilipp Zabel <p.zabel@pengutronix.de>
Date2015-09-03 11:50 +0200
SubjectRe: [PATCH] reset: Fix of_reset_control_get() for consistent return values
Message-ID<q4zjz-8gK-7@gated-at.bofh.it>
In reply to#1217740
Hi Alban,

Am Mittwoch, den 02.09.2015, 18:35 +0200 schrieb Alban:
[...]
> That's no really the case. If the property doesn't exists, or the
> requested index is out of range, of_parse_phandle_with_args() always
> return -ENOENT. This is important for optional properties.

You are right, I've looked ad __of_parse_phandle_with_args and missed
that it's explicitly checked in of_parse_phandle_with_args. I have
applied your patch.

best regards
Philipp

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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web