From: Zijun Hu <quic_zijuhu@quicinc.com>
ERR_CAST() is normally used to cast an error-valued pointer type to
another different type, But the first ERR_CAST() is to cast away the
const in fwnode_create_software_node().
Add comment for this unusual ERR_CAST() usage.
Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
drivers/base/swnode.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index b1726a3515f6fbe13c2186af1f74479263798e42..67040fff99b02c43999b175c2ba7e6d04322a446 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -933,6 +933,7 @@ fwnode_create_software_node(const struct property_entry *properties,
struct software_node *node;
struct swnode *p;
+ /* Only cast away the const by ERR_CAST() */
if (IS_ERR(parent))
return ERR_CAST(parent);
--
2.34.1
On Thu, Apr 10, 2025 at 09:12:11PM +0800, Zijun Hu wrote: > From: Zijun Hu <quic_zijuhu@quicinc.com> > > ERR_CAST() is normally used to cast an error-valued pointer type to > another different type, But the first ERR_CAST() is to cast away the > const in fwnode_create_software_node(). > > Add comment for this unusual ERR_CAST() usage. ... > + /* Only cast away the const by ERR_CAST() */ > if (IS_ERR(parent)) > return ERR_CAST(parent); TBH, I don't see the value of this comment. And looking into the code, I would rather drop this part. The current users do not rely on the any specific code to be returned and also they check parent to be valid beforehand. But let's hear others first. -- With Best Regards, Andy Shevchenko
On 2025/4/14 16:00, Andy Shevchenko wrote: >> From: Zijun Hu <quic_zijuhu@quicinc.com> >> >> ERR_CAST() is normally used to cast an error-valued pointer type to >> another different type, But the first ERR_CAST() is to cast away the >> const in fwnode_create_software_node(). >> >> Add comment for this unusual ERR_CAST() usage. > ... > >> + /* Only cast away the const by ERR_CAST() */ >> if (IS_ERR(parent)) >> return ERR_CAST(parent); > TBH, I don't see the value of this comment. And looking into the code, I would thank you Andy for comments. will drop this patch in v2. > rather drop this part. The current users do not rely on the any specific code > to be returned and also they check parent to be valid beforehand. > > But let's hear others first.
© 2016 - 2026 Red Hat, Inc.