Skip to contentSkip to conversation

staging: usbip: remove an unnecessary lock in usbip_event_happened. The variable "happened" is local. So I think there is no need to lock here.

PATCH In review Harvey Yang 3 participants 4 messages Nov 5, 2012 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: usbip: remove an unnecessary lock in usbip_event_happened. The variable "happened" is local. So I think there is no need to lock here.

From: harvey.yang <[email protected]>

---
 drivers/staging/usbip/usbip_event.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
drivers/staging/usbip/usbip_event.c +0 -2
index d332a34..668f8e0 100644
@@ -116,10 +116,8 @@ int usbip_event_happened(struct usbip_device *ud)
 {
 	int happened = 0;
 
-	spin_lock(&ud->lock);
 	if (ud->event != 0)
 		happened = 1;
-	spin_unlock(&ud->lock);
 
 	return happened;
 }
Signature · 1 line
1.7.1
#1 lore raw
Quoted 13 lines · Harvey Yang

From: harvey.yang <[email protected]>

---
 drivers/staging/usbip/usbip_event.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
drivers/staging/usbip/usbip_event.c +0 -0
index d332a34..668f8e0 100644

drivers/staging/usbip/usbip_event.c int usbip_event_happened(struct usbip_device *ud) · line 122

Quoted 9 lines
drivers/staging/usbip/usbip_event.c +0 -2
@@ -116,10 +116,8 @@ int usbip_event_happened(struct usbip_device *ud)
 {
 	int happened = 0;
 
-	spin_lock(&ud->lock);
 	if (ud->event != 0)
 		happened = 1;
-	spin_unlock(&ud->lock);
 
 	return happened;

Are you sure that the real fix for this isn't just making 'happened' a static variable? That would make more sense here. Well maybe, the code seems pretty dumb, it's hard to tell what this is supposed to be doing, any ideas?

thanks,

greg k-h

#2 lore raw
In reply to Harvey Yang

Hi,

drivers/staging/usbip/usbip_event.c int usbip_event_happened(struct usbip_device *ud) · line 122

Quoted 8 lines
        int happened = 0;
drivers/staging/usbip/usbip_event.c +0 -2
-       spin_lock(&ud->lock);
        if (ud->event != 0)
                happened = 1;
-       spin_unlock(&ud->lock);
 
        return happened;

I am guessing locking was intended to protect ud->event along with happened so that (checking the value of ud->event and setting value of happened) was atomic.

return ud->event != 0 ? 1 : 0;

Regards.

#3 lore raw

I think no need to make 'happened' static as we just check 'ud->event' feild. Maybe making this function inline would make more sense.

inline int usbip_event_happened(struct usbip_device *ud)

{
        return ud->event ? 1 : 0;
}

Thanks
Harvey

Quoted 18 lines · Prashant Shah

Hi,

drivers/staging/usbip/usbip_event.c int usbip_event_happened(struct usbip_device *ud) · line 122

Quoted 8 lines
        int happened = 0;
drivers/staging/usbip/usbip_event.c +0 -2
-       spin_lock(&ud->lock);
        if (ud->event != 0)
                happened = 1;
-       spin_unlock(&ud->lock);
 
        return happened;

I am guessing locking was intended to protect ud->event along with happened so that (checking the value of ud->event and setting value of happened) was atomic.

return ud->event != 0 ? 1 : 0;

Regards.