diff mbox

platform/x86: sony-laptop: Mark expected switch fall-through

Message ID 20180705204703.GA12352@embeddedor.com (mailing list archive)
State Changes Requested, archived
Delegated to: Darren Hart
Headers show

Commit Message

Gustavo A. R. Silva July 5, 2018, 8:47 p.m. UTC
In preparation to enabling -Wimplicit-fallthrough, mark switch cases
where we are expecting to fall through.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 drivers/platform/x86/sony-laptop.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Darren Hart July 6, 2018, 11:24 p.m. UTC | #1
On Thu, Jul 05, 2018 at 03:47:03PM -0500, Gustavo A. R. Silva wrote:
> In preparation to enabling -Wimplicit-fallthrough, mark switch cases
> where we are expecting to fall through.
> 
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
>  drivers/platform/x86/sony-laptop.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
> index b205b03..e614cb7 100644
> --- a/drivers/platform/x86/sony-laptop.c
> +++ b/drivers/platform/x86/sony-laptop.c
> @@ -4427,6 +4427,7 @@ sony_pic_read_possible_resource(struct acpi_resource *resource, void *context)
>  	default:
>  		dprintk("Resource %d isn't an IRQ nor an IO port\n",
>  			resource->type);
> +		/* fall through */

Here too, I wonder if this is intentional. Either way, from what I can see, the
final line in the function:

	return AE_CTRL_TERMINATE;

Is unreachable as there are no "break" statements in the switch, and the default
falls through to return AE_OK. Something doesn't seem right here.
Andy Shevchenko July 7, 2018, 4:19 p.m. UTC | #2
On Sat, Jul 7, 2018 at 2:24 AM, Darren Hart <dvhart@infradead.org> wrote:

>         return AE_CTRL_TERMINATE;
>
> Is unreachable as there are no "break" statements in the switch, and the default
> falls through to return AE_OK. Something doesn't seem right here.

Darren, I didn't look at the code in question, though just to clarify
such error codes.
If the function used in acpi_walk_namespace() or alike, AE_OK means
"To continue", while AE_CTRL_TERMINATE to "stop, whatever we looked
for is found right now".
Mattia Dongili July 7, 2018, 6:56 p.m. UTC | #3
On Fri, Jul 06, 2018 at 04:24:27PM -0700, Darren Hart wrote:
> On Thu, Jul 05, 2018 at 03:47:03PM -0500, Gustavo A. R. Silva wrote:
> > In preparation to enabling -Wimplicit-fallthrough, mark switch cases
> > where we are expecting to fall through.
> > 
> > Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> > ---
> >  drivers/platform/x86/sony-laptop.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
> > index b205b03..e614cb7 100644
> > --- a/drivers/platform/x86/sony-laptop.c
> > +++ b/drivers/platform/x86/sony-laptop.c
> > @@ -4427,6 +4427,7 @@ sony_pic_read_possible_resource(struct acpi_resource *resource, void *context)
> >  	default:
> >  		dprintk("Resource %d isn't an IRQ nor an IO port\n",
> >  			resource->type);
> > +		/* fall through */
> 
> Here too, I wonder if this is intentional. Either way, from what I can see, the
> final line in the function:
> 
> 	return AE_CTRL_TERMINATE;
> 
> Is unreachable as there are no "break" statements in the switch, and the default
> falls through to return AE_OK. Something doesn't seem right here.

I think so too. Looks to me that the default case was meant to return
AE_CTRL_TERMINATE (i.e. swapping it to be last would do).

Having written that code aeons ago, I'm not sure if there is a good
reason to be like that, though it still looks like a bug (that
existed ever since...).

Want to fix it as part of this patch series? Or I can send a patch
myself, let me know.
Darren Hart Sept. 11, 2018, 10:51 p.m. UTC | #4
On Sun, Jul 08, 2018 at 03:56:17AM +0900, Mattia Dongili wrote:
> On Fri, Jul 06, 2018 at 04:24:27PM -0700, Darren Hart wrote:
> > On Thu, Jul 05, 2018 at 03:47:03PM -0500, Gustavo A. R. Silva wrote:
> > > In preparation to enabling -Wimplicit-fallthrough, mark switch cases
> > > where we are expecting to fall through.
> > > 
> > > Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> > > ---
> > >  drivers/platform/x86/sony-laptop.c | 1 +
> > >  1 file changed, 1 insertion(+)
> > > 
> > > diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
> > > index b205b03..e614cb7 100644
> > > --- a/drivers/platform/x86/sony-laptop.c
> > > +++ b/drivers/platform/x86/sony-laptop.c
> > > @@ -4427,6 +4427,7 @@ sony_pic_read_possible_resource(struct acpi_resource *resource, void *context)
> > >  	default:
> > >  		dprintk("Resource %d isn't an IRQ nor an IO port\n",
> > >  			resource->type);
> > > +		/* fall through */
> > 
> > Here too, I wonder if this is intentional. Either way, from what I can see, the
> > final line in the function:
> > 
> > 	return AE_CTRL_TERMINATE;
> > 
> > Is unreachable as there are no "break" statements in the switch, and the default
> > falls through to return AE_OK. Something doesn't seem right here.
> 
> I think so too. Looks to me that the default case was meant to return
> AE_CTRL_TERMINATE (i.e. swapping it to be last would do).
> 
> Having written that code aeons ago, I'm not sure if there is a good
> reason to be like that, though it still looks like a bug (that
> existed ever since...).
> 
> Want to fix it as part of this patch series? Or I can send a patch
> myself, let me know.

Mattia,

I'd prefer to decouple the fix from the implicit fall through discussion. Please
send a separate fix.
diff mbox

Patch

diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
index b205b03..e614cb7 100644
--- a/drivers/platform/x86/sony-laptop.c
+++ b/drivers/platform/x86/sony-laptop.c
@@ -4427,6 +4427,7 @@  sony_pic_read_possible_resource(struct acpi_resource *resource, void *context)
 	default:
 		dprintk("Resource %d isn't an IRQ nor an IO port\n",
 			resource->type);
+		/* fall through */
 
 	case ACPI_RESOURCE_TYPE_END_TAG:
 		return AE_OK;