lkml.org 
[lkml]   [2019]   [Mar]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH v2] hv: utils: enhance code for human read
    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
    >

    \
     
     \ /
      Last update: 2019-03-25 23:43    [W:4.424 / U:0.336 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site