Skip to contentSkip to conversation

drivers/usb/core/sysfs.c Fix variable 'retval' set but not used

PATCH In review Justin P. Mattock 4 participants 13 messages Aug 3, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drivers/usb/core/sysfs.c Fix variable 'retval' set but not used

The below fixes a warning generated by GCC:
CC drivers/usb/core/sysfs.o
drivers/usb/core/sysfs.c: In function 'usb_create_sysfs_intf_files':
drivers/usb/core/sysfs.c:889:6: warning: variable 'retval' set but not used

Let me know if these are totally wrong etc.. And I'll try my best to resend properly..

---
 drivers/usb/core/sysfs.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/usb/core/sysfs.c +1 -2
index 448f5b4..af56b3e 100644
@@ -886,7 +886,6 @@ int usb_create_sysfs_intf_files(struct usb_interface *intf)
 {
 	struct usb_device *udev = interface_to_usbdev(intf);
 	struct usb_host_interface *alt = intf->cur_altsetting;
-	int retval;
 
 	if (intf->sysfs_files_created || intf->unregistering)
 		return 0;
@@ -895,7 +894,7 @@ int usb_create_sysfs_intf_files(struct usb_interface *intf)
 			!(udev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS))
 		alt->string = usb_cache_string(udev, alt->desc.iInterface);
 	if (alt->string)
-		retval = device_create_file(&intf->dev, &dev_attr_interface);
+		device_create_file(&intf->dev, &dev_attr_interface);
 	intf->sysfs_files_created = 1;
 	return 0;
 }
Signature · 1 line
1.7.1.rc1.21.gf3bd6
#1 lore raw

PATCH 2/2 drivers/usb/host/ehci-hub.c Fix variable 'i' set but not used

The below fixes a build warning from GCC:

drivers/usb/host/ehci-hub.c: In function 'create_companion_file':
drivers/usb/host/ehci-hub.c:533:6: warning: variable 'i' set but not used

Let me know if these are totally wrong etc.. And I'll try my best to resend properly..

---
 drivers/usb/host/ehci-hub.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/usb/host/ehci-hub.c +1 -2
