[PATCH] clk: also return NULL for -ENOENT in devm_clk_get_optional functions

From: Yang Xiwen forbidden405@outlook.com
As described by the doc.
Signed-off-by: Yang Xiwen forbidden405@outlook.com --- Handle both ENODATA and ENOENT. --- include/clk.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/include/clk.h b/include/clk.h index d91285235f..c9aa2360e1 100644 --- a/include/clk.h +++ b/include/clk.h @@ -224,8 +224,9 @@ static inline struct clk *devm_clk_get_optional(struct udevice *dev, const char *id) { struct clk *clk = devm_clk_get(dev, id); + int ret = PTR_ERR(clk);
- if (PTR_ERR(clk) == -ENODATA) + if (ret == -ENODATA || ret == -ENOENT) return NULL;
return clk; @@ -335,7 +336,7 @@ static inline int clk_get_by_name_optional(struct udevice *dev, int ret;
ret = clk_get_by_name(dev, name, clk); - if (ret == -ENODATA) + if (ret == -ENODATA || ret == -ENOENT) return 0;
return ret; @@ -359,7 +360,7 @@ static inline int clk_get_by_name_nodev_optional(ofnode node, const char *name, int ret;
ret = clk_get_by_name_nodev(node, name, clk); - if (ret == -ENODATA) + if (ret == -ENODATA || ret == -ENOENT) return 0;
return ret;
--- base-commit: 580eb31199be8a822e62f20965854a242f895d03 change-id: 20230725-clk-fix-inc-903aa0540739
Best regards,

On Mon, Jul 24, 2023 at 2:32 PM Yang Xiwen via B4 Relay devnull+forbidden405.outlook.com@kernel.org wrote:
From: Yang Xiwen forbidden405@outlook.com
As described by the doc.
Which doc? Please mention the details in the commit log.

On 7/25/2023 1:34 AM, Fabio Estevam wrote:
On Mon, Jul 24, 2023 at 2:32 PM Yang Xiwen via B4 Relay devnull+forbidden405.outlook.com@kernel.org wrote:
From: Yang Xiwen forbidden405@outlook.com
As described by the doc.
Which doc? Please mention the details in the commit log.
It's in the source annotation of devm_clk_get_optional. The annotation says -ENOENT should be handled, but the code doesn't. It handles -ENODATA instead, which confuses me a lot.
The optional functions are introduced to simplify clock consumer's code so that they can assume the struct clk * returned by these functional are either valid or NULL. Not handling ENOENT is not the intended case.
participants (3)
-
Fabio Estevam
-
Yang Xiwen
-
Yang Xiwen via B4 Relay