On Thu, May 14, 2026 at 05:04:53AM +0000, Jia He wrote:
> The miscdev kunit suite registers two miscdevices with the same name
> and expects -EEXIST. The second call currently goes all the way to
> sysfs_create_dir_ns(), which prints "cannot create duplicate filename"
> with a backtrace on every run.
> 
> Walk misc_list under misc_mtx, return -EEXIST on a name collision and
> free the just-allocated minor before returning.
> 
> To: Arnd Bergmann <[email protected]>
> To: Greg Kroah-Hartman <[email protected]>

This should be Cc: right?

> 
> Signed-off-by: Jia He <[email protected]>
> ---
>  drivers/char/misc.c | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/drivers/char/misc.c b/drivers/char/misc.c
> index 726516fb0a3b..d6ffa21ac495 100644
> --- a/drivers/char/misc.c
> +++ b/drivers/char/misc.c
> @@ -248,6 +248,28 @@ int misc_register(struct miscdevice *misc)
>               }
>       }
>  
> +     /*
> +      * Detect duplicate names up-front so the subsequent
> +      * device_create_with_groups() does not trip
> +      * sysfs_create_dir_ns()->sysfs_warn_dup(), which unconditionally
> +      * dumps a stack trace. Both the existing miscdev kunit suite
> +      * (miscdev_test_duplicate_name) and any caller racing on the same
> +      * name would otherwise pollute dmesg on every -EEXIST.
> +      */
> +     {
> +             struct miscdevice *c;
> +
> +             list_for_each_entry(c, &misc_list, list) {
> +                     if (strcmp(c->name, misc->name) == 0) {
> +                             misc_minor_free(misc->minor);
> +                             if (is_dynamic)
> +                                     misc->minor = MISC_DYNAMIC_MINOR;
> +                             err = -EEXIST;
> +                             goto out;
> +                     }
> +             }
> +     }

Don't do additional {} where not needed.

And as the current code works properly, we are relying on sysfs for the
rejection, why do this now here?  The stack dump is good, it shows the
offending caller, so they can fix it up better.  So why change this?

thanks,

greg k-h

Reply via email to