Re: [PATCH 10/13] usb: core: config: fix checkpatch.pl braces warning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Oct 05, 2021 at 02:34:03PM +0100, Robert Greener wrote:
> This fixes the following checkpatch.pl warnings:
> 
> core/config.c:268: CHECK:BRACES: braces {} should be used on all arms of this statement
> core/config.c:272: CHECK:BRACES: Unbalanced braces around else statement
> core/config.c:649: CHECK:BRACES: Blank lines aren't necessary after an open brace '{'

This is one aspect of checkpatch I don't understand at all.

> Signed-off-by: Robert Greener <rob@xxxxxxxxxxxxxx>
> ---
>  drivers/usb/core/config.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
> index 9717f89bcb6f..76038e8c84c5 100644
> --- a/drivers/usb/core/config.c
> +++ b/drivers/usb/core/config.c
> @@ -265,11 +265,12 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno,
>  	buffer += d->bLength;
>  	size -= d->bLength;
>  
> -	if (d->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE)
> +	if (d->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE) {
>  		n = USB_DT_ENDPOINT_AUDIO_SIZE;
> -	else if (d->bLength >= USB_DT_ENDPOINT_SIZE)
> +	}

Why is it necessary to add braces to the "if" clause?  The "else"
clause doesn't use braces; it consists of a single "if" statement.
Things would different if the code had been:

	if (d->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE)
		n = USB_DT_ENDPOINT_AUDIO_SIZE;
	else {
		if (d->bLength >= USB_DT_ENDPOINT_SIZE)
			...
	}

Then I would agree that braces were needed.  But it isn't.  After all,
coding-style.rst says "Do not unnecessarily use braces where a single
statement will do."

This seems like a bug in checkpatch.pl.

Alan Stern



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux