Re: [PATCH 072/141] can: peak_usb: Fix fall-through warnings for Clang

From: Joe Perches
Date: Sat Nov 21 2020 - 14:50:23 EST


On Sat, 2020-11-21 at 14:17 +0100, Marc Kleine-Budde wrote:
> On 11/20/20 7:34 PM, Gustavo A. R. Silva wrote:
> > In preparation to enable -Wimplicit-fallthrough for Clang, fix a warning
> > by explicitly adding a break statement instead of letting the code fall
> > through to the next case.
> >
> > Link: https://github.com/KSPP/linux/issues/115
> > Signed-off-by: Gustavo A. R. Silva <gustavoars@xxxxxxxxxx>
[]
> > diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
[]
> > @@ -299,6 +299,8 @@ static void peak_usb_write_bulk_callback(struct urb *urb)
> >   if (net_ratelimit())
> >   netdev_err(netdev, "Tx urb aborted (%d)\n",
> >   urb->status);
> > + break;
> > +
> >   case -EPROTO:
> >   case -ENOENT:
> >   case -ECONNRESET:
> >
>
> What about moving the default to the end if the case, which is more common anyways:
>
> diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
[]
> @@ -295,16 +295,16 @@ static void peak_usb_write_bulk_callback(struct urb *urb)
>                 netif_trans_update(netdev);
>                 break;
>  
>
> - default:
> - if (net_ratelimit())
> - netdev_err(netdev, "Tx urb aborted (%d)\n",
> - urb->status);
>         case -EPROTO:
>         case -ENOENT:
>         case -ECONNRESET:
>         case -ESHUTDOWN:
> -
>                 break;
> +
> + default:
> + if (net_ratelimit())
> + netdev_err(netdev, "Tx urb aborted (%d)\n",
> + urb->status);

That's fine and is more generally used style but this
default: case should IMO also end with a break;

+ break;

>         }