Skip to contentSkip to conversation

em28xx-i2c: rt_mutex_trylock() returns zero on failure

PATCH Superseded Dan Carpenter 2 participants 3 messages Mar 11, 2016 – May 9, 2016

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

PATCH 1/1 em28xx-i2c: rt_mutex_trylock() returns zero on failure

The code is checking for negative returns but it should be checking for zero.

Fixes aab3125c43d8 ('[media] em28xx: add support for registering multiple i2c buses')

---
Is -EBUSY correct? -EAGAIN?

drivers/media/usb/em28xx/em28xx-i2c.c +2 -3
index a19b5c8..f80dd3a 100644
@@ -507,9 +507,8 @@ static int em28xx_i2c_xfer(struct i2c_adapter *i2c_adap,
 	if (dev->disconnected)
 		return -ENODEV;
 
-	rc = rt_mutex_trylock(&dev->i2c_bus_lock);
-	if (rc < 0)
-		return rc;
+	if (!rt_mutex_trylock(&dev->i2c_bus_lock))
+		return -EBUSY;
 
 	/* Switch I2C bus if needed */
 	if (bus != dev->cur_i2c_bus &&
#1 lore raw

Em Fri, 11 Mar 2016 11:13:01 +0300
Dan Carpenter <[email protected]> escreveu:

Quoted 7 lines

The code is checking for negative returns but it should be checking for zero.

Fixes aab3125c43d8 ('[media] em28xx: add support for registering multiple i2c buses')

---
Is -EBUSY correct? -EAGAIN?

I guess -EAGAIN would be better.

Regards,
Mauro

Quoted 21 lines
drivers/media/usb/em28xx/em28xx-i2c.c +2 -4
index a19b5c8..f80dd3a 100644
@@ -507,9 +507,8 @@ static int em28xx_i2c_xfer(struct i2c_adapter *i2c_adap,
 	if (dev->disconnected)
 		return -ENODEV;
 
-	rc = rt_mutex_trylock(&dev->i2c_bus_lock);
-	if (rc < 0)
-		return rc;
+	if (!rt_mutex_trylock(&dev->i2c_bus_lock))
+		return -EBUSY;
 
 	/* Switch I2C bus if needed */
 	if (bus != dev->cur_i2c_bus &&
--

To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Thanks,
Mauro
#2 lore raw

PATCH v2 1/1 em28xx-i2c: rt_mutex_trylock() returns zero on failure

The code is checking for negative returns but it should be checking for zero.

Fixes aab3125c43d8 ('[media] em28xx: add support for registering multiple i2c buses')

---
Use different error code.

drivers/media/usb/em28xx/em28xx-i2c.c +2 -3
index a19b5c8..1a9e1e5 100644
@@ -507,9 +507,8 @@ static int em28xx_i2c_xfer(struct i2c_adapter *i2c_adap,
 	if (dev->disconnected)
 		return -ENODEV;
 
-	rc = rt_mutex_trylock(&dev->i2c_bus_lock);
-	if (rc < 0)
-		return rc;
+	if (!rt_mutex_trylock(&dev->i2c_bus_lock))
+		return -EAGAIN;
 
 	/* Switch I2C bus if needed */
 	if (bus != dev->cur_i2c_bus &&