Commit 1ba0fb42 authored by Zijun Hu's avatar Zijun Hu Committed by Greg Kroah-Hartman
Browse files

char: misc: Does not request module for miscdevice with dynamic minor



misc_open() may request module for miscdevice with dynamic minor, which
is meaningless since:

- The dynamic minor allocated is unknown in advance without registering
  miscdevice firstly.
- Macro MODULE_ALIAS_MISCDEV() is not applicable for dynamic minor.

Fix by only requesting module for miscdevice with fixed minor.

Acked-by: default avatarThadeu Lima de Souza Cascardo <cascardo@igalia.com>
Signed-off-by: default avatarZijun Hu <zijun.hu@oss.qualcomm.com>
Link: https://lore.kernel.org/r/20250714-rfc_miscdev-v6-6-2ed949665bde@oss.qualcomm.com


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 52e2bb5f
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -132,7 +132,8 @@ static int misc_open(struct inode *inode, struct file *file)
		break;
	}

	if (!new_fops) {
	/* Only request module for fixed minor code */
	if (!new_fops && minor < MISC_DYNAMIC_MINOR) {
		mutex_unlock(&misc_mtx);
		request_module("char-major-%d-%d", MISC_MAJOR, minor);
		mutex_lock(&misc_mtx);
@@ -144,9 +145,10 @@ static int misc_open(struct inode *inode, struct file *file)
			new_fops = fops_get(iter->fops);
			break;
		}
	}

	if (!new_fops)
		goto fail;
	}

	/*
	 * Place the miscdevice in the file's