mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* check device_create_file() return code in usb_create_sysfs_intf_files()
@ 2011-03-24 14:31 Sergey Senozhatsky
  2011-03-24 14:42 ` Michal Nazarewicz
  2011-03-24 14:55 ` Alan Stern
  0 siblings, 2 replies; 6+ messages in thread
From: Sergey Senozhatsky @ 2011-03-24 14:31 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Alan Stern, Chris Wright, linux-usb, linux-kernel

Hello,

I just noticed that usb_create_sysfs_intf_files() ignores device_create_file() 
return code and sets intf->sysfs_files_created to 1, even if sysfs_add_file_mode() 
returned -ENOMEM (or later sysfs_add_one() returned -EEXIST).

Shouldn't we check retval for 0 before setting intf->sysfs_files_created?

---

 drivers/usb/core/sysfs.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 6781c36..5a02524 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -856,8 +856,10 @@ int usb_create_sysfs_intf_files(struct usb_interface *intf)
 		alt->string = usb_cache_string(udev, alt->desc.iInterface);
 	if (alt->string)
 		retval = device_create_file(&intf->dev, &dev_attr_interface);
-	intf->sysfs_files_created = 1;
-	return 0;
+	if (retval == 0)
+		intf->sysfs_files_created = 1;
+
+	return retval;
 }
 
 void usb_remove_sysfs_intf_files(struct usb_interface *intf)


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: check device_create_file() return code in usb_create_sysfs_intf_files()
  2011-03-24 14:31 check device_create_file() return code in usb_create_sysfs_intf_files() Sergey Senozhatsky
@ 2011-03-24 14:42 ` Michal Nazarewicz
  2011-03-24 14:56   ` Sergey Senozhatsky
  2011-03-24 14:55 ` Alan Stern
  1 sibling, 1 reply; 6+ messages in thread
From: Michal Nazarewicz @ 2011-03-24 14:42 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Sergey Senozhatsky
  Cc: Alan Stern, Chris Wright, linux-usb, linux-kernel

On Thu, 24 Mar 2011 15:31:16 +0100, Sergey Senozhatsky wrote:
> diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
> index 6781c36..5a02524 100644
> --- a/drivers/usb/core/sysfs.c
> +++ b/drivers/usb/core/sysfs.c
> @@ -856,8 +856,10 @@ int usb_create_sysfs_intf_files(struct  
> usb_interface *intf)
>  		alt->string = usb_cache_string(udev, alt->desc.iInterface);
>  	if (alt->string)
>  		retval = device_create_file(&intf->dev, &dev_attr_interface);
> -	intf->sysfs_files_created = 1;
> -	return 0;
> +	if (retval == 0)
> +		intf->sysfs_files_created = 1;
> +
> +	return retval;
>  }

retval may be uninitialised.  You need to zero it at the beginning of the
function (or somewhere).

> void usb_remove_sysfs_intf_files(struct usb_interface *intf)
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michal "mina86" Nazarewicz    (o o)
ooo +-----<email/xmpp: mnazarewicz@google.com>-----ooO--(_)--Ooo--

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: check device_create_file() return code in usb_create_sysfs_intf_files()
  2011-03-24 14:31 check device_create_file() return code in usb_create_sysfs_intf_files() Sergey Senozhatsky
  2011-03-24 14:42 ` Michal Nazarewicz
@ 2011-03-24 14:55 ` Alan Stern
  2011-03-24 15:05   ` Sergey Senozhatsky
  1 sibling, 1 reply; 6+ messages in thread
From: Alan Stern @ 2011-03-24 14:55 UTC (permalink / raw)
  To: Sergey Senozhatsky
  Cc: Greg Kroah-Hartman, Chris Wright, linux-usb, linux-kernel

On Thu, 24 Mar 2011, Sergey Senozhatsky wrote:

> Hello,
> 
> I just noticed that usb_create_sysfs_intf_files() ignores device_create_file() 
> return code and sets intf->sysfs_files_created to 1, even if sysfs_add_file_mode() 
> returned -ENOMEM (or later sysfs_add_one() returned -EEXIST).
> 
> Shouldn't we check retval for 0 before setting intf->sysfs_files_created?

No.  We want this routine to succeed even if the sysfs files can't be 
created.  The interface string attribute is more or less optional.

It would be okay to add a comment explaining this, so that other people
don't make the same mistake (which has already happened -- you're not
the first).

