Skip to contentSkip to conversation

USB: usb-skeleton.c: fix compilation error and restore kref_put on fail in skel_open

PATCH Superseded Constantine Shulyupin 2 participants 2 messages Oct 7, 2012 – Oct 10, 2012 USB

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 USB: usb-skeleton.c: fix compilation error and restore kref_put on fail in skel_open

From: Constantine Shulyupin <[email protected]>

Function skel_open increments usage count for the device with kref_get and the usage count should be decremented on the function failure.

Some last changes in function skel_open and finally commit 52a7499 Revert "USB: usb-skeleton.c: fix open/disconnect race" introduced a bug in function skel_open, which this patch fixes.

---
 drivers/usb/usb-skeleton.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/usb/usb-skeleton.c +4 -2
index 0616f23..027005b 100644
@@ -113,8 +113,10 @@ static int skel_open(struct inode *inode, struct file *file)
 	mutex_lock(&dev->io_mutex);
 
 	retval = usb_autopm_get_interface(interface);
-	if (retval)
-		goto out_err;
+	if (retval) {
+		kref_put(&dev->kref, skel_delete);
+		goto exit;
+	}
 
 	/* save our object in the file's private structure */
 	file->private_data = dev;
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 20 lines · On Sunday 07 October 2012 11:57:12 Constantine Shulyupin wrote:

From: Constantine Shulyupin <[email protected]>

Function skel_open increments usage count for the device with kref_get and the usage count should be decremented on the function failure.

Some last changes in function skel_open and finally commit 52a7499 Revert "USB: usb-skeleton.c: fix open/disconnect race" introduced a bug in function skel_open, which this patch fixes.

---
 drivers/usb/usb-skeleton.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/usb/usb-skeleton.c +0 -0
index 0616f23..027005b 100644
@@ -113,8 +113,10 @@ static int skel_open(struct inode *inode, struct file *file)
 	mutex_lock(&dev->io_mutex);
 

drivers/usb/usb-skeleton.c static int skel_open(struct inode *inode, struct file *file) · line 122

Quoted 10 lines
drivers/usb/usb-skeleton.c +4 -2
 	retval = usb_autopm_get_interface(interface);
-	if (retval)
-		goto out_err;
+	if (retval) {
+		kref_put(&dev->kref, skel_delete);
+		goto exit;
+	}
 
 	/* save our object in the file's private structure */
 	file->private_data = dev;

Hi,

good catch, but the fix is wrong. You also need to drop the lock.

Regards
Oliver