Skip to content

Commit 9b242c4

Browse files
billauergregkh
authored andcommitted
char: xillybus: Fix trivial bug with mutex
commit c002f04c0bc79ec00d4beb75fb631d5bf37419bd upstream. @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. Reported-by: Hyunwoo Kim <[email protected]> Signed-off-by: Eli Billauer <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 00baca7 commit 9b242c4

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/char/xillybus/xillybus_class.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,15 @@ int xillybus_find_inode(struct inode *inode,
227227
break;
228228
}
229229

230-
mutex_unlock(&unit_mutex);
231-
232-
if (!unit)
230+
if (!unit) {
231+
mutex_unlock(&unit_mutex);
233232
return -ENODEV;
233+
}
234234

235235
*private_data = unit->private_data;
236236
*index = minor - unit->lowest_minor;
237237

238+
mutex_unlock(&unit_mutex);
238239
return 0;
239240
}
240241
EXPORT_SYMBOL(xillybus_find_inode);

0 commit comments

Comments
 (0)