Skip to contentSkip to conversation

reset: Put back *_optional variants

PATCH New John Youn 4 participants 8 messages May 26, 2016 – May 31, 2016 Reset controller framework

lore
Share & tools
lore

John Youn

author
#0 lore raw

PATCH 1/1 reset: Put back *_optional variants

Prior to commit 6c96f05c8bb8 ("reset: Make [of_]reset_control_get[_foo] functions wrappers"), the optional variants returned -ENOTSUPP when CONFIG_RESET_CONTROLLER was not set. This patch reverts to this behavior. Otherwise those calls will return -EINVAL causing users to think that an error occurred when CONFIG_RESET_CONTROLLER is not set.

Fixes 6c96f05c8bb8 ("reset: Make [of_]reset_control_get[_foo] functions wrappers")

---

Hi Philipp, Hans,

The commit referenced above breaks an upcoming patch for the dwc2 driver that adds an optional reset control.

https://marc.info/?l=linux-usb&m=146161328211584&w=2

I've attempted to add the optional variants back the way they were working before. Let me know if I need to do anything else to fix it or if it should be done another way.

Regards,
John

 include/linux/reset.h | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)
include/linux/reset.h +31 -2
index ec0306ce..739d33d 100644
@@ -14,10 +14,24 @@ int reset_control_status(struct reset_control *rstc);
 
 struct reset_control *__of_reset_control_get(struct device_node *node,
 				     const char *id, int index, int shared);
+
+struct reset_control *__of_reset_control_get_optional(struct device_node *node,
+				     const char *id, int index, int shared)
+{
+	return __of_reset_control_get(node, id, index, shared);
+}
+
 void reset_control_put(struct reset_control *rstc);
 struct reset_control *__devm_reset_control_get(struct device *dev,
 				     const char *id, int index, int shared);
 
+static inline struct reset_control *__devm_reset_control_get_optional(
+					struct device *dev,
+					const char *id, int index, int shared)
+{
+	return __devm_reset_control_get(dev, id, index, shared);
+}
+
 int __must_check device_reset(struct device *dev);
 
 static inline int device_reset_optional(struct device *dev)
@@ -74,6 +88,13 @@ static inline struct reset_control *__of_reset_control_get(
 	return ERR_PTR(-EINVAL);
 }
 
+static inline struct reset_control *__of_reset_control_get_optional(
+					struct device_node *node,
+					const char *id, int index, int shared)
+{
+	return ERR_PTR(-ENOTSUPP);
+}
+
 static inline struct reset_control *__devm_reset_control_get(
 					struct device *dev,
 					const char *id, int index, int shared)
@@ -81,6 +102,13 @@ static inline struct reset_control *__devm_reset_control_get(
 	return ERR_PTR(-EINVAL);
 }
 
