* [PATCH] hv: utils: fix coding style
@ 2019-03-05 23:45 Jesús Castro
2019-03-06 0:37 ` Joe Perches
2019-03-12 0:29 ` [PATCH v2] hv: utils: enhance code for human read Jesús Castro
0 siblings, 2 replies; 5+ messages in thread
From: Jesús Castro @ 2019-03-05 23:45 UTC (permalink / raw)
To: kys, haiyangz, sthemmin, sashal
Cc: miguel.bernal, devel, linux-kernel, Jesús Castro
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.
Signed-off-by: Jesús Castro <x51v4n@gmail.com>
---
drivers/hv/hv_utils_transport.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/hv/hv_utils_transport.c b/drivers/hv/hv_utils_transport.c
index 832777527936..eff5419b7b35 100644
--- 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.
--
2.21.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] hv: utils: fix coding style
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
2019-03-12 0:29 ` [PATCH v2] hv: utils: enhance code for human read Jesús Castro
1 sibling, 1 reply; 5+ messages in thread
From: Joe Perches @ 2019-03-06 0:37 UTC (permalink / raw)
To: Jesús Castro, kys, haiyangz, sthemmin, sashal
Cc: miguel.bernal, devel, linux-kernel
On Tue, 2019-03-05 at 17:45 -0600, Jesús Castro wrote:
> 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.
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;
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] hv: utils: fix coding style
2019-03-06 0:37 ` Joe Perches
@ 2019-03-11 23:21 ` Jesús Castro
0 siblings, 0 replies; 5+ messages in thread
From: Jesús Castro @ 2019-03-11 23:21 UTC (permalink / raw)
To: Joe Perches
Cc: kys, haiyangz, sthemmin, sashal, miguel.bernal, devel, linux-kernel
> > 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;
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] hv: utils: enhance code for human read
2019-03-05 23:45 [PATCH] hv: utils: fix coding style Jesús Castro
2019-03-06 0:37 ` Joe Perches
@ 2019-03-12 0:29 ` Jesús Castro
2019-03-25 22:42 ` Jesús Castro
1 sibling, 1 reply; 5+ messages in thread
From: Jesús Castro @ 2019-03-12 0:29 UTC (permalink / raw)
To: kys, haiyangz, sthemmin, sashal
Cc: miguel.bernal, devel, linux-kernel, joe, Jesús Castro, Joe Perches
The if/else block from hvt_op_open function can be written
as a switch/case block, and the bool issue_reset variable
is avoided.
No functional change made.
Suggested-by: Joe Perches <joe@perches.com>
Signed-off-by: Jesús Castro <x51v4n@gmail.com>
---
v2: Refactoring hvt_op_open function with a switch/case block.
Change subject from: fix coding style
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;
--
2.21.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] hv: utils: enhance code for human read
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
0 siblings, 0 replies; 5+ messages in thread
From: Jesús Castro @ 2019-03-25 22:42 UTC (permalink / raw)
To: kys, haiyangz, sthemmin, sashal
Cc: miguel.bernal, devel, linux-kernel, Joe Perches
On Mon, Mar 11, 2019 at 06:29:49PM -0600, Jesús Castro wrote:
> The if/else block from hvt_op_open function can be written
> as a switch/case block, and the bool issue_reset variable
> is avoided.
>
> No functional change made.
>
> Suggested-by: Joe Perches <joe@perches.com>
> Signed-off-by: Jesús Castro <x51v4n@gmail.com>
> ---
>
> v2: Refactoring hvt_op_open function with a switch/case block.
> Change subject from: fix coding style
>
ping?
> 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;
> --
> 2.21.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-03-25 22:42 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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
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).