2020-04-18 18:44:50

by Matthew Wilcox

[permalink] [raw]
Subject: Re: [PATCH 5/9] usb: fix empty-body warning in sysfs.c

On Sat, Apr 18, 2020 at 11:41:07AM -0700, Randy Dunlap wrote:
> +++ linux-next-20200327/drivers/usb/core/sysfs.c
> @@ -1263,7 +1263,7 @@ void usb_create_sysfs_intf_files(struct
> if (!alt->string && !(udev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS))
> alt->string = usb_cache_string(udev, alt->desc.iInterface);
> if (alt->string && device_create_file(&intf->dev, &dev_attr_interface))
> - ; /* We don't actually care if the function fails. */
> + do_empty(); /* We don't actually care if the function fails. */
> intf->sysfs_files_created = 1;
> }

Why not just?

+ if (alt->string)
+ device_create_file(&intf->dev, &dev_attr_interface);


2020-04-18 18:47:31

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH 5/9] usb: fix empty-body warning in sysfs.c

On 4/18/20 11:44 AM, Matthew Wilcox wrote:
> On Sat, Apr 18, 2020 at 11:41:07AM -0700, Randy Dunlap wrote:
>> +++ linux-next-20200327/drivers/usb/core/sysfs.c
>> @@ -1263,7 +1263,7 @@ void usb_create_sysfs_intf_files(struct
>> if (!alt->string && !(udev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS))
>> alt->string = usb_cache_string(udev, alt->desc.iInterface);
>> if (alt->string && device_create_file(&intf->dev, &dev_attr_interface))
>> - ; /* We don't actually care if the function fails. */
>> + do_empty(); /* We don't actually care if the function fails. */
>> intf->sysfs_files_created = 1;
>> }
>
> Why not just?
>
> + if (alt->string)
> + device_create_file(&intf->dev, &dev_attr_interface);
>

Yes, looks good. Thanks.

--
~Randy

2020-04-18 19:54:53

by Alan Stern

[permalink] [raw]
Subject: Re: [PATCH 5/9] usb: fix empty-body warning in sysfs.c

On Sat, 18 Apr 2020, Matthew Wilcox wrote:

> On Sat, Apr 18, 2020 at 11:41:07AM -0700, Randy Dunlap wrote:
> > +++ linux-next-20200327/drivers/usb/core/sysfs.c
> > @@ -1263,7 +1263,7 @@ void usb_create_sysfs_intf_files(struct
> > if (!alt->string && !(udev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS))
> > alt->string = usb_cache_string(udev, alt->desc.iInterface);
> > if (alt->string && device_create_file(&intf->dev, &dev_attr_interface))
> > - ; /* We don't actually care if the function fails. */
> > + do_empty(); /* We don't actually care if the function fails. */
> > intf->sysfs_files_created = 1;
> > }
>
> Why not just?
>
> + if (alt->string)
> + device_create_file(&intf->dev, &dev_attr_interface);

This is another __must_check function call.

The reason we don't care if the call fails is because the file
being created holds the USB interface string descriptor, something
which is purely informational and hardly ever gets set (and no doubt
gets used even less often).

Is this another situation where the comment should be expanded and the
code modified to include a useless test and cast-to-void?

Or should device_create_file() not be __must_check after all?

Greg?

Alan Stern