hv: utils: fix coding style
PATCH 1/1 hv: utils: fix coding style
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.
--- drivers/hv/hv_utils_transport.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/hv/hv_utils_transport.c +1 -2
@@ -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.
Signature · 1 line
2.21.0
Quoted 7 lines · Jesús Castro
Checkpatch script is showing a coding style error and is showing:
ERROR: else should follow close brace '}'
(quoted diff) +2
-0+ } + else if (hvt->mode == HVUTIL_TRANSPORT_NETLINK) {This commit fixes the coding style, not a functional change.
[]
drivers/hv/hv_utils_transport.c
Quoted 1 line
drivers/hv/hv_utils_transport.c +0
-0
[]
drivers/hv/hv_utils_transport.c static int hvt_op_open(struct inode *inode, struct file *file) · line 145
Quoted 10 lines
drivers/hv/hv_utils_transport.c +1
-2@@ -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(-)
drivers/hv/hv_utils_transport.c +11 -11
@@ -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;
Quoted 24 lines
Quoted 7 lines
Checkpatch script is showing a coding style error and is showing:
ERROR: else should follow close brace '}'
(quoted diff) +2
-0+ } + else if (hvt->mode == HVUTIL_TRANSPORT_NETLINK) {This commit fixes the coding style, not a functional change.
[]
drivers/hv/hv_utils_transport.c
Quoted 1 line
drivers/hv/hv_utils_transport.c +0
-0[]
drivers/hv/hv_utils_transport.c static int hvt_op_open(struct inode *inode, struct file *file) · line 145
Quoted 10 lines
drivers/hv/hv_utils_transport.c +1
-2@@ -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.
Quoted 4 lines
This block is probably better as a switch/case and the separate bool
issue_resetautomatic 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.
Quoted 58 lines
Perhaps:
--- drivers/hv/hv_utils_transport.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)drivers/hv/hv_utils_transport.c +11
-11@@ -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;
PATCH v2 1/1 hv: utils: enhance code for human read
In reply to Jesús CastroThe 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.
---
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(-)
drivers/hv/hv_utils_transport.c +11 -11
@@ -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;
Signature · 1 line
2.21.0
Re: [PATCH v2] hv: utils: enhance code for human read
Quoted 4 lines · Jesús Castro
The if/else block from
hvt_op_openfunction can be written as a switch/case block, and the boolissue_resetvariable is avoided.
Quoted 9 lines
No functional change made.
Suggested-by Joe Perches <[email protected]>Signed-off-by Jesús Castro <[email protected]>---
v2: Refactoring
hvt_op_openfunction with a switch/case block.
Change subject from: fix coding style
ping?
Quoted 57 lines
drivers/hv/hv_utils_transport.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)drivers/hv/hv_utils_transport.c +11
-11@@ -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;Signature · 1 line
2.21.0