Commit 3c01d922 authored by Thadeu Lima de Souza Cascardo's avatar Thadeu Lima de Souza Cascardo Committed by Wentao Guan
Browse files

char: misc: deallocate static minor in error path

stable inclusion
from stable-v6.6.83
commit d43b3f646686070c6aaec068d8f53475571edac3
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBX1M5

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=d43b3f646686070c6aaec068d8f53475571edac3



--------------------------------

commit 6d991f569c5ef6eaeadf1238df2c36e3975233ad upstream.

When creating sysfs files fail, the allocated minor must be freed such that
it can be later reused. That is specially harmful for static minor numbers,
since those would always fail to register later on.

Fixes: 6d04d2b554b1 ("misc: misc_minor_alloc to use ida for all dynamic/misc dynamic minors")
Cc: stable <stable@kernel.org>
Signed-off-by: default avatarThadeu Lima de Souza Cascardo <cascardo@igalia.com>
Link: https://lore.kernel.org/r/20250123123249.4081674-5-cascardo@igalia.com


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit d43b3f646686070c6aaec068d8f53475571edac3)
Signed-off-by: default avatarWentao Guan <guanwentao@uniontech.com>
parent 5107bd83
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -264,8 +264,8 @@ int misc_register(struct miscdevice *misc)
		device_create_with_groups(&misc_class, misc->parent, dev,
					  misc, misc->groups, "%s", misc->name);
	if (IS_ERR(misc->this_device)) {
		if (is_dynamic) {
		misc_minor_free(misc->minor);
		if (is_dynamic) {
			misc->minor = MISC_DYNAMIC_MINOR;
		}
		err = PTR_ERR(misc->this_device);