Alan Stern


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: check device_create_file() return code in usb_create_sysfs_intf_files()
  2011-03-24 14:42 ` Michal Nazarewicz
@ 2011-03-24 14:56   ` Sergey Senozhatsky
  2011-03-24 14:58     ` Michal Nazarewicz
  0 siblings, 1 reply; 6+ messages in thread
From: Sergey Senozhatsky @ 2011-03-24 14:56 UTC (permalink / raw)
  To: Michal Nazarewicz
  Cc: Greg Kroah-Hartman, Alan Stern, Chris Wright, linux-usb, linux-kernel

On (03/24/11 15:42), Michal Nazarewicz wrote:
> >@@ -856,8 +856,10 @@ int usb_create_sysfs_intf_files(struct
> >usb_interface *intf)
> > 		alt->string = usb_cache_string(udev, alt->desc.iInterface);
> > 	if (alt->string)
> > 		retval = device_create_file(&intf->dev, &dev_attr_interface);
> >-	intf->sysfs_files_created = 1;
> >-	return 0;
> >+	if (retval == 0)
> >+		intf->sysfs_files_created = 1;
> >+
> >+	return retval;
> > }
> 
> retval may be uninitialised.  You need to zero it at the beginning of the
> function (or somewhere).
> 

Oops... Yes, indeed. Thanks.

---

 drivers/usb/core/sysfs.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 6781c36..d03c630 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -846,7 +846,7 @@ 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;
+	int retval = -1;
 
 	if (intf->sysfs_files_created || intf->unregistering)
 		return 0;
@@ -856,8 +856,10 @@ int usb_create_sysfs_intf_files(struct usb_interface *intf)
 		alt->string = usb_cache_string(udev, alt->desc.iInterface);
 	if (alt->string)
 		retval = device_create_file(&intf->dev, &dev_attr_interface);
-	intf->sysfs_files_created = 1;
-	return 0;
+	if (retval == 0)
+		intf->sysfs_files_created = 1;
+
+	return retval;
 }
 
 void usb_remove_sysfs_intf_files(struct usb_interface *intf)


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: check device_create_file() return code in usb_create_sysfs_intf_files()
  2011-03-24 14:56   ` Sergey Senozhatsky
@ 2011-03-24 14:58     ` Michal Nazarewicz
  0 siblings, 0 replies; 6+ messages in thread
From: Michal Nazarewicz @ 2011-03-24 14:58 UTC (permalink / raw)
  To: Sergey Senozhatsky
  Cc: Greg Kroah-Hartman, Alan Stern, Chris Wright, linux-usb, linux-kernel

On Thu, 24 Mar 2011 15:56:06 +0100, Sergey Senozhatsky wrote:
> diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
> index 6781c36..d03c630 100644
> --- a/drivers/usb/core/sysfs.c
> +++ b/drivers/usb/core/sysfs.c
> @@ -846,7 +846,7 @@ 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;
> +	int retval = -1;

That should be 0 or some other meaningful value. A literal -1 is definitely
not a good choice.  This is just for future since Alan has explained this
patch is not needed.

> 	if (intf->sysfs_files_created || intf->unregistering)
>  		return 0;

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michal "mina86" Nazarewicz    (o o)
ooo +-----<email/xmpp: mnazarewicz@google.com>-----ooO--(_)--Ooo--

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: check device_create_file() return code in usb_create_sysfs_intf_files()
  2011-03-24 14:55 ` Alan Stern
@ 2011-03-24 15:05   ` Sergey Senozhatsky
  0 siblings, 0 replies; 6+ messages in thread
From: Sergey Senozhatsky @ 2011-03-24 15:05 UTC (permalink / raw)
  To: Alan Stern; +Cc: Greg Kroah-Hartman, Chris Wright, linux-usb, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 823 bytes --]

On (03/24/11 10:55), Alan Stern wrote:
> > I just noticed that usb_create_sysfs_intf_files() ignores device_create_file() 
> > return code and sets intf->sysfs_files_created to 1, even if sysfs_add_file_mode() 
> > returned -ENOMEM (or later sysfs_add_one() returned -EEXIST).
> > 
> > Shouldn't we check retval for 0 before setting intf->sysfs_files_created?
> 
> No.  We want this routine to succeed even if the sysfs files can't be 
> created.  The interface string attribute is more or less optional.
> 
> It would be okay to add a comment explaining this, so that other people
> don't make the same mistake (which has already happened -- you're not
> the first).
> 

Thanks. Sorry for the noise then.
Well, in that case, I guess, `int retval;' can be removed, since it's 
unused.


Best,
	Sergey

[-- Attachment #2: Type: application/pgp-signature, Size: 316 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-03-24 15:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-24 14:31 check device_create_file() return code in usb_create_sysfs_intf_files() Sergey Senozhatsky
2011-03-24 14:42 ` Michal Nazarewicz
2011-03-24 14:56   ` Sergey Senozhatsky
2011-03-24 14:58     ` Michal Nazarewicz
2011-03-24 14:55 ` Alan Stern
2011-03-24 15:05   ` Sergey Senozhatsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®