index e7d3d8d..dc7290f 100644
@@ -530,11 +530,10 @@ static DEVICE_ATTR(companion, 0644, show_companion, store_companion);
 
 static inline void create_companion_file(struct ehci_hcd *ehci)
 {
-	int	i;
 
 	/* with integrated TT there is no companion! */
 	if (!ehci_is_TDI(ehci))
-		i = device_create_file(ehci_to_hcd(ehci)->self.controller,
+		device_create_file(ehci_to_hcd(ehci)->self.controller,
 				       &dev_attr_companion);
 }
 
Signature · 1 line
1.7.1.rc1.21.gf3bd6
#2 lore raw
In reply to Justin P. Mattock

drivers/usb/core/sysfs.c int usb_create_sysfs_intf_files(struct usb_interface *intf) · line 899

Quoted 7 lines · Justin P. Mattock
drivers/usb/core/sysfs.c +1 -1
 
 	if (alt->string)
-		retval = device_create_file(&intf->dev, &dev_attr_interface);
+		device_create_file(&intf->dev, &dev_attr_interface);
 	intf->sysfs_files_created = 1;
 	return 0;

What should the code do if device_create_file() manages to fail? Yes, ignoring the return value is one option, but is it the best one? 'return ret;' might be another one. Somebody who understands this code and has more caffeine than me should look this over.

(Nothing personal Justin - it's just my opinion that *anytime* we have a patch that remove a check for a return code, it needs to justify that ignoring the return code is appropriate).

#3 lore raw
Quoted 14 lines · On 08/03/2010 04:28 AM, [email protected] wrote:

drivers/usb/core/sysfs.c int usb_create_sysfs_intf_files(struct usb_interface *intf) · line 899

Quoted 7 lines · Justin P. Mattock
drivers/usb/core/sysfs.c +1 -1
 
  	if (alt->string)
-		retval = device_create_file(&intf->dev,&dev_attr_interface);
+		device_create_file(&intf->dev,&dev_attr_interface);
  	intf->sysfs_files_created = 1;
  	return 0;

What should the code do if device_create_file() manages to fail? Yes, ignoring the return value is one option, but is it the best one? 'return ret;' might be another one. Somebody who understands this code and has more caffeine than me should look this over.

ignoring the return value is one option, but is it the best one? probably not. As for return ret; the option did cross my mind, but figured to do what I had done by removing the retval

Quoted 4 lines

(Nothing personal Justin - it's just my opinion that *anytime* we have a patch that remove a check for a return code, it needs to justify that ignoring the return code is appropriate).

nothing personal taken.. in fact I agree with that whole paragraph. looking back I should of really explained why I was removing this code besides a warning message.

Thanks for the response and info on this..

Justin P. Mattock

maintainer
#4 lore raw
In reply to [email protected]
Quoted 8 lines · On Tue, 3 Aug 2010 [email protected] wrote:

drivers/usb/core/sysfs.c int usb_create_sysfs_intf_files(struct usb_interface *intf) · line 899

Quoted 7 lines · Justin P. Mattock
drivers/usb/core/sysfs.c +1 -1
 
 	if (alt->string)
-		retval = device_create_file(&intf->dev, &dev_attr_interface);
+		device_create_file(&intf->dev, &dev_attr_interface);
 	intf->sysfs_files_created = 1;
 	return 0;

Justin, did you try compiling your new code? Those unused values are there because device_create_file is declared as __must_check.

Quoted 4 lines

What should the code do if device_create_file() manages to fail? Yes, ignoring the return value is one option, but is it the best one? 'return ret;' might be another one. Somebody who understands this code and has more caffeine than me should look this over.

Failure to create a file in sysfs is almost never fatal and usually not even dangerous. Ignoring the error is generally better than failing the entire operation.

Alan Stern

#5 lore raw
Quoted 5 lines · Alan Stern
Quoted 3 lines · On Tue, 3 Aug 2010 [email protected] wrote:
Quoted 1 line · Justin P. Mattock
drivers/usb/core/sysfs.c +0 -0
Quoted 9 lines
Quoted 5 lines

drivers/usb/core/sysfs.c int usb_create_sysfs_intf_files(struct usb_interface *intf) · line 899

Quoted 5 lines

if (alt->string)

drivers/usb/core/sysfs.c +1 -1
-		retval = device_create_file(&intf->dev,&dev_attr_interface);
+		device_create_file(&intf->dev,&dev_attr_interface);
  	intf->sysfs_files_created = 1;
  	return 0;

Justin, did you try compiling your new code? Those unused values are there because device_create_file is declared as __must_check.

I went as far as compiling, once I saw no warning then figured o.k
I'll send out what I have for feedback then go from there.
(and just for the record I want to thank those who took the time to go through and give feedback).

Quoted 5 lines
Quoted 4 lines

What should the code do if device_create_file() manages to fail? Yes, ignoring the return value is one option, but is it the best one? 'return ret;' might be another one. Somebody who understands this code and has more caffeine than me should look this over.

Quoted 7 lines

Failure to create a file in sysfs is almost never fatal and usually not even dangerous. Ignoring the error is generally better than failing the entire operation.

Alan Stern

ahh.. you made this more clear for me.. cool thanks!

Justin P. Mattock

maintainer
#6 lore raw
Quoted 16 lines · Justin P. Mattock
Quoted 5 lines · Alan Stern
Quoted 3 lines · On Tue, 3 Aug 2010 [email protected] wrote:
Quoted 1 line · Justin P. Mattock
drivers/usb/core/sysfs.c +0 -0
Quoted 9 lines
Quoted 5 lines

drivers/usb/core/sysfs.c int usb_create_sysfs_intf_files(struct usb_interface *intf) · line 899

Quoted 5 lines

if (alt->string)

drivers/usb/core/sysfs.c +1 -1
-		retval = device_create_file(&intf->dev,&dev_attr_interface);
+		device_create_file(&intf->dev,&dev_attr_interface);
  	intf->sysfs_files_created = 1;
  	return 0;

Justin, did you try compiling your new code? Those unused values are there because device_create_file is declared as __must_check.

Quoted 4 lines

I went as far as compiling, once I saw no warning then figured o.k I'll send out what I have for feedback then go from there. (and just for the record I want to thank those who took the time to go through and give feedback).

It's a little surprising that you didn't get any warning. I guess you don't have CONFIG_ENABLE_MUST_CHECK turned on.

Alan Stern

#7 lore raw
Quoted 23 lines · Alan Stern
Quoted 16 lines · Justin P. Mattock
Quoted 5 lines · Alan Stern
Quoted 3 lines · On Tue, 3 Aug 2010 [email protected] wrote:
Quoted 1 line · Justin P. Mattock
drivers/usb/core/sysfs.c +0 -0
Quoted 9 lines
Quoted 5 lines

drivers/usb/core/sysfs.c int usb_create_sysfs_intf_files(struct usb_interface *intf) · line 899

Quoted 5 lines
   	if (alt->string)
drivers/usb/core/sysfs.c +1 -1
-		retval = device_create_file(&intf->dev,&dev_attr_interface);
+		device_create_file(&intf->dev,&dev_attr_interface);
   	intf->sysfs_files_created = 1;
   	return 0;

Justin, did you try compiling your new code? Those unused values are there because device_create_file is declared as __must_check.

Quoted 4 lines

I went as far as compiling, once I saw no warning then figured o.k I'll send out what I have for feedback then go from there. (and just for the record I want to thank those who took the time to go through and give feedback).

Quoted 6 lines

It's a little surprising that you didn't get any warning. I guess you don't have CONFIG_ENABLE_MUST_CHECK turned on.

Alan Stern

no nothing.. just the original warning.. as for MUST_CHECK yeah your right it's off.

Justin P. Mattock

#8 lore raw
In reply to Alan Stern
Quoted 14 lines · Alan Stern
Quoted 8 lines · On Tue, 3 Aug 2010 [email protected] wrote:

drivers/usb/core/sysfs.c int usb_create_sysfs_intf_files(struct usb_interface *intf) · line 899

Quoted 7 lines · Justin P. Mattock
drivers/usb/core/sysfs.c +1 -1
 
 	if (alt->string)
-		retval = device_create_file(&intf->dev, &dev_attr_interface);
+		device_create_file(&intf->dev, &dev_attr_interface);
 	intf->sysfs_files_created = 1;
 	return 0;

Justin, did you try compiling your new code? Those unused values are there because device_create_file is declared as __must_check.

Quoted 8 lines
Quoted 4 lines

What should the code do if device_create_file() manages to fail? Yes, ignoring the return value is one option, but is it the best one? 'return ret;' might be another one. Somebody who understands this code and has more caffeine than me should look this over.

Failure to create a file in sysfs is almost never fatal and usually not even dangerous. Ignoring the error is generally better than failing the entire operation.

Then why the __must_check attribute if it's usually ignorable? I thought that was reserved for functions that you damned sight better well check for errors because bad things are afoot otherwise?

maintainer
#9 lore raw
Quoted 7 lines · On Tue, 3 Aug 2010 [email protected] wrote:
Quoted 3 lines

Failure to create a file in sysfs is almost never fatal and usually not even dangerous. Ignoring the error is generally better than failing the entire operation.

Then why the __must_check attribute if it's usually ignorable? I thought that was reserved for functions that you damned sight better well check for errors because bad things are afoot otherwise?

That's a good question. Perhaps Greg KH knows the answer.

Alan Stern

#10 lore raw
Quoted 11 lines · Alan Stern
Quoted 7 lines · On Tue, 3 Aug 2010 [email protected] wrote:
Quoted 3 lines

Failure to create a file in sysfs is almost never fatal and usually not even dangerous. Ignoring the error is generally better than failing the entire operation.

Then why the __must_check attribute if it's usually ignorable? I thought that was reserved for functions that you damned sight better well check for errors because bad things are afoot otherwise?

That's a good question. Perhaps Greg KH knows the answer.

You should check the return value for that function. To not do that is a bug. This one looks like it snuck through. Fixing it properly is the correct thing to do.

thanks,

greg k-h

maintainer
#11 lore raw
Quoted 11 lines · Greg KH
Quoted 10 lines · Alan Stern
Quoted 7 lines · On Tue, 3 Aug 2010 [email protected] wrote:
Quoted 3 lines

Failure to create a file in sysfs is almost never fatal and usually not even dangerous. Ignoring the error is generally better than failing the entire operation.

Then why the __must_check attribute if it's usually ignorable? I thought that was reserved for functions that you damned sight better well check for errors because bad things are afoot otherwise?

Quoted 5 lines
Quoted 1 line

That's a good question. Perhaps Greg KH knows the answer.

You should check the return value for that function. To not do that is a bug. This one looks like it snuck through. Fixing it properly is the correct thing to do.

In other words, usb_set_configuration() should fail if usb_create_sysfs_intf_files() is unable to create the attribute file containing an interface's string descriptor?

And likewise, ehci_run() should fail if the "companion" and debugging files can't be created?

Alan Stern

#12 lore raw
Quoted 19 lines · Alan Stern
Quoted 11 lines · Greg KH
Quoted 10 lines · Alan Stern
Quoted 7 lines · On Tue, 3 Aug 2010 [email protected] wrote:
Quoted 3 lines

Failure to create a file in sysfs is almost never fatal and usually not even dangerous. Ignoring the error is generally better than failing the entire operation.

Then why the __must_check attribute if it's usually ignorable? I thought that was reserved for functions that you damned sight better well check for errors because bad things are afoot otherwise?

Quoted 5 lines
Quoted 1 line

That's a good question. Perhaps Greg KH knows the answer.

You should check the return value for that function. To not do that is a bug. This one looks like it snuck through. Fixing it properly is the correct thing to do.

Quoted 6 lines

In other words, usb_set_configuration() should fail if usb_create_sysfs_intf_files() is unable to create the attribute file containing an interface's string descriptor?

And likewise, ehci_run() should fail if the "companion" and debugging files can't be created?

Ah, yeah, now I recall why we didn't do anything with those values :)

It's best to continue on. Perhaps we should just emit a warning to the system log if the file fails to be created and move on. That would properly handle the return value and keep gcc, and everyone else, happy.

thanks,

greg k-h