Skip to contentSkip to conversation

char: xillybus: Fix trivial bug with mutex

PATCH New Eli Billauer 1 participant 1 message Nov 17, 2022

Subsystems (3)
lore
Share & tools
lore

Eli Billauer

author maintainer
#0 lore raw

PATCH 1/1 char: xillybus: Fix trivial bug with mutex

@unit_mutex protects @unit from being freed, so obviously it should be released after @unit is used, and not before.

This is a follow-up to commit 282a4b71816b ("char: xillybus: Prevent use-after-free due to race condition") which ensures, among others, the protection of @private_data after @unit_mutex has been released.

---
 drivers/char/xillybus/xillybus_class.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/char/xillybus/xillybus_class.c +4 -3
index 0f238648dcfe..e9a288e61c15 100644
@@ -227,14 +227,15 @@ int xillybus_find_inode(struct inode *inode,
 			break;
 		}
 
-	mutex_unlock(&unit_mutex);
-
-	if (!unit)
+	if (!unit) {
+		mutex_unlock(&unit_mutex);
 		return -ENODEV;
+	}
 
 	*private_data = unit->private_data;
 	*index = minor - unit->lowest_minor;
 
+	mutex_unlock(&unit_mutex);
 	return 0;
 }
 EXPORT_SYMBOL(xillybus_find_inode);
Signature · 1 line
2.17.1