All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jesús Castro" <x51v4n@gmail.com>
To: Joe Perches <joe@perches.com>
Cc: kys@microsoft.com, haiyangz@microsoft.com,
	sthemmin@microsoft.com, sashal@kernel.org,
	miguel.bernal@zapopan.tecmm.edu.mx, devel@linuxdriverproject.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] hv: utils: fix coding style
Date: Mon, 11 Mar 2019 17:21:12 -0600	[thread overview]
Message-ID: <20190311232110.GA1842@griffin> (raw)
In-Reply-To: <8d9f56e98854efb8858768119d935ac6091cfc50.camel@perches.com>

> > Checkpatch script is showing a coding style error and is showing:
> > 
> > ERROR: else should follow close brace '}'
> > +	}
> > +	else if (hvt->mode == HVUTIL_TRANSPORT_NETLINK) {
> > 
> > This commit fixes the coding style, not a functional change.
> []
> > diff --git a/drivers/hv/hv_utils_transport.c b/drivers/hv/hv_utils_transport.c
> []
> > @@ -139,8 +139,7 @@ static int hvt_op_open(struct inode *inode, struct file *file)
> >  		 * device gets released.
> >  		 */
> >  		hvt->mode = HVUTIL_TRANSPORT_CHARDEV;
> > -	}
> > -	else if (hvt->mode == HVUTIL_TRANSPORT_NETLINK) {
> > +	} else if (hvt->mode == HVUTIL_TRANSPORT_NETLINK) {
> >  		/*
> >  		 * We're switching from netlink communication to using char
> >  		 * device. Issue the reset first.
> 
> Rather than merely shutting up checkpatch warnings,
> please try to improve the code for humans to read.
> 
> This block is probably better as a switch/case and
> the separate bool issue_reset automatic seems
> unnecessary as it's only used in one case.
> 

I'll follow your suggestion and send the v2.

Thanks for your advice to look beyond the scripts, I'll take it into
account for the next patches.

> Perhaps:
> ---
>  drivers/hv/hv_utils_transport.c | 22 +++++++++++-----------
>  1 file changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/hv/hv_utils_transport.c b/drivers/hv/hv_utils_transport.c
> index 832777527936..6b27dd7be9bb 100644
> --- a/drivers/hv/hv_utils_transport.c
> +++ b/drivers/hv/hv_utils_transport.c
> @@ -125,35 +125,35 @@ static int hvt_op_open(struct inode *inode, struct file *file)
>  {
>  	struct hvutil_transport *hvt;
>  	int ret = 0;
> -	bool issue_reset = false;
>  
>  	hvt = container_of(file->f_op, struct hvutil_transport, fops);
>  
>  	mutex_lock(&hvt->lock);
>  
> -	if (hvt->mode == HVUTIL_TRANSPORT_DESTROY) {
> -		ret = -EBADF;
> -	} else if (hvt->mode == HVUTIL_TRANSPORT_INIT) {
> +	switch (hvt->mode) {
> +	case HVUTIL_TRANSPORT_INIT:
>  		/*
>  		 * Switching to CHARDEV mode. We switch bach to INIT when
>  		 * device gets released.
>  		 */
>  		hvt->mode = HVUTIL_TRANSPORT_CHARDEV;
> -	}
> -	else if (hvt->mode == HVUTIL_TRANSPORT_NETLINK) {
> +		break;
> +	case HVUTIL_TRANSPORT_NETLINK:
>  		/*
>  		 * We're switching from netlink communication to using char
>  		 * device. Issue the reset first.
>  		 */
> -		issue_reset = true;
>  		hvt->mode = HVUTIL_TRANSPORT_CHARDEV;
> -	} else {
> +		hvt_reset(hvt);
> +		break;
> +	case HVUTIL_TRANSPORT_DESTROY:
> +		ret = -EBADF;
> +		break;
> +	default:
>  		ret = -EBUSY;
> +		break;
>  	}
>  
> -	if (issue_reset)
> -		hvt_reset(hvt);
> -
>  	mutex_unlock(&hvt->lock);
>  
>  	return ret;
> 
> 

  reply	other threads:[~2019-03-11 23:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-05 23:45 [PATCH] hv: utils: fix coding style Jesús Castro
2019-03-06  0:37 ` Joe Perches
2019-03-11 23:21   ` Jesús Castro [this message]
2019-03-12  0:29 ` [PATCH v2] hv: utils: enhance code for human read Jesús Castro
2019-03-25 22:42   ` Jesús Castro

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=20190311232110.GA1842@griffin \
    --to=x51v4n@gmail.com \
    --cc=devel@linuxdriverproject.org \
    --cc=haiyangz@microsoft.com \
    --cc=joe@perches.com \
    --cc=kys@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miguel.bernal@zapopan.tecmm.edu.mx \
    --cc=sashal@kernel.org \
    --cc=sthemmin@microsoft.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.