Skip to contentSkip to conversation

rc: double unlock in rc_register_device()

PATCH In review Dan Carpenter 2 participants 2 messages May 26, 2011

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

PATCH 1/1 rc: double unlock in rc_register_device()

If change_protocol() fails and we goto out_raw, then it calls unlock twice. I noticed that the other time we called change_protocol() we held the &dev->lock, so I changed it to hold it here too.

---
Compile tested only.

drivers/media/rc/rc-main.c +2 -1
index f57cd56..136a6c6 100644
@@ -1097,7 +1097,6 @@ int rc_register_device(struct rc_dev *dev)
 		if (rc < 0)
 			goto out_input;
 	}
-	mutex_unlock(&dev->lock);
 
 	if (dev->change_protocol) {
 		rc = dev->change_protocol(dev, rc_map->rc_type);
@@ -1105,6 +1104,8 @@ int rc_register_device(struct rc_dev *dev)
 			goto out_raw;
 	}
 
+	mutex_unlock(&dev->lock);
+
 	IR_dprintk(1, "Registered rc%ld (driver: %s, remote: %s, mode %s)\n",
 		   dev->devno,
 		   dev->driver_name ? dev->driver_name : "unknown",
Reviewed-by Acked-by on v1 1/1
#1 lore raw
Quoted 2 lines · Dan Carpenter

If change_protocol() fails and we goto out_raw, then it calls unlock twice.

Gah, good catch, I gotta quit adding new bugs... ;)

Quoted 6 lines

I noticed that the other time we called change_protocol() we held the &dev->lock, so I changed it to hold it here too.

---
Compile tested only.

I've sanity-checked the code, and yeah, calling change_protocol() function pointers with the lock held should be perfectly fine here too. The change_protocol functions are device-driver-specific, and don't touch the core rc device lock.

Signature · 2 lines
Jarod Wilson
[email protected]