Message ID | 4780418.GXAFRqVoOG@kreacher |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp393602wrn; Fri, 20 Jan 2023 11:50:20 -0800 (PST) X-Google-Smtp-Source: AMrXdXtSIZHPDQ5dWkYtU9S0qXTQi9YE/jnldIPQX5YOqGFT6ieoHt5ZLBXVUKyDv+Srm+2hg7JP X-Received: by 2002:a17:906:489b:b0:850:52f8:5ca9 with SMTP id v27-20020a170906489b00b0085052f85ca9mr16355115ejq.28.1674244219949; Fri, 20 Jan 2023 11:50:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674244219; cv=none; d=google.com; s=arc-20160816; b=reUOwHDSzFpQDqioTyojFH4zxE4dYqUSMnl9bbJC2GjvyP5ooF8+ynDiJHsKqmrpvT O5vgVS61IArmXgwh7BGvZVF/AF904DWtkON2ELqYpoxDyM0iDHw2+41anTh2Yzmx8rv+ 4gLwbeaSXfPNuw2Ddat3Z9ZAPUiHfccQfyjA6mCJV1eRaIdBw93j2Jv6cf4DcaPA2Oh9 Y5F6PSW9MYtvujFxr55bRjGBlq/ZAk+ypJ7GUNLEIhf/oxyo0p3nLJdg3h7nKxByUwY1 3jEWNnjckFxpb3prPd/oXlkKUgFslZAKuU9RGHnJUXuKUbR0TFgtV61RaAULbMTXbjCx 3pqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=g7VaidTW8f1TzmOqU0QMokVgFmF2iCPwVDvhwLhafIE=; b=BaJAtrHuq5EhLKlqhPFCjKb6Gw/OrTPGACYYqSJeWlftGQa+s0nue8sCoKEXVgEHP2 P1mT9LvCfhzKFZGd3l0YW61iykbfcts9tGgOIln+fdJmoa0IlPhdJ3Mu+97iURtKmJFF 8JqXG7+dgJ14qOVcC6vADlM2kE6hwzD6avHRF8IyExg3IRATYZTQ8ta+hl0BZzVvidQu j593N0Y6SxGBgENkVkcMTYwSqsOB9TiqtAZjqehfhAjdTnE64NYF/AZiG8Uc1nQepJLn gBT3pdQ5uiCFOWeg1YVtCE524xFteDdIJnk7p667SwymOTJWsEuRdJ+VauYdfwXlvP5C L6Ug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sd34-20020a1709076e2200b008705d5bb5d1si18700271ejc.951.2023.01.20.11.49.56; Fri, 20 Jan 2023 11:50:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229915AbjATTs4 (ORCPT <rfc822;forouhar.linux@gmail.com> + 99 others); Fri, 20 Jan 2023 14:48:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229995AbjATTsl (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 20 Jan 2023 14:48:41 -0500 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DED6A3A583; Fri, 20 Jan 2023 11:48:32 -0800 (PST) Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.1.0) id eb38fa6f8f139020; Fri, 20 Jan 2023 20:48:30 +0100 Received: from kreacher.localnet (unknown [213.134.183.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id E55B723101AB; Fri, 20 Jan 2023 20:48:29 +0100 (CET) From: "Rafael J. Wysocki" <rjw@rjwysocki.net> To: Linux PM <linux-pm@vger.kernel.org>, Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: 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: [PATCH v1 2/2] thermal: Fail object registration if thermal class is not registered Date: Fri, 20 Jan 2023 20:48:07 +0100 Message-ID: <4780418.GXAFRqVoOG@kreacher> In-Reply-To: <5905717.lOV4Wx5bFT@kreacher> References: <5905717.lOV4Wx5bFT@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 213.134.183.98 X-CLIENT-HOSTNAME: 213.134.183.98 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvhedrudduvddgudefvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepvddufedrudefgedrudekfedrleeknecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvddufedrudefgedrudekfedrleekpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeeipdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepghhrvghgkhhhsehlihhnuhigfhhouhhnuggrthhiohhnrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrghdp rhgtphhtthhopehsrhhinhhivhgrshdrphgrnhgurhhuvhgruggrsehlihhnuhigrdhinhhtvghlrdgtohhmpdhrtghpthhtoheprhhuihdriihhrghnghesihhnthgvlhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755572307238690971?= X-GMAIL-MSGID: =?utf-8?q?1755572307238690971?= |
Series |
driver core/thermal: Fail registration of thermal object when thermal_class is not registered
|
|
Commit Message
Rafael J. Wysocki
Jan. 20, 2023, 7:48 p.m. UTC
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(+)
Comments
On 20/01/2023 20:48, 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> Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
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? thanks, greg k-h
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. 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. Oh well, we may as well just allocate it dynamically.
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? > Oh well, we may as well just allocate it dynamically. Allocate what? confused, greg k-h
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/
On Tue, Jan 24, 2023 at 02:57:55PM +0100, Rafael J. Wysocki wrote: > On Tue, Jan 24, 2023 at 7:03 AM Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote: > > > > 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/ That looks good, I like that change, it's much simpler overall. greg k-h
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; +} + 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); + cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); if (!cdev) return ERR_PTR(-ENOMEM); @@ -1342,6 +1345,9 @@ thermal_zone_device_register_with_trips( if (num_trips > 0 && (!ops->get_trip_type || !ops->get_trip_temp) && !trips) return ERR_PTR(-EINVAL); + if (!class_is_registered(&thermal_class)) + return ERR_PTR(-ENODEV); + tz = kzalloc(sizeof(*tz), GFP_KERNEL); if (!tz) return ERR_PTR(-ENOMEM);