+static inline struct reset_control *__devm_reset_control_get_optional(
+					struct device *dev,
+					const char *id, int index, int shared)
+{
+	return ERR_PTR(-ENOTSUPP);
+}
+
 #endif /* CONFIG_RESET_CONTROLLER */
 
 /**
@@ -110,7 +138,8 @@ static inline struct reset_control *__must_check reset_control_get(
 static inline struct reset_control *reset_control_get_optional(
 					struct device *dev, const char *id)
 {
-	return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, 0);
+	return __of_reset_control_get_optional(dev ? dev->of_node : NULL,
+					       id, 0, 0);
 }
 
 /**
@@ -194,7 +223,7 @@ static inline struct reset_control *__must_check devm_reset_control_get(
 static inline struct reset_control *devm_reset_control_get_optional(
 					struct device *dev, const char *id)
 {
-	return __devm_reset_control_get(dev, id, 0, 0);
+	return __devm_reset_control_get_optional(dev, id, 0, 0);
 }
 
 /**
Signature · 1 line
2.8.2
#1 lore raw

PATCH 1/1 reset: Put back *_optional variants

Hi,

Quoted 15 lines · John Youn

Prior to commit 6c96f05c8bb8 ("reset: Make [of_]reset_control_get[_foo] functions wrappers"), the optional variants returned -ENOTSUPP when CONFIG_RESET_CONTROLLER was not set. This patch reverts to this behavior. Otherwise those calls will return -EINVAL causing users to think that an error occurred when CONFIG_RESET_CONTROLLER is not set.

Fixes 6c96f05c8bb8 ("reset: Make [of_]reset_control_get[_foo] functions wrappers")

---

Hi Philipp, Hans,

The commit referenced above breaks an upcoming patch for the dwc2 driver that adds an optional reset control.

Quoted 8 lines

https://marc.info/?l=linux-usb&m=146161328211584&w=2

I've attempted to add the optional variants back the way they were working before. Let me know if I need to do anything else to fix it or if it should be done another way.

Regards,
John

Hmm, I don't like all the extra code your patch adds just to fix a return value...

Looking at the code before my "reset: Make [of_]reset_control_get[_foo] functions wrappers" patch, all the dev*_get* functions were returning ENOTSUPP except for [devm_]reset_control_get, so following your logic we should also change the of_reset_control_get_by_index variant to return -ENOTSUP.

Or better, simply make them all return -ENOTSUP, that seems both consistent and more KISS to me, this would mean an error code change for [devm_]reset_control_get, but will fix all the other getters from having a changed error-code, and I would callers of [devm_]reset_control_get to not care which error code they get, except for -EPROBE_DEFER.

So IMHO the following change would be a better way to fix this:

include/linux/reset.h +2 -2
@@ -65,14 +65,14 @@ static inline struct reset_control *__of_reset_control_get(
                                         struct device_node *node,
                                         const char *id, int index, int shared)
  {
-   return ERR_PTR(-EINVAL);
+ return ERR_PTR(-ENOTSUPP);
  }
 
  static inline struct reset_control *__devm_reset_control_get(
                                         struct device *dev,
                                         const char *id, int index, int shared)
  {
-   return ERR_PTR(-EINVAL);
+ return ERR_PTR(-ENOTSUPP);
  }
 
  #endif /* CONFIG_RESET_CONTROLLER */

Regards,

Hans

Quoted 81 lines
 include/linux/reset.h | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)
include/linux/reset.h +31 -2
index ec0306ce..739d33d 100644
@@ -14,10 +14,24 @@ int reset_control_status(struct reset_control *rstc);
 
 struct reset_control *__of_reset_control_get(struct device_node *node,
 				     const char *id, int index, int shared);
+
+struct reset_control *__of_reset_control_get_optional(struct device_node *node,
+				     const char *id, int index, int shared)
+{
+	return __of_reset_control_get(node, id, index, shared);
+}
+
 void reset_control_put(struct reset_control *rstc);
 struct reset_control *__devm_reset_control_get(struct device *dev,
 				     const char *id, int index, int shared);
 
+static inline struct reset_control *__devm_reset_control_get_optional(
+					struct device *dev,
+					const char *id, int index, int shared)
+{
+	return __devm_reset_control_get(dev, id, index, shared);
+}
+
 int __must_check device_reset(struct device *dev);
 
 static inline int device_reset_optional(struct device *dev)
@@ -74,6 +88,13 @@ static inline struct reset_control *__of_reset_control_get(
 	return ERR_PTR(-EINVAL);
 }
 
+static inline struct reset_control *__of_reset_control_get_optional(
+					struct device_node *node,
+					const char *id, int index, int shared)
+{
+	return ERR_PTR(-ENOTSUPP);
+}
+
 static inline struct reset_control *__devm_reset_control_get(
 					struct device *dev,
 					const char *id, int index, int shared)
@@ -81,6 +102,13 @@ static inline struct reset_control *__devm_reset_control_get(
 	return ERR_PTR(-EINVAL);
 }
 
