linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan.Cameron@huawei.com (Jonathan Cameron)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 7/8] firmware: arm_scmi: improve exit paths and code readability
Date: Thu, 17 May 2018 10:13:07 +0100	[thread overview]
Message-ID: <20180517094927.0000690f@huawei.com> (raw)
In-Reply-To: <1525885634-22348-8-git-send-email-sudeep.holla@arm.com>

On Wed, 9 May 2018 18:07:13 +0100
Sudeep Holla <sudeep.holla@arm.com> wrote:

> The existing code intends the good path to reduce the code which is so
> uncommon. It's obvious to have more readable code with a goto used for
> the error path. This patch adds more appropriate error paths and makes
> code more readable. It also moves a error logging outside the scope of
> locking.
> 
> Suggested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>

It could be argued the lock move is unrelated and should be in a separate
patch... Not particularly important though.

Some comments inline, but I'm happy with how you did this.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/firmware/arm_scmi/bus.c | 22 ++++++++++++----------
>  1 file changed, 12 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c
> index f2760a596c28..472c88ae1c0f 100644
> --- a/drivers/firmware/arm_scmi/bus.c
> +++ b/drivers/firmware/arm_scmi/bus.c
> @@ -125,13 +125,13 @@ scmi_device_create(struct device_node *np, struct device *parent, int protocol)
>  	int id, retval;
>  	struct scmi_device *scmi_dev;
>  
> -	id = ida_simple_get(&scmi_bus_id, 1, 0, GFP_KERNEL);
> -	if (id < 0)
> -		return NULL;
> -
>  	scmi_dev = kzalloc(sizeof(*scmi_dev), GFP_KERNEL);
>  	if (!scmi_dev)
> -		goto no_mem;
> +		return NULL;
> +
> +	id = ida_simple_get(&scmi_bus_id, 1, 0, GFP_KERNEL);
> +	if (id < 0)
> +		goto free_mem;

I guess this reorder was to match what is done in remove?

Personally I would have reordered remove as that was a one line change, but
it really doesn't matter.

>  
>  	scmi_dev->id = id;
>  	scmi_dev->protocol_id = protocol;
> @@ -141,13 +141,15 @@ scmi_device_create(struct device_node *np, struct device *parent, int protocol)
>  	dev_set_name(&scmi_dev->dev, "scmi_dev.%d", id);
>  
>  	retval = device_register(&scmi_dev->dev);
> -	if (!retval)
> -		return scmi_dev;
> +	if (retval)
> +		goto put_dev;
>  
> +	return scmi_dev;

If you are respinning I'd add a blank line here for readability.

> +put_dev:
>  	put_device(&scmi_dev->dev);
> -	kfree(scmi_dev);
> -no_mem:
>  	ida_simple_remove(&scmi_bus_id, id);
> +free_mem:
> +	kfree(scmi_dev);
>  	return NULL;
>  }
>  
> @@ -171,9 +173,9 @@ int scmi_protocol_register(int protocol_id, scmi_prot_init_fn_t fn)
>  	spin_lock(&protocol_lock);
>  	ret = idr_alloc(&scmi_protocols, fn, protocol_id, protocol_id + 1,
>  			GFP_ATOMIC);
> +	spin_unlock(&protocol_lock);
>  	if (ret != protocol_id)
>  		pr_err("unable to allocate SCMI idr slot, err %d\n", ret);
> -	spin_unlock(&protocol_lock);
>  
>  	return ret;
>  }

  reply	other threads:[~2018-05-17  9:13 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-09 17:07 [PATCH 0/8] firmware: arm_scmi: trivial cleanups Sudeep Holla
2018-05-09 17:07 ` [PATCH 1/8] firmware: arm_scmi: improve code readability using bitfield accessor macros Sudeep Holla
2018-05-17  8:14   ` Jonathan Cameron
2018-05-09 17:07 ` [PATCH 2/8] firmware: arm_scmi: fix kernel-docs documentation Sudeep Holla
2018-05-17  8:30   ` Jonathan Cameron
2018-05-09 17:07 ` [PATCH 3/8] firmware: arm_scmi: rename get_transition_latency and add_opps_to_device Sudeep Holla
2018-05-10  8:29   ` Rafael J. Wysocki
2018-05-10  9:53     ` Sudeep Holla
2018-05-17  8:32   ` Jonathan Cameron
2018-05-09 17:07 ` [PATCH 4/8] firmware: arm_scmi: rename scmi_xfer_{init,get,put} Sudeep Holla
2018-05-17  8:38   ` Jonathan Cameron
2018-05-09 17:07 ` [PATCH 5/8] firmware: arm_scmi: drop unused `con_priv` structure member Sudeep Holla
2018-05-17  8:41   ` Jonathan Cameron
2018-05-09 17:07 ` [PATCH 6/8] firmware: arm_scmi: remove unnecessary bitmap_zero Sudeep Holla
2018-05-17  8:43   ` Jonathan Cameron
2018-05-09 17:07 ` [PATCH 7/8] firmware: arm_scmi: improve exit paths and code readability Sudeep Holla
2018-05-17  9:13   ` Jonathan Cameron [this message]
2018-05-09 17:07 ` [PATCH 8/8] firmware: arm_scmi: simplify exit path by returning on error Sudeep Holla
2018-05-17  9:14   ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180517094927.0000690f@huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).