> -----Original Message-----
> From: Greg Kroah-Hartman <[email protected]>
> Sent: Thursday, May 14, 2026 3:00 PM
> To: Justin He <[email protected]>
> Cc: [email protected]; [email protected]; linux-perf-
> [email protected]; [email protected]; kunit-
> [email protected]; [email protected]; linux-
> [email protected]; Arnd Bergmann <[email protected]>; Alexander Viro
> <[email protected]>; Christian Brauner <[email protected]>; Jan Kara
> <[email protected]>; Peter Zijlstra <[email protected]>; Ingo Molnar
> <[email protected]>; Arnaldo Carvalho de Melo <[email protected]>;
> Namhyung Kim <[email protected]>; Mark Rutland
> <[email protected]>; Alexander Shishkin
> <[email protected]>; Jiri Olsa <[email protected]>; Ian
> Rogers <[email protected]>; Adrian Hunter <[email protected]>;
> James Clark <[email protected]>; Brendan Higgins
> <[email protected]>; David Gow <[email protected]>; Rae Moar
> <[email protected]>; Alexander Potapenko <[email protected]>;
> Marco Elver <[email protected]>; Dmitry Vyukov <[email protected]>;
> Andrew Morton <[email protected]>; Paul E. McKenney
> <[email protected]>; Petr Mladek <[email protected]>; Kees Cook
> <[email protected]>; David Disseldorp <[email protected]>
> Subject: Re: [PATCH 5/7] misc: reject duplicate names in misc_register()
> 
> 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 for the feedback.
I’ll drop the two patches that silence the sysfs warning for duplicate 
filenames.

--- 
Cheers,
Justin He(Jia He)

 

Reply via email to