+static inline struct reset_control *__devm_reset_control_get_optional(
+					struct device *dev,
+					const char *id, int index, int shared)
+{
+	return ERR_PTR(-ENOTSUPP);
+}
+
 #endif /* CONFIG_RESET_CONTROLLER */
 
 /**
@@ -110,7 +138,8 @@ static inline struct reset_control *__must_check reset_control_get(
 static inline struct reset_control *reset_control_get_optional(
 					struct device *dev, const char *id)
 {
-	return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, 0);
+	return __of_reset_control_get_optional(dev ? dev->of_node : NULL,
+					       id, 0, 0);
 }
 
 /**
@@ -194,7 +223,7 @@ static inline struct reset_control *__must_check devm_reset_control_get(
 static inline struct reset_control *devm_reset_control_get_optional(
 					struct device *dev, const char *id)
 {
-	return __devm_reset_control_get(dev, id, 0, 0);
+	return __devm_reset_control_get_optional(dev, id, 0, 0);
 }
 
 /**
#2 lore raw

PATCH 1/1 reset: Put back *_optional variants

Quoted 54 lines · Hans de Goede

Hi,

Quoted 15 lines · John Youn

Prior to commit 6c96f05c8bb8 ("reset: Make [of_]reset_control_get[_foo] functions wrappers"), the optional variants returned -ENOTSUPP when CONFIG_RESET_CONTROLLER was not set. This patch reverts to this behavior. Otherwise those calls will return -EINVAL causing users to think that an error occurred when CONFIG_RESET_CONTROLLER is not set.

Fixes 6c96f05c8bb8 ("reset: Make [of_]reset_control_get[_foo] functions wrappers")

---

Hi Philipp, Hans,

The commit referenced above breaks an upcoming patch for the dwc2 driver that adds an optional reset control.

Quoted 8 lines

https://marc.info/?l=linux-usb&m=146161328211584&w=2

I've attempted to add the optional variants back the way they were working before. Let me know if I need to do anything else to fix it or if it should be done another way.

Regards,
John

Hmm, I don't like all the extra code your patch adds just to fix a return value...

Looking at the code before my "reset: Make [of_]reset_control_get[_foo] functions wrappers" patch, all the dev*_get* functions were returning ENOTSUPP except for [devm_]reset_control_get, so following your logic we should also change the of_reset_control_get_by_index variant to return -ENOTSUP.

Or better, simply make them all return -ENOTSUP, that seems both consistent and more KISS to me, this would mean an error code change for [devm_]reset_control_get, but will fix all the other getters from having a changed error-code, and I would callers of [devm_]reset_control_get to not care which error code they get, except for -EPROBE_DEFER.

So IMHO the following change would be a better way to fix this:

include/linux/reset.h +1 -1
@@ -65,14 +65,14 @@ static inline struct reset_control *__of_reset_control_get(
                                         struct device_node *node,
                                         const char *id, int index, int shared)
  {
-   return ERR_PTR(-EINVAL);
+ return ERR_PTR(-ENOTSUPP);
  }

include/linux/reset.h static inline struct reset_control *__of_reset_control_get( · line 78

Quoted 10 lines
include/linux/reset.h +1 -1
 
  static inline struct reset_control *__devm_reset_control_get(
                                         struct device *dev,
                                         const char *id, int index, int shared)
  {
-   return ERR_PTR(-EINVAL);
+ return ERR_PTR(-ENOTSUPP);
  }
 
  #endif /* CONFIG_RESET_CONTROLLER */

I'm good with this. However, per Philipp on a previous thread, the intended behavior is to return -EINVAL for the non-optional functions.

http://marc.info/?l=linux-usb&m=146156945528848&w=2

Philipp,

Any suggestions?

Regards,
John

#3 lore raw

PATCH 1/1 reset: Put back *_optional variants

Hi,

Quoted 64 lines · John Youn
Quoted 63 lines · Hans de Goede

Hi,

Quoted 15 lines · John Youn

Prior to commit 6c96f05c8bb8 ("reset: Make [of_]reset_control_get[_foo] functions wrappers"), the optional variants returned -ENOTSUPP when CONFIG_RESET_CONTROLLER was not set. This patch reverts to this behavior. Otherwise those calls will return -EINVAL causing users to think that an error occurred when CONFIG_RESET_CONTROLLER is not set.

Fixes 6c96f05c8bb8 ("reset: Make [of_]reset_control_get[_foo] functions wrappers")

---

Hi Philipp, Hans,

The commit referenced above breaks an upcoming patch for the dwc2 driver that adds an optional reset control.

Quoted 8 lines

https://marc.info/?l=linux-usb&m=146161328211584&w=2

I've attempted to add the optional variants back the way they were working before. Let me know if I need to do anything else to fix it or if it should be done another way.

Regards,
John

Hmm, I don't like all the extra code your patch adds just to fix a return value...

Looking at the code before my "reset: Make [of_]reset_control_get[_foo] functions wrappers" patch, all the dev*_get* functions were returning ENOTSUPP except for [devm_]reset_control_get, so following your logic we should also change the of_reset_control_get_by_index variant to return -ENOTSUP.

Or better, simply make them all return -ENOTSUP, that seems both consistent and more KISS to me, this would mean an error code change for [devm_]reset_control_get, but will fix all the other getters from having a changed error-code, and I would callers of [devm_]reset_control_get to not care which error code they get, except for -EPROBE_DEFER.

So IMHO the following change would be a better way to fix this:

include/linux/reset.h +2 -2
@@ -65,14 +65,14 @@ static inline struct reset_control *__of_reset_control_get(
                                         struct device_node *node,
                                         const char *id, int index, int shared)
  {
-   return ERR_PTR(-EINVAL);
+ return ERR_PTR(-ENOTSUPP);
  }
 
  static inline struct reset_control *__devm_reset_control_get(
                                         struct device *dev,
                                         const char *id, int index, int shared)
  {
-   return ERR_PTR(-EINVAL);
+ return ERR_PTR(-ENOTSUPP);
  }
 
Quoted 7 lines

include/linux/reset.h static inline struct reset_control *__of_reset_control_get( · line 78

Quoted 1 line
include/linux/reset.h +0 -0
  #endif /* CONFIG_RESET_CONTROLLER */

I'm good with this. However, per Philipp on a previous thread, the intended behavior is to return -EINVAL for the non-optional functions.

http://marc.info/?l=linux-usb&m=146156945528848&w=2

As Philipp rightfully points out, calling the non-optional functions without CONFIG_RESET_CONTROLLER is a no-no, so IMHO we should not have to care too much about the error code in that case, as long as we return an error.

Also note that even before my patch things were already inconsistent with the of_...get... functions already always returning -ENOTSUPP when CONFIG_RESET_CONTROLLER was not set, to me it seems best and also KISS to just return -ENOTSUPP from all get functions when CONFIG_RESET_CONTROLLER is not set.

Anyways this is Philipp's call, this is all just my 2 cents.

Regards,

Hans

maintainer
#4 lore raw

PATCH 1/1 reset: Put back *_optional variants

Hi,

Am Freitag, den 27.05.2016, 09:06 +0200 schrieb Hans de Goede:
[...]

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines

So IMHO the following change would be a better way to fix this:

include/linux/reset.h +2 -2
@@ -65,14 +65,14 @@ static inline struct reset_control *__of_reset_control_get(
                                         struct device_node *node,
                                         const char *id, int index, int shared)
  {
-   return ERR_PTR(-EINVAL);
+ return ERR_PTR(-ENOTSUPP);
  }
 
  static inline struct reset_control *__devm_reset_control_get(
                                         struct device *dev,
                                         const char *id, int index, int shared)
  {
-   return ERR_PTR(-EINVAL);
+ return ERR_PTR(-ENOTSUPP);
  }
 
Quoted 7 lines
Quoted 7 lines

include/linux/reset.h static inline struct reset_control *__of_reset_control_get( · line 78

Quoted 1 line
include/linux/reset.h +0 -0
  #endif /* CONFIG_RESET_CONTROLLER */

I'm good with this. However, per Philipp on a previous thread, the intended behavior is to return -EINVAL for the non-optional functions.

http://marc.info/?l=linux-usb&m=146156945528848&w=2

Adding Dinh to Cc: because he wanted this changed from -EINVAL. My point then was that WARN_ON + -EINVAL is indented in this case.

Given that the warning backtrace already helps to identify the issue (CONFIG_RESET_CONTROLLER disabled), and that changing the return value to -ENOTSUPP improves consistency with the rest of the API and reduces the amount of inline wrappers, I concur.

Quoted 5 lines

As Philipp rightfully points out, calling the non-optional functions without CONFIG_RESET_CONTROLLER is a no-no, so IMHO we should not have to care too much about the error code in that case, as long as we return an error.

Quoted 7 lines

Also note that even before my patch things were already inconsistent with the of_...get... functions already always returning -ENOTSUPP when CONFIG_RESET_CONTROLLER was not set, to me it seems best and also KISS to just return -ENOTSUPP from all get functions when CONFIG_RESET_CONTROLLER is not set.

Anyways this is Philipp's call, this is all just my 2 cents.

Let the stubs return -ENOTSUPP consistently. A quick grep doesn't show any driver handling -EINVAL explicitly either.

regards
Philipp

#5 lore raw

PATCH 1/1 reset: Put back *_optional variants

Hi,

Quoted 51 lines · Philipp Zabel

Hi,

Am Freitag, den 27.05.2016, 09:06 +0200 schrieb Hans de Goede:
[...]

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines

So IMHO the following change would be a better way to fix this:

include/linux/reset.h +2 -2
@@ -65,14 +65,14 @@ static inline struct reset_control *__of_reset_control_get(
                                         struct device_node *node,
                                         const char *id, int index, int shared)
  {
-   return ERR_PTR(-EINVAL);
+ return ERR_PTR(-ENOTSUPP);
  }
 
  static inline struct reset_control *__devm_reset_control_get(
                                         struct device *dev,
                                         const char *id, int index, int shared)
  {
-   return ERR_PTR(-EINVAL);
+ return ERR_PTR(-ENOTSUPP);
  }
 
Quoted 7 lines
Quoted 7 lines

include/linux/reset.h static inline struct reset_control *__of_reset_control_get( · line 78

Quoted 1 line
include/linux/reset.h +0 -0
  #endif /* CONFIG_RESET_CONTROLLER */

I'm good with this. However, per Philipp on a previous thread, the intended behavior is to return -EINVAL for the non-optional functions.

http://marc.info/?l=linux-usb&m=146156945528848&w=2

Adding Dinh to Cc: because he wanted this changed from -EINVAL. My point then was that WARN_ON + -EINVAL is indented in this case.

Given that the warning backtrace already helps to identify the issue (CONFIG_RESET_CONTROLLER disabled), and that changing the return value to -ENOTSUPP improves consistency with the rest of the API and reduces the amount of inline wrappers, I concur.

Quoted 11 lines

As Philipp rightfully points out, calling the non-optional functions without CONFIG_RESET_CONTROLLER is a no-no, so IMHO we should not have to care too much about the error code in that case, as long as we return an error.

Also note that even before my patch things were already inconsistent with the of_...get... functions already always returning -ENOTSUPP when CONFIG_RESET_CONTROLLER was not set, to me it seems best and also KISS to just return -ENOTSUPP from all get functions when CONFIG_RESET_CONTROLLER is not set.

Quoted 4 lines
Quoted 1 line

Anyways this is Philipp's call, this is all just my 2 cents.

Let the stubs return -ENOTSUPP consistently. A quick grep doesn't show any driver handling -EINVAL explicitly either.

Great.

John Youn, can you submit a patch changing the return of the stubs from -EINVAL to -ENOTSUPP please ?

Thanks & Regards,

Hans

maintainer
#6 lore raw

PATCH 1/1 reset: Put back *_optional variants

Am Montag, den 30.05.2016, 13:32 +0200 schrieb Hans de Goede:

Quoted 37 lines

Hi,

Quoted 34 lines · Philipp Zabel

Hi,

Am Freitag, den 27.05.2016, 09:06 +0200 schrieb Hans de Goede:
[...]

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines

So IMHO the following change would be a better way to fix this:

include/linux/reset.h +2 -2
@@ -65,14 +65,14 @@ static inline struct reset_control *__of_reset_control_get(
                                         struct device_node *node,
                                         const char *id, int index, int shared)
  {
-   return ERR_PTR(-EINVAL);
+ return ERR_PTR(-ENOTSUPP);
  }
 
  static inline struct reset_control *__devm_reset_control_get(
                                         struct device *dev,
                                         const char *id, int index, int shared)
  {
-   return ERR_PTR(-EINVAL);
+ return ERR_PTR(-ENOTSUPP);
  }
 
Quoted 7 lines
Quoted 7 lines

include/linux/reset.h static inline struct reset_control *__of_reset_control_get( · line 78

Quoted 1 line
include/linux/reset.h +0 -0
  #endif /* CONFIG_RESET_CONTROLLER */

I'm good with this. However, per Philipp on a previous thread, the intended behavior is to return -EINVAL for the non-optional functions.

http://marc.info/?l=linux-usb&m=146156945528848&w=2

Adding Dinh to Cc: because he wanted this changed from -EINVAL. My point then was that WARN_ON + -EINVAL is indented in this case.

No idea how this happened, but I meant "intended", obviously :)

regards
Philipp

#7 lore raw

PATCH 1/1 reset: Put back *_optional variants

In reply to Hans de Goede
Quoted 56 lines · Hans de Goede

Hi,

Quoted 53 lines · Philipp Zabel

Hi,

Am Freitag, den 27.05.2016, 09:06 +0200 schrieb Hans de Goede:
[...]

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines

So IMHO the following change would be a better way to fix this:

include/linux/reset.h +2 -2
@@ -65,14 +65,14 @@ static inline struct reset_control *__of_reset_control_get(
                                         struct device_node *node,
                                         const char *id, int index, int shared)
  {
-   return ERR_PTR(-EINVAL);
+ return ERR_PTR(-ENOTSUPP);
  }
 
  static inline struct reset_control *__devm_reset_control_get(
                                         struct device *dev,
                                         const char *id, int index, int shared)
  {
-   return ERR_PTR(-EINVAL);
+ return ERR_PTR(-ENOTSUPP);
  }
 
Quoted 7 lines
Quoted 7 lines

include/linux/reset.h static inline struct reset_control *__of_reset_control_get( · line 78

Quoted 1 line
include/linux/reset.h +0 -0
  #endif /* CONFIG_RESET_CONTROLLER */

I'm good with this. However, per Philipp on a previous thread, the intended behavior is to return -EINVAL for the non-optional functions.

http://marc.info/?l=linux-usb&m=146156945528848&w=2

Adding Dinh to Cc: because he wanted this changed from -EINVAL. My point then was that WARN_ON + -EINVAL is indented in this case.

Given that the warning backtrace already helps to identify the issue (CONFIG_RESET_CONTROLLER disabled), and that changing the return value to -ENOTSUPP improves consistency with the rest of the API and reduces the amount of inline wrappers, I concur.

Quoted 12 lines

As Philipp rightfully points out, calling the non-optional functions without CONFIG_RESET_CONTROLLER is a no-no, so IMHO we should not have to care too much about the error code in that case, as long as we return an error.

Also note that even before my patch things were already inconsistent with the of_...get... functions already always returning -ENOTSUPP when CONFIG_RESET_CONTROLLER was not set, to me it seems best and also KISS to just return -ENOTSUPP from all get functions when CONFIG_RESET_CONTROLLER is not set.

Anyways this is Philipp's call, this is all just my 2 cents.

Quoted 8 lines
Quoted 2 lines

Let the stubs return -ENOTSUPP consistently. A quick grep doesn't show any driver handling -EINVAL explicitly either.

Great.

John Youn, can you submit a patch changing the return of the stubs from -EINVAL to -ENOTSUPP please ?

Sure. I'll send a patch tomorrow.

Regards,
John