linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Linux PM <linux-pm@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
	Zhang Rui <rui.zhang@intel.com>
Subject: Re: [PATCH v1 2/2] thermal: Fail object registration if thermal class is not registered
Date: Tue, 24 Jan 2023 14:57:55 +0100	[thread overview]
Message-ID: <CAJZ5v0ju0h9FbswXqB9GEy_ZjANvy=6NGday1Qn5PrRV7TkQfw@mail.gmail.com> (raw)
In-Reply-To: <Y890oFSRSG4G2kp6@kroah.com>

On Tue, Jan 24, 2023 at 7:03 AM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> On Mon, Jan 23, 2023 at 09:16:33PM +0100, Rafael J. Wysocki wrote:
> > On Sat, Jan 21, 2023 at 8:40 AM Greg Kroah-Hartman
> > <gregkh@linuxfoundation.org> wrote:
> > >
> > > On Fri, Jan 20, 2023 at 08:48:07PM +0100, Rafael J. Wysocki wrote:
> > > > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > > >
> > > > If thermal_class is not registered with the driver core, there is no way
> > > > to expose the interfaces used by the thermal control framework, so
> > > > prevent thermal zones and cooling devices from being registered in
> > > > that case by returning an error from object registration functions.
> > > >
> > > > For this purpose, introduce class_is_registered() that checks the
> > > > private pointer of the given class and returns 'false' if it is NULL,
> > > > which means that the class has not been registered, and use it in the
> > > > thermal framework.
> > > >
> > > > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > > > ---
> > > >  drivers/thermal/thermal_core.c |    6 ++++++
> > > >  include/linux/device/class.h   |    5 +++++
> > > >  2 files changed, 11 insertions(+)
> > > >
> > > > Index: linux-pm/include/linux/device/class.h
> > > > ===================================================================
> > > > --- linux-pm.orig/include/linux/device/class.h
> > > > +++ linux-pm/include/linux/device/class.h
> > > > @@ -82,6 +82,11 @@ struct class_dev_iter {
> > > >       const struct device_type        *type;
> > > >  };
> > > >
> > > > +static inline bool class_is_registered(struct class *class)
> > > > +{
> > > > +     return !!class->p;
> > >
> > > I really do not like this as it is exposing internals to drivers and
> > > whenever we do that, it gets abused and we have to unwind the mess in a
> > > few years.
> > >
> > > Overall, I'm trying to remove the ->p usage, but that's a longterm goal
> > > of mine (to allow class and bus structures to be in read-only memory),
> > > which isn't your issue here, but it's good to think about why you want
> > > to know this information (more below.)
> > >
> > > > +}
> > > > +
> > > >  extern struct kobject *sysfs_dev_block_kobj;
> > > >  extern struct kobject *sysfs_dev_char_kobj;
> > > >  extern int __must_check __class_register(struct class *class,
> > > > Index: linux-pm/drivers/thermal/thermal_core.c
> > > > ===================================================================
> > > > --- linux-pm.orig/drivers/thermal/thermal_core.c
> > > > +++ linux-pm/drivers/thermal/thermal_core.c
> > > > @@ -880,6 +880,9 @@ __thermal_cooling_device_register(struct
> > > >           !ops->set_cur_state)
> > > >               return ERR_PTR(-EINVAL);
> > > >
> > > > +     if (!class_is_registered(&thermal_class))
> > > > +             return ERR_PTR(-ENODEV);
> > >
> > > If the class isn't registered, then sommething went wrong with the
> > > thermal core code, right?  So why isn't the thermal core keeping a local
> > > variable of "class was registered" and relying on the driver core to
> > > know this?
> > >
> > > The number of individual users that should be doing one thing or another
> > > if a class is not registered feels very very slim.  How come this code
> > > is being called at all if the thermal class was not registered in the
> > > first place?  What would have prevented that from happening?  Is it an
> > > ordering issue, or a kernel configuration issue?
> >
> > It's basically a matter of class_register() returning an error.
>
> Ok, so not a real problem then :)
>
> > Yes, we could use an extra variable for this purpose, but that would
> > be a bit wasteful, because thermal_class will then sit unused and
> > occupy memory in vain.
>
> How would it retain memory if class_register() failed?

The point was that we might use the existing (but not registered)
class object to "flag" the fact that the class could not be used
without adding extra variables.

> > Oh well, we may as well just allocate it dynamically.
>
> Allocate what?

Well, that was a bit terse, sorry.

This patch implements what I meant:
https://patchwork.kernel.org/project/linux-pm/patch/5660360.DvuYhMxLoT@kreacher/

  reply	other threads:[~2023-01-24 13:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-20 19:45 [PATCH v1 0/2] driver core/thermal: Fail registration of thermal object when thermal_class is not registered Rafael J. Wysocki
2023-01-20 19:46 ` [PATCH v1 1/2] driver core: class: Clear private pointer on registration failures Rafael J. Wysocki
2023-01-20 22:43   ` Daniel Lezcano
2023-01-20 19:48 ` [PATCH v1 2/2] thermal: Fail object registration if thermal class is not registered Rafael J. Wysocki
2023-01-20 22:43   ` Daniel Lezcano
2023-01-21  7:40   ` Greg Kroah-Hartman
2023-01-23 20:16     ` Rafael J. Wysocki
2023-01-24  6:03       ` Greg Kroah-Hartman
2023-01-24 13:57         ` Rafael J. Wysocki [this message]
2023-01-24 17:03           ` Greg Kroah-Hartman

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='CAJZ5v0ju0h9FbswXqB9GEy_ZjANvy=6NGday1Qn5PrRV7TkQfw@mail.gmail.com' \
    --to=rafael@kernel.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=rui.zhang@intel.com \
    --cc=srinivas.pandruvada@linux.intel.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;
as well as URLs for NNTP newsgroup(s).