[v2,3/6] software node: Deduplicate code in fwnode_create_software_node()

Message ID 20210329151207.36619-3-andriy.shevchenko@linux.intel.com (mailing list archive)
State Not Applicable, archived
Headers
Series [v2,1/6] software node: Free resources explicitly when swnode_register() fails |

Commit Message

Andy Shevchenko March 29, 2021, 3:12 p.m. UTC
  Deduplicate conditional and assignment in fwnode_create_software_node(),
i.e. parent is checked in two out of three cases and parent software node
is assigned by to_swnode() call.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v2: no changes
 drivers/base/swnode.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
  

Comments

Daniel Scally March 29, 2021, 9:06 p.m. UTC | #1
Hi Andy

On 29/03/2021 16:12, Andy Shevchenko wrote:
> Deduplicate conditional and assignment in fwnode_create_software_node(),
> i.e. parent is checked in two out of three cases and parent software node
> is assigned by to_swnode() call.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


Reviewed-by: Daniel Scally <djrscally@gmail.com>

> ---
> v2: no changes
>  drivers/base/swnode.c | 17 ++++++++---------
>  1 file changed, 8 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
> index 19aa44bc2628..db982859171e 100644
> --- a/drivers/base/swnode.c
> +++ b/drivers/base/swnode.c
> @@ -973,15 +973,14 @@ fwnode_create_software_node(const struct property_entry *properties,
>  {
>  	struct fwnode_handle *fwnode;
>  	struct software_node *node;
> -	struct swnode *p = NULL;
> -
> -	if (parent) {
> -		if (IS_ERR(parent))
> -			return ERR_CAST(parent);
> -		if (!is_software_node(parent))
> -			return ERR_PTR(-EINVAL);
> -		p = to_swnode(parent);
> -	}
> +	struct swnode *p;
> +
> +	if (IS_ERR(parent))
> +		return ERR_CAST(parent);
> +
> +	p = to_swnode(parent);
> +	if (parent && !p)
> +		return ERR_PTR(-EINVAL);
>  
>  	node = software_node_alloc(properties);
>  	if (IS_ERR(node))
  

Patch

diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index 19aa44bc2628..db982859171e 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -973,15 +973,14 @@  fwnode_create_software_node(const struct property_entry *properties,
 {
 	struct fwnode_handle *fwnode;
 	struct software_node *node;
-	struct swnode *p = NULL;
-
-	if (parent) {
-		if (IS_ERR(parent))
-			return ERR_CAST(parent);
-		if (!is_software_node(parent))
-			return ERR_PTR(-EINVAL);
-		p = to_swnode(parent);
-	}
+	struct swnode *p;
+
+	if (IS_ERR(parent))
+		return ERR_CAST(parent);
+
+	p = to_swnode(parent);
+	if (parent && !p)
+		return ERR_PTR(-EINVAL);
 
 	node = software_node_alloc(properties);
 	if (IS_ERR(node))