reset: Make optional functions really optional.
v2 cover reset: Make optional functions really optional.
v2:
- Make some comments more explicit
- Add optional flag to reduce code duplication
- Change shared flag from int to bool to match optional flag
Up until now optional functions in the reset API were similar to the non optional.
This patch corrects that, while maintaining compatibility with existing drivers.
As suggested here: https://lkml.org/lkml/2016/12/14/502
Ramiro Oliveira (2):
reset: Change shared flag from int to bool
reset: make optional functions really optional
drivers/reset/core.c | 39 +++++++++++++++++++++++++++++++-------- include/linux/reset.h | 45 ++++++++++++++++++++++++++------------------- 2 files changed, 57 insertions(+), 27 deletions(-)
Signature · 1 line
2.11.0
PATCH v2 1/2 reset: Change shared flag from int to bool
Since the new parameter being added is going to be a bool this patch changes the shared flag from int to bool to match the new parameter.
--- drivers/reset/core.c | 8 ++++---- include/linux/reset.h | 32 ++++++++++++++++---------------- 2 files changed, 20 insertions(+), 20 deletions(-)
drivers/reset/core.c +4 -4
@@ -38,7 +38,7 @@ struct reset_control {struct list_head list;unsigned int id;unsigned int refcnt; -int shared; +bool shared;atomic_t deassert_count; };
@@ -213,7 +213,7 @@ EXPORT_SYMBOL_GPL(reset_control_status);static struct reset_control *__reset_control_get (struct reset_controller_dev *rcdev, -unsigned int index,int shared) +unsigned int index,bool shared) {struct reset_control *rstc;
@@ -258,7 +258,7 @@ static void __reset_control_put(struct reset_control *rstc) }struct reset_control *__of_reset_control_get (struct device_node *node, -const char *id,int index,int shared) +const char *id,int index,bool shared) {struct reset_control *rstc;struct reset_controller_dev *r, *rcdev;
@@ -338,7 +338,7 @@ static void devm_reset_control_release(struct device *dev, void *res) }struct reset_control *__devm_reset_control_get (struct device *dev, -const char *id,int index,int shared) +const char *id,int index,bool shared) {struct reset_control **ptr, *rstc;
include/linux/reset.h +16 -16
@@ -13,10 +13,10 @@ int reset_control_deassert(struct reset_control *rstc);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); +const char *id,int index,bool 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); +const char *id,int index,bool shared);int __must_check device_reset (struct device *dev);
@@ -69,14 +69,14 @@ static inline int device_reset_optional(struct device *dev)static inline struct reset_control *__of_reset_control_get (struct device_node *node, -const char *id,int index,int shared) +const char *id,int index,bool shared) {return ERR_PTR (-ENOTSUPP ); }static inline struct reset_control *__devm_reset_control_get (struct device *dev, -const char *id,int index,int shared) +const char *id,int index,bool shared) {return ERR_PTR (-ENOTSUPP ); }
@@ -132,19 +132,19 @@ __must_check reset_control_get_exclusive(struct device *dev, const char *id)static inline struct reset_control *reset_control_get_shared (struct device *dev,const char *id) { -return __of_reset_control_get (dev ? dev->of_node :NULL , id,0 ,1 ); +return __of_reset_control_get (dev ? dev->of_node :NULL , id,0 , true); }static inline struct reset_control *reset_control_get_optional_exclusive (struct device *dev,const char *id) { -return __of_reset_control_get (dev ? dev->of_node :NULL , id,0 ,0 ); +return __of_reset_control_get (dev ? dev->of_node :NULL , id,0 , false); }static inline struct reset_control *reset_control_get_optional_shared (struct device *dev,const char *id) { -return __of_reset_control_get (dev ? dev->of_node :NULL , id,0 ,1 ); +return __of_reset_control_get (dev ? dev->of_node :NULL , id,0 , true); }/**
@@ -185,7 +185,7 @@ static inline struct reset_control *of_reset_control_get_exclusive(static inline struct reset_control *of_reset_control_get_shared (struct device_node *node,const char *id) { -return __of_reset_control_get (node, id,0 ,1 ); +return __of_reset_control_get (node, id,0 , true); }/**
@@ -202,7 +202,7 @@ static inline struct reset_control *of_reset_control_get_shared(static inline struct reset_control *of_reset_control_get_exclusive_by_index (struct device_node *node,int index) { -return __of_reset_control_get (node,NULL , index,0 ); +return __of_reset_control_get (node,NULL , index, false); }/**
@@ -230,7 +230,7 @@ static inline struct reset_control *of_reset_control_get_exclusive_by_index(static inline struct reset_control *of_reset_control_get_shared_by_index (struct device_node *node,int index) { -return __of_reset_control_get (node,NULL , index,1 ); +return __of_reset_control_get (node,NULL , index, true); }/**
@@ -252,7 +252,7 @@ __must_check devm_reset_control_get_exclusive(struct device *dev,#ifndef CONFIG_RESET_CONTROLLER WARN_ON (1 );#endif -return __devm_reset_control_get (dev, id,0 ,0 ); +return __devm_reset_control_get (dev, id,0 , false); }/**
@@ -267,19 +267,19 @@ __must_check devm_reset_control_get_exclusive(struct device *dev,static inline struct reset_control *devm_reset_control_get_shared (struct device *dev,const char *id) { -return __devm_reset_control_get (dev, id,0 ,1 ); +return __devm_reset_control_get (dev, id,0 , true); }static inline struct reset_control *devm_reset_control_get_optional_exclusive (struct device *dev,const char *id) { -return __devm_reset_control_get (dev, id,0 ,0 ); +return __devm_reset_control_get (dev, id,0 , false); }static inline struct reset_control *devm_reset_control_get_optional_shared (struct device *dev,const char *id) { -return __devm_reset_control_get (dev, id,0 ,1 ); +return __devm_reset_control_get (dev, id,0 , true); }/**
@@ -297,7 +297,7 @@ static inline struct reset_control *devm_reset_control_get_optional_shared(static inline struct reset_control *devm_reset_control_get_exclusive_by_index (struct device *dev,int index) { -return __devm_reset_control_get (dev,NULL , index,0 ); +return __devm_reset_control_get (dev,NULL , index, false); }/**
@@ -313,7 +313,7 @@ devm_reset_control_get_exclusive_by_index(struct device *dev, int index)static inline struct reset_control *devm_reset_control_get_shared_by_index (struct device *dev,int index) { -return __devm_reset_control_get (dev,NULL , index,1 ); +return __devm_reset_control_get (dev,NULL , index, true); }/*
Signature · 1 line
2.11.0
PATCH v2 2/2 reset: make optional functions really optional
In reply to Ramiro OliveiraThe optional functions weren't really optional so this patch makes them really optional.
--- drivers/reset/core.c | 35 +++++++++++++++++++++++++++++------ include/linux/reset.h | 45 ++++++++++++++++++++++++++------------------- 2 files changed, 55 insertions(+), 25 deletions(-)
drivers/reset/core.c +29 -6
@@ -135,9 +135,15 @@ EXPORT_SYMBOL_GPL(devm_reset_controller_register);* @rstc: reset controller * * Calling this on a shared reset controller is an error. +* +* If rstc is NULL it is an optional reset and the function will just +* return 0. */ int reset_control_reset (struct reset_control *rstc) { +if (!rstc) +return 0 ; +if (WARN_ON (rstc->shared))return -EINVAL ;
@@ -158,9 +164,15 @@ EXPORT_SYMBOL_GPL(reset_control_reset);* * For shared reset controls a driver cannot expect the hw's registers and * internal state to be reset, but must be prepared for this to happen. +* +* If rstc is NULL it is an optional reset and the function will just +* return 0. */ int reset_control_assert (struct reset_control *rstc) { +if (!rstc) +return 0 ; +if (!rstc->rcdev->ops->assert)return -ENOTSUPP ;
@@ -181,9 +193,15 @@ EXPORT_SYMBOL_GPL(reset_control_assert);* @rstc: reset controller * * After calling this function, the reset is guaranteed to be deasserted. +* +* If rstc is NULL it is an optional reset and the function will just +* return 0. */ int reset_control_deassert (struct reset_control *rstc) { +if (!rstc) +return 0 ; +if (!rstc->rcdev->ops->deassert)return -ENOTSUPP ;
@@ -199,11 +217,14 @@ EXPORT_SYMBOL_GPL(reset_control_deassert);/** * reset_control_status - returns a negative errno if not supported, a * positive value if the reset line is asserted, or zero if the reset -* line is not asserted. +* line is not asserted or if the desc is NULL (optional reset). * @rstc: reset controller */ int reset_control_status (struct reset_control *rstc) { +if (!rstc) +return 0 ; +if (rstc->rcdev->ops->status)return rstc->rcdev->ops->status (rstc->rcdev, rstc->id);
@@ -258,7 +279,8 @@ static void __reset_control_put(struct reset_control *rstc) }struct reset_control *__of_reset_control_get (struct device_node *node, -const char *id,int index,bool shared) +const char *id,int index,bool shared, +bool optional) {struct reset_control *rstc;struct reset_controller_dev *r, *rcdev;
@@ -273,13 +295,13 @@ struct reset_control *__of_reset_control_get(struct device_node *node, index =of_property_match_string (node,"reset-names" , id);if (index <0 ) -return ERR_PTR (-ENOENT ); +return optional ?NULL :ERR_PTR (-ENOENT ); } ret =of_parse_phandle_with_args (node,"resets" ,"#reset-cells" , index, &args);if (ret) -return ERR_PTR (ret); +return optional ?NULL :ERR_PTR (ret);mutex_lock (&reset_list_mutex); rcdev =NULL ;
@@ -338,7 +360,8 @@ static void devm_reset_control_release(struct device *dev, void *res) }struct reset_control *__devm_reset_control_get (struct device *dev, -const char *id,int index,bool shared) +const char *id,int index,bool shared, +bool optional) {struct reset_control **ptr, *rstc;
@@ -348,7 +371,7 @@ struct reset_control *__devm_reset_control_get(struct device *dev,return ERR_PTR (-ENOMEM ); rstc =__of_reset_control_get (dev ? dev->of_node :NULL , - id, index, shared); + id, index, shared, optional);if (!IS_ERR (rstc)) { *ptr = rstc;devres_add (dev, ptr);
include/linux/reset.h +26 -19
144 lines not on this page · raw message
Signature · 1 line
2.11.0
Philipp Zabel
maintainerRe: [PATCH v2 2/2] reset: make optional functions really optional
Hi Ramiro,
Am Dienstag, den 27.12.2016, 12:37 +0000 schrieb Ramiro Oliveira:
Quoted 2 lines
The optional functions weren't really optional so this patch makes them really optional.
Please add a bit of detail to the description. Since this changes the API, you should mention that the reset_control_get_optional variants now return NULL instead of an error if there is no matching reset phandle in the device tree and that the reset_control_* functions accept NULL rstc pointers.
Quoted 85 lines
Signed-off-by Ramiro Oliveira <[email protected]>--- drivers/reset/core.c | 35 +++++++++++++++++++++++++++++------ include/linux/reset.h | 45 ++++++++++++++++++++++++++------------------- 2 files changed, 55 insertions(+), 25 deletions(-)drivers/reset/core.c +24
-2@@ -135,9 +135,15 @@ EXPORT_SYMBOL_GPL(devm_reset_controller_register);* @rstc: reset controller * * Calling this on a shared reset controller is an error. +* +* If rstc is NULL it is an optional reset and the function will just +* return 0. */ int reset_control_reset (struct reset_control *rstc) { +if (!rstc) +return 0 ; +if (WARN_ON (rstc->shared))return -EINVAL ;@@ -158,9 +164,15 @@ EXPORT_SYMBOL_GPL(reset_control_reset);* * For shared reset controls a driver cannot expect the hw's registers and * internal state to be reset, but must be prepared for this to happen. +* +* If rstc is NULL it is an optional reset and the function will just +* return 0. */ int reset_control_assert (struct reset_control *rstc) { +if (!rstc) +return 0 ; +if (!rstc->rcdev->ops->assert)return -ENOTSUPP ;@@ -181,9 +193,15 @@ EXPORT_SYMBOL_GPL(reset_control_assert);* @rstc: reset controller * * After calling this function, the reset is guaranteed to be deasserted. +* +* If rstc is NULL it is an optional reset and the function will just +* return 0. */ int reset_control_deassert (struct reset_control *rstc) { +if (!rstc) +return 0 ; +if (!rstc->rcdev->ops->deassert)return -ENOTSUPP ;@@ -199,11 +217,14 @@ EXPORT_SYMBOL_GPL(reset_control_deassert);/** * reset_control_status - returns a negative errno if not supported, a * positive value if the reset line is asserted, or zero if the reset -* line is not asserted. +* line is not asserted or if the desc is NULL (optional reset). * @rstc: reset controller */ int reset_control_status (struct reset_control *rstc) { +if (!rstc) +return 0 ; +if (rstc->rcdev->ops->status)return rstc->rcdev->ops->status (rstc->rcdev, rstc->id);@@ -258,7 +279,8 @@ static void __reset_control_put(struct reset_control *rstc) }struct reset_control *__of_reset_control_get (struct device_node *node, -const char *id,int index,bool shared) +const char *id,int index,bool shared, +bool optional) {struct reset_control *rstc;struct reset_controller_dev *r, *rcdev;
drivers/reset/core.c struct reset_control *__of_reset_control_get(struct device_node *node, · line 298
Quoted 5 lines
drivers/reset/core.c +1
-1@@ -273,13 +295,13 @@ struct reset_control *__of_reset_control_get(struct device_node *node, index =of_property_match_string (node,"reset-names" , id);if (index <0 ) -return ERR_PTR (-ENOENT ); +return optional ?NULL :ERR_PTR (-ENOENT );
of_property_match_string can return -EINVAL, -ENODATA, or -EILSEQ. I think -EILSEQ should still be returned.
drivers/reset/core.c struct reset_control *__of_reset_control_get(struct device_node *node, · line 304
Quoted 7 lines
drivers/reset/core.c +1
-1} ret =of_parse_phandle_with_args (node,"resets" ,"#reset-cells" , index, &args);if (ret) -return ERR_PTR (ret); +return optional ?NULL :ERR_PTR (ret);
of_parse_phandle_with_args can return -ENOENT or -EINVAL. I think -EINVAL should still be returned.
Quoted 174 lines
drivers/reset/core.c +3
-2mutex_lock (&reset_list_mutex); rcdev =NULL ;@@ -338,7 +360,8 @@ static void devm_reset_control_release(struct device *dev, void *res) }struct reset_control *__devm_reset_control_get (struct device *dev, -const char *id,int index,bool shared) +const char *id,int index,bool shared, +bool optional) {struct reset_control **ptr, *rstc;@@ -348,7 +371,7 @@ struct reset_control *__devm_reset_control_get(struct device *dev,return ERR_PTR (-ENOMEM ); rstc =__of_reset_control_get (dev ? dev->of_node :NULL , - id, index, shared); + id, index, shared, optional);if (!IS_ERR (rstc)) { *ptr = rstc;devres_add (dev, ptr);include/linux/reset.h +25
-18@@ -13,10 +13,12 @@ int reset_control_deassert(struct reset_control *rstc);int reset_control_status (struct reset_control *rstc);struct reset_control *__of_reset_control_get (struct device_node *node, -const char *id,int index,bool shared); +const char *id,int index,bool shared, +bool optional);void reset_control_put (struct reset_control *rstc);struct reset_control *__devm_reset_control_get (struct device *dev, -const char *id,int index,bool shared); +const char *id,int index,bool shared, +bool optional);int __must_check device_reset (struct device *dev);@@ -69,14 +71,15 @@ static inline int device_reset_optional(struct device *dev)static inline struct reset_control *__of_reset_control_get (struct device_node *node, -const char *id,int index,bool shared) +const char *id,int index,bool shared, +bool optional) {return ERR_PTR (-ENOTSUPP ); }static inline struct reset_control *__devm_reset_control_get ( -struct device *dev, -const char *id,int index,bool shared) +struct device *dev,const char *id, +int index,bool shared,bool optional) {return ERR_PTR (-ENOTSUPP ); }@@ -104,7 +107,8 @@ __must_check reset_control_get_exclusive(struct device *dev, const char *id)#ifndef CONFIG_RESET_CONTROLLER WARN_ON (1 );#endif -return __of_reset_control_get (dev ? dev->of_node :NULL , id,0 ,0 ); +return __of_reset_control_get (dev ? dev->of_node :NULL , id,0 , false, + false); }/** @@ -132,19 +136,22 @@ __must_check reset_control_get_exclusive(struct device *dev, const char *id)static inline struct reset_control *reset_control_get_shared (struct device *dev,const char *id) { -return __of_reset_control_get (dev ? dev->of_node :NULL , id,0 , true); +return __of_reset_control_get (dev ? dev->of_node :NULL , id,0 , true, + false); }static inline struct reset_control *reset_control_get_optional_exclusive (struct device *dev,const char *id) { -return __of_reset_control_get (dev ? dev->of_node :NULL , id,0 , false); +return __of_reset_control_get (dev ? dev->of_node :NULL , id,0 , false, + true); }static inline struct reset_control *reset_control_get_optional_shared (struct device *dev,const char *id) { -return __of_reset_control_get (dev ? dev->of_node :NULL , id,0 , true); +return __of_reset_control_get (dev ? dev->of_node :NULL , id,0 , true, + true); }/** @@ -160,7 +167,7 @@ static inline struct reset_control *reset_control_get_optional_shared(static inline struct reset_control *of_reset_control_get_exclusive (struct device_node *node,const char *id) { -return __of_reset_control_get (node, id,0 ,0 ); +return __of_reset_control_get (node, id,0 , false, false); }/** @@ -185,7 +192,7 @@ static inline struct reset_control *of_reset_control_get_exclusive(static inline struct reset_control *of_reset_control_get_shared (struct device_node *node,const char *id) { -return __of_reset_control_get (node, id,0 , true); +return __of_reset_control_get (node, id,0 , true, false); }/** @@ -202,7 +209,7 @@ static inline struct reset_control *of_reset_control_get_shared(static inline struct reset_control *of_reset_control_get_exclusive_by_index (struct device_node *node,int index) { -return __of_reset_control_get (node,NULL , index, false); +return __of_reset_control_get (node,NULL , index, false, false); }/** @@ -230,7 +237,7 @@ static inline struct reset_control *of_reset_control_get_exclusive_by_index(static inline struct reset_control *of_reset_control_get_shared_by_index (struct device_node *node,int index) { -return __of_reset_control_get (node,NULL , index, true); +return __of_reset_control_get (node,NULL , index, true, false); }/** @@ -252,7 +259,7 @@ __must_check devm_reset_control_get_exclusive(struct device *dev,#ifndef CONFIG_RESET_CONTROLLER WARN_ON (1 );#endif -return __devm_reset_control_get (dev, id,0 , false); +return __devm_reset_control_get (dev, id,0 , false, false); }/** @@ -267,19 +274,19 @@ __must_check devm_reset_control_get_exclusive(struct device *dev,static inline struct reset_control *devm_reset_control_get_shared (struct device *dev,const char *id) { -return __devm_reset_control_get (dev, id,0 , true); +return __devm_reset_control_get (dev, id,0 , true, false); }static inline struct reset_control *devm_reset_control_get_optional_exclusive (struct device *dev,const char *id) { -return __devm_reset_control_get (dev, id,0 , false); +return __devm_reset_control_get (dev, id,0 , false, true); }static inline struct reset_control *devm_reset_control_get_optional_shared (struct device *dev,const char *id) { -return __devm_reset_control_get (dev, id,0 , true); +return __devm_reset_control_get (dev, id,0 , true, true); }/** @@ -297,7 +304,7 @@ static inline struct reset_control *devm_reset_control_get_optional_shared(static inline struct reset_control *devm_reset_control_get_exclusive_by_index (struct device *dev,int index) { -return __devm_reset_control_get (dev,NULL , index, false); +return __devm_reset_control_get (dev,NULL , index, false, false); }/**
include/linux/reset.h devm_reset_control_get_exclusive_by_index(struct device *dev, int index) · line 326
Quoted 8 lines
include/linux/reset.h +1
-1@@ -313,7 +320,7 @@ devm_reset_control_get_exclusive_by_index(struct device *dev, int index)static inline struct reset_control *devm_reset_control_get_shared_by_index (struct device *dev,int index) { -return __devm_reset_control_get (dev,NULL , index, true); +return __devm_reset_control_get (dev,NULL , index, true, false); }/*
regards
Philipp
Re: [PATCH v2 2/2] reset: make optional functions really optional
Hi Philipp
Quoted 12 lines · Philipp Zabel
Hi Ramiro,
Am Dienstag, den 27.12.2016, 12:37 +0000 schrieb Ramiro Oliveira:
Quoted 2 lines
The optional functions weren't really optional so this patch makes them really optional.
Please add a bit of detail to the description. Since this changes the API, you should mention that the
reset_control_get_optionalvariants now return NULL instead of an error if there is no matching reset phandle in the device tree and that the reset_control_* functions accept NULL rstc pointers.
Would you be ok with something like this:
"The *_get_optional_* functions weren't really optional so this patch makes them really optional.
These *_get_optional_* functions will now return NULL instead of an error if no matching reset phandle is found in the DT, and all the reset_control_* functions now accept NULL rstc pointers
Quoted 77 lines
Quoted 77 lines
Signed-off-by Ramiro Oliveira <[email protected]>--- drivers/reset/core.c | 35 +++++++++++++++++++++++++++++------ include/linux/reset.h | 45 ++++++++++++++++++++++++++------------------- 2 files changed, 55 insertions(+), 25 deletions(-)drivers/reset/core.c +22
-1@@ -135,9 +135,15 @@ EXPORT_SYMBOL_GPL(devm_reset_controller_register);* @rstc: reset controller * * Calling this on a shared reset controller is an error. +* +* If rstc is NULL it is an optional reset and the function will just +* return 0. */ int reset_control_reset (struct reset_control *rstc) { +if (!rstc) +return 0 ; +if (WARN_ON (rstc->shared))return -EINVAL ;@@ -158,9 +164,15 @@ EXPORT_SYMBOL_GPL(reset_control_reset);* * For shared reset controls a driver cannot expect the hw's registers and * internal state to be reset, but must be prepared for this to happen. +* +* If rstc is NULL it is an optional reset and the function will just +* return 0. */ int reset_control_assert (struct reset_control *rstc) { +if (!rstc) +return 0 ; +if (!rstc->rcdev->ops->assert)return -ENOTSUPP ;@@ -181,9 +193,15 @@ EXPORT_SYMBOL_GPL(reset_control_assert);* @rstc: reset controller * * After calling this function, the reset is guaranteed to be deasserted. +* +* If rstc is NULL it is an optional reset and the function will just +* return 0. */ int reset_control_deassert (struct reset_control *rstc) { +if (!rstc) +return 0 ; +if (!rstc->rcdev->ops->deassert)return -ENOTSUPP ;@@ -199,11 +217,14 @@ EXPORT_SYMBOL_GPL(reset_control_deassert);/** * reset_control_status - returns a negative errno if not supported, a * positive value if the reset line is asserted, or zero if the reset -* line is not asserted. +* line is not asserted or if the desc is NULL (optional reset). * @rstc: reset controller */ int reset_control_status (struct reset_control *rstc) { +if (!rstc) +return 0 ; +if (rstc->rcdev->ops->status)return rstc->rcdev->ops->status (rstc->rcdev, rstc->id);@@ -258,7 +279,8 @@ static void __reset_control_put(struct reset_control *rstc) }
Quoted 17 lines
drivers/reset/core.c struct reset_control *__of_reset_control_get(struct device_node *node, · line 298
Quoted 13 lines
drivers/reset/core.c +3
-2struct reset_control *__of_reset_control_get (struct device_node *node, -const char *id,int index,bool shared) +const char *id,int index,bool shared, +bool optional) {struct reset_control *rstc;struct reset_controller_dev *r, *rcdev;@@ -273,13 +295,13 @@ struct reset_control *__of_reset_control_get(struct device_node *node, index =of_property_match_string (node,"reset-names" , id);if (index <0 ) -return ERR_PTR (-ENOENT ); +return optional ?NULL :ERR_PTR (-ENOENT );
of_property_match_stringcan return-EINVAL,-ENODATA, or-EILSEQ. I think-EILSEQshould still be returned.
I'll make the function return NULL, -ENOENT, or -EILSEQ.
Quoted 11 lines
drivers/reset/core.c struct reset_control *__of_reset_control_get(struct device_node *node, · line 304
Quoted 7 lines
drivers/reset/core.c +1
-1} ret =of_parse_phandle_with_args (node,"resets" ,"#reset-cells" , index, &args);if (ret) -return ERR_PTR (ret); +return optional ?NULL :ERR_PTR (ret);
of_parse_phandle_with_argscan return-ENOENTor-EINVAL. I think-EINVALshould still be returned.
Same as above. I'll make the function return NULL, -ENOENT, or -EINVAL.
Quoted 181 lines
Quoted 181 lines
drivers/reset/core.c +3
-2mutex_lock (&reset_list_mutex); rcdev =NULL ;@@ -338,7 +360,8 @@ static void devm_reset_control_release(struct device *dev, void *res) }struct reset_control *__devm_reset_control_get (struct device *dev, -const char *id,int index,bool shared) +const char *id,int index,bool shared, +bool optional) {struct reset_control **ptr, *rstc;@@ -348,7 +371,7 @@ struct reset_control *__devm_reset_control_get(struct device *dev,return ERR_PTR (-ENOMEM ); rstc =__of_reset_control_get (dev ? dev->of_node :NULL , - id, index, shared); + id, index, shared, optional);if (!IS_ERR (rstc)) { *ptr = rstc;devres_add (dev, ptr);include/linux/reset.h +26
-19@@ -13,10 +13,12 @@ int reset_control_deassert(struct reset_control *rstc);int reset_control_status (struct reset_control *rstc);struct reset_control *__of_reset_control_get (struct device_node *node, -const char *id,int index,bool shared); +const char *id,int index,bool shared, +bool optional);void reset_control_put (struct reset_control *rstc);struct reset_control *__devm_reset_control_get (struct device *dev, -const char *id,int index,bool shared); +const char *id,int index,bool shared, +bool optional);int __must_check device_reset (struct device *dev);@@ -69,14 +71,15 @@ static inline int device_reset_optional(struct device *dev)static inline struct reset_control *__of_reset_control_get (struct device_node *node, -const char *id,int index,bool shared) +const char *id,int index,bool shared, +bool optional) {return ERR_PTR (-ENOTSUPP ); }static inline struct reset_control *__devm_reset_control_get ( -struct device *dev, -const char *id,int index,bool shared) +struct device *dev,const char *id, +int index,bool shared,bool optional) {return ERR_PTR (-ENOTSUPP ); }@@ -104,7 +107,8 @@ __must_check reset_control_get_exclusive(struct device *dev, const char *id)#ifndef CONFIG_RESET_CONTROLLER WARN_ON (1 );#endif -return __of_reset_control_get (dev ? dev->of_node :NULL , id,0 ,0 ); +return __of_reset_control_get (dev ? dev->of_node :NULL , id,0 , false, + false); }/** @@ -132,19 +136,22 @@ __must_check reset_control_get_exclusive(struct device *dev, const char *id)static inline struct reset_control *reset_control_get_shared (struct device *dev,const char *id) { -return __of_reset_control_get (dev ? dev->of_node :NULL , id,0 , true); +return __of_reset_control_get (dev ? dev->of_node :NULL , id,0 , true, + false); }static inline struct reset_control *reset_control_get_optional_exclusive (struct device *dev,const char *id) { -return __of_reset_control_get (dev ? dev->of_node :NULL , id,0 , false); +return __of_reset_control_get (dev ? dev->of_node :NULL , id,0 , false, + true); }static inline struct reset_control *reset_control_get_optional_shared (struct device *dev,const char *id) { -return __of_reset_control_get (dev ? dev->of_node :NULL , id,0 , true); +return __of_reset_control_get (dev ? dev->of_node :NULL , id,0 , true, + true); }/** @@ -160,7 +167,7 @@ static inline struct reset_control *reset_control_get_optional_shared(static inline struct reset_control *of_reset_control_get_exclusive (struct device_node *node,const char *id) { -return __of_reset_control_get (node, id,0 ,0 ); +return __of_reset_control_get (node, id,0 , false, false); }/** @@ -185,7 +192,7 @@ static inline struct reset_control *of_reset_control_get_exclusive(static inline struct reset_control *of_reset_control_get_shared (struct device_node *node,const char *id) { -return __of_reset_control_get (node, id,0 , true); +return __of_reset_control_get (node, id,0 , true, false); }/** @@ -202,7 +209,7 @@ static inline struct reset_control *of_reset_control_get_shared(static inline struct reset_control *of_reset_control_get_exclusive_by_index (struct device_node *node,int index) { -return __of_reset_control_get (node,NULL , index, false); +return __of_reset_control_get (node,NULL , index, false, false); }/** @@ -230,7 +237,7 @@ static inline struct reset_control *of_reset_control_get_exclusive_by_index(static inline struct reset_control *of_reset_control_get_shared_by_index (struct device_node *node,int index) { -return __of_reset_control_get (node,NULL , index, true); +return __of_reset_control_get (node,NULL , index, true, false); }/** @@ -252,7 +259,7 @@ __must_check devm_reset_control_get_exclusive(struct device *dev,#ifndef CONFIG_RESET_CONTROLLER WARN_ON (1 );#endif -return __devm_reset_control_get (dev, id,0 , false); +return __devm_reset_control_get (dev, id,0 , false, false); }/** @@ -267,19 +274,19 @@ __must_check devm_reset_control_get_exclusive(struct device *dev,static inline struct reset_control *devm_reset_control_get_shared (struct device *dev,const char *id) { -return __devm_reset_control_get (dev, id,0 , true); +return __devm_reset_control_get (dev, id,0 , true, false); }static inline struct reset_control *devm_reset_control_get_optional_exclusive (struct device *dev,const char *id) { -return __devm_reset_control_get (dev, id,0 , false); +return __devm_reset_control_get (dev, id,0 , false, true); }static inline struct reset_control *devm_reset_control_get_optional_shared (struct device *dev,const char *id) { -return __devm_reset_control_get (dev, id,0 , true); +return __devm_reset_control_get (dev, id,0 , true, true); }/** @@ -297,7 +304,7 @@ static inline struct reset_control *devm_reset_control_get_optional_shared(static inline struct reset_control *devm_reset_control_get_exclusive_by_index (struct device *dev,int index) { -return __devm_reset_control_get (dev,NULL , index, false); +return __devm_reset_control_get (dev,NULL , index, false, false); }/** @@ -313,7 +320,7 @@ devm_reset_control_get_exclusive_by_index(struct device *dev, int index)static inline struct reset_control *devm_reset_control_get_shared_by_index (struct device *dev,int index) { -return __devm_reset_control_get (dev,NULL , index, true); +return __devm_reset_control_get (dev,NULL , index, true, false); }
Quoted 5 lines
include/linux/reset.h devm_reset_control_get_exclusive_by_index(struct device *dev, int index) · line 326
Quoted 1 line
include/linux/reset.h +0
-0/* regards
Philipp
BRs,
Ramiro
Philipp Zabel
maintainerRe: [PATCH v2 2/2] reset: make optional functions really optional
Hi Ramiro,
Am Montag, den 09.01.2017, 17:19 +0000 schrieb Ramiro Oliveira:
Quoted 16 lines
Hi Philipp
Quoted 12 lines · Philipp Zabel
Hi Ramiro,
Am Dienstag, den 27.12.2016, 12:37 +0000 schrieb Ramiro Oliveira:
Quoted 2 lines
The optional functions weren't really optional so this patch makes them really optional.
Please add a bit of detail to the description. Since this changes the API, you should mention that the
reset_control_get_optionalvariants now return NULL instead of an error if there is no matching reset phandle in the device tree and that the reset_control_* functions accept NULL rstc pointers.
Quoted 8 lines
Would you be ok with something like this:
"The *_get_optional_* functions weren't really optional so this patch makes them really optional.
These *_get_optional_* functions will now return NULL instead of an error if no matching reset phandle is found in the DT, and all the reset_control_* functions now accept NULL rstc pointers
Yes, that looks fine to me.
[...]
Quoted 11 lines
Quoted 10 lines
drivers/reset/core.c struct reset_control *__of_reset_control_get(struct device_node *node, · line 298
Quoted 6 lines
drivers/reset/core.c +1
-1@@ -273,13 +295,13 @@ struct reset_control *__of_reset_control_get(struct device_node *node, index =of_property_match_string (node,"reset-names" , id);if (index <0 ) -return ERR_PTR (-ENOENT ); +return optional ?NULL :ERR_PTR (-ENOENT );
of_property_match_stringcan return-EINVAL,-ENODATA, or-EILSEQ. I think-EILSEQshould still be returned.
Quoted 1 line
I'll make the function return NULL,
-ENOENT, or-EILSEQ.
Ok.
Quoted 12 lines
Quoted 11 lines
drivers/reset/core.c struct reset_control *__of_reset_control_get(struct device_node *node, · line 304
Quoted 7 lines
drivers/reset/core.c +1
-1} ret =of_parse_phandle_with_args (node,"resets" ,"#reset-cells" , index, &args);if (ret) -return ERR_PTR (ret); +return optional ?NULL :ERR_PTR (ret);
of_parse_phandle_with_argscan return-ENOENTor-EINVAL. I think-EINVALshould still be returned.
Quoted 1 line
Same as above. I'll make the function return NULL,
-ENOENT, or-EINVAL.
thanks
Philipp