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 282a4b7181 ("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 <imv4bel@gmail.com>
Signed-off-by: Eli Billauer <eli.billauer@gmail.com>
Link: https://lore.kernel.org/r/20221117071825.3942-1-eli.billauer@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Eli Billauer 2022-11-17 09:18:25 +02:00 committed by Greg Kroah-Hartman
parent 0ef77698b8
commit c002f04c0b
1 changed files with 4 additions and 3 deletions

View File

@ -227,14 +227,15 @@ int xillybus_find_inode(struct inode *inode,
break;
}
if (!unit) {
mutex_unlock(&unit_mutex);
if (!unit)
return -ENODEV;
}
*private_data = unit->private_data;
*index = minor - unit->lowest_minor;
mutex_unlock(&unit_mutex);
return 0;
}
EXPORT_SYMBOL(xillybus_find_inode);