All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Sergey Shtylyov <s.shtylyov@omp.ru>
Cc: Peter Chen <peter.chen@kernel.org>, linux-usb@vger.kernel.org
Subject: Re: [PATCH] usb: common: usb-otg-fsm: drop unreachable code in otg_statemachine()
Date: Wed, 9 Feb 2022 12:33:50 +0100	[thread overview]
Message-ID: <YgOmnsR2YJiyctGg@kroah.com> (raw)
In-Reply-To: <aa29a5b5-f45a-c08c-a955-4f48bd9e4920@omp.ru>

On Wed, Feb 09, 2022 at 01:33:53PM +0300, Sergey Shtylyov wrote:
> On 2/9/22 8:35 AM, Greg Kroah-Hartman wrote:
> 
> >> The *switch* statement in otg_statemachine() does handle all possible OTG
> >> states explicitly, so the *default* label is unreachable.
> >>
> >> Found by Linux Verification Center (linuxtesting.org) with the SVACE static
> >> analysis tool.
> >>
> >> Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>
> >>
> >> ---
> >> This patch is against the 'usb-next' branch of Greg KH's 'usb.git' repo.
> >> Peter Chen's 'usb.git' repo seems outdated, so I chose to ignore it...
> >>
> >>  drivers/usb/common/usb-otg-fsm.c |    2 --
> >>  1 file changed, 2 deletions(-)
> >>
> >> Index: usb/drivers/usb/common/usb-otg-fsm.c
> >> ===================================================================
> >> --- usb.orig/drivers/usb/common/usb-otg-fsm.c
> >> +++ usb/drivers/usb/common/usb-otg-fsm.c
> >> @@ -440,8 +440,6 @@ int otg_statemachine(struct otg_fsm *fsm
> >>  		if (fsm->id || fsm->a_bus_drop || fsm->a_clr_err)
> >>  			otg_set_state(fsm, OTG_STATE_A_WAIT_VFALL);
> >>  		break;
> >> -	default:
> >> -		break;
> >>  	}
> >>  	mutex_unlock(&fsm->lock);
> >>  
> > 
> > There is nothing wrong with leaving lines like this in the code to
> > handle any potential bugs.
> > Why do you think it needs to be removed?  What benefit does this patch
> > have?
> 
>    These lines as they are bring no value at all.
>    Note that (as I said)  all the values of 'enum usb_otg_state' are
> already handled with explicit *case* label...

And so now you will trigger the checkers that ask "you do not have a
default: line for your case statement!"

This is safer as is, please do not "clean up" things that are not
actually a problem.

thanks,

greg k-h

      reply	other threads:[~2022-02-09 12:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-08 20:32 [PATCH] usb: common: usb-otg-fsm: drop unreachable code in otg_statemachine() Sergey Shtylyov
2022-02-09  5:35 ` Greg Kroah-Hartman
2022-02-09 10:33   ` Sergey Shtylyov
2022-02-09 11:33     ` Greg Kroah-Hartman [this message]

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=YgOmnsR2YJiyctGg@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=peter.chen@kernel.org \
    --cc=s.shtylyov@omp.ru \
    /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.