mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Chris Down <chris@chrisdown.name>
Cc: linux-kernel@vger.kernel.org, Petr Mladek <pmladek@suse.com>,
	kernel-team@fb.com
Subject: Re: [RFC PATCH] printk: console: Allow each console to have its own loglevel
Date: Thu, 19 May 2022 19:45:27 +0200	[thread overview]
Message-ID: <YoaCN+OH6cG0p1CN@kroah.com> (raw)
In-Reply-To: <YoZoXOghSuCy9Bi+@chrisdown.name>

On Thu, May 19, 2022 at 04:55:08PM +0100, Chris Down wrote:
> Greg Kroah-Hartman writes:
> > On Thu, May 19, 2022 at 04:08:04PM +0100, Chris Down wrote:
> > > Greg Kroah-Hartman writes:
> > > > >  struct console {
> > > > >  	char	name[16];
> > > > >  	void	(*write)(struct console *, const char *, unsigned);
> > > > > @@ -179,9 +173,11 @@ struct console {
> > > > >  	void	*data;
> > > > >  	struct	 console *next;
> > > > >  	int	level;
> > > > > -	struct	device classdev;
> > > > > +	struct	device *classdev;
> > > >
> > > > Ick, no, keep the real structure here.  It can properly handle the
> > > > reference counting for the object.  Just correctly clean up in the
> > > > release function, not anywhere else.
> > > 
> > > Sorry, I'm getting more and more confused about what you're asking me to do,
> > > and less and less clear on the rationale.
> > > 
> > > Can you please clarify what "correctly cleaning up" would mean for a
> > > non-pointer `struct device'?
> > > 
> > > Is your concern that...
> > > 
> > >     register_console(c)
> > >         device_initialize(c->d)
> > >         device_add(c->d)
> > >     unregister_console(c)
> > >         device_unregister(c->d)      console_classdev_release(c->d)
> > >     register_console(c)
> > >         device_initialize(c->d)  <-- classdev was not previously zeroed out
> > > 				     in console_classdev_release() and bad 				     things may happen
> > 
> > Note, you can not "recycle" a structure in the driver model.  So when
> > the console is unregistered, it should be freed.  When it is registered,
> > it should be created.  Perhaps that is the confusion here?
> 
> I suspect you're close to the source of the confusion. So your point is that
> the `struct console' should be freed when the driver refcount drops to 0
> rather than trying to do it the other way around. Right?

When the "device" refcount, not driver.  refcounts are for data.

> So, just to try to come to a solution, here's the lay of the land as I
> understand it. Currently pretty much all consoles are statically defined
> (and most of the non-static cases are false positives)
> 
>     % git grep 'struct console.*=' -- '*.c' | awk '/static/ { print "static"; } !/static/ { print "non-static" }' | sort | uniq -c
>          15 non-static
>         105 static

ah, ok, then we have a problem, and your change to the struct device
being a pointer is correct.

That's the problem when you only see a tiny bit of the kernel in a
patch, sorry for the confusion.

But you still need to free the device structure that is pointed to by
the device in the release function.  Your release function can not be
"empty" like your original patch was.

thanks,

greg k-h

  reply	other threads:[~2022-05-19 17:45 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-18 14:24 Chris Down
2022-05-18 14:32 ` Chris Down
2022-05-18 15:34 ` Greg Kroah-Hartman
2022-05-18 19:46   ` Chris Down
2022-05-18 19:54     ` Greg Kroah-Hartman
2022-05-18 20:27       ` Chris Down
2022-05-19  7:04         ` Greg Kroah-Hartman
2022-05-19 14:12           ` Chris Down
2022-05-19 14:35             ` Greg Kroah-Hartman
2022-05-19 15:08               ` Chris Down
2022-05-19 15:24                 ` Greg Kroah-Hartman
2022-05-19 15:25                 ` Greg Kroah-Hartman
2022-05-19 15:55                   ` Chris Down
2022-05-19 17:45                     ` Greg Kroah-Hartman [this message]
2022-05-19 17:55                       ` Chris Down
2022-05-24  9:19     ` Petr Mladek
2022-05-30 10:48       ` [OFFLIST] " Chris Down
2022-05-30 10:49         ` Chris Down
2022-05-19  7:26 ` Geert Uytterhoeven
2022-05-19 14:37   ` Chris Down
2022-05-19 17:48     ` Geert Uytterhoeven
2022-05-19 18:05       ` Chris Down
2022-05-19 13:59 ` [printk] 6f922c8d53: BUG:kernel_NULL_pointer_dereference,address kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YoaCN+OH6cG0p1CN@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=chris@chrisdown.name \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmladek@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®