Re: [PATCH v4 6/8] char: misc: Does not request module for miscdevice with dynamic minor
From: Greg Kroah-Hartman
Date: Sun Jul 06 2025 - 04:56:02 EST
On Fri, Jul 04, 2025 at 09:26:04PM +0800, Zijun Hu wrote:
> From: Zijun Hu <zijun.hu@xxxxxxxxxxxxxxxx>
>
> misc_open() may request module for miscdevice with dynamic minor
> which is meaningless since macro MODULE_ALIAS_MISCDEV() is not
> applicable for dynamic minor.
>
> Fix by only requesting module for miscdevice with fixed minor.
>
> Signed-off-by: Zijun Hu <zijun.hu@xxxxxxxxxxxxxxxx>
> ---
> drivers/char/misc.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/char/misc.c b/drivers/char/misc.c
> index 96ed343cf5c8509a09855020049a9af82a3ede95..a0aae0fc792666a7bdc0ba00da9dc02ff9cead42 100644
> --- a/drivers/char/misc.c
> +++ b/drivers/char/misc.c
> @@ -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,10 +145,11 @@ static int misc_open(struct inode *inode, struct file *file)
> new_fops = fops_get(iter->fops);
> break;
> }
> - if (!new_fops)
> - goto fail;
> }
>
> + if (!new_fops)
> + goto fail;
> +
This is fine, but is it going to break any existing users that happened
to rely on this behaviour?
thanks,
greg k-h