From: Heiner Kallweit <hkallweit1@gmail.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
Pavel Machek <pavel@kernel.org>, Len Brown <lenb@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Danilo Krummrich <dakr@kernel.org>
Cc: Linux PM <linux-pm@vger.kernel.org>, driver-core@lists.linux.dev
Subject: [PATCH] PM / wakeup: Allocate class wakeup_class statically
Date: Sun, 29 Mar 2026 18:14:15 +0200 [thread overview]
Message-ID: <0fe1b679-ab28-4505-b0db-14e7ac3ba749@gmail.com> (raw)
Allocating wakeup_class statically avoids a little runtime overhead.
Define groups and device release function as part of the class, so that
we don't have to repeat this for each class device.
Whilst at it, constify wakeup_source_attrs[].
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/base/power/wakeup_stats.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/base/power/wakeup_stats.c b/drivers/base/power/wakeup_stats.c
index 308f8bde9..72beb8fce 100644
--- a/drivers/base/power/wakeup_stats.c
+++ b/drivers/base/power/wakeup_stats.c
@@ -18,8 +18,6 @@
#include "power.h"
-static struct class *wakeup_class;
-
#define wakeup_attr(_name) \
static ssize_t _name##_show(struct device *dev, \
struct device_attribute *attr, char *buf) \
@@ -114,7 +112,7 @@ static ssize_t prevent_suspend_time_ms_show(struct device *dev,
}
static DEVICE_ATTR_RO(prevent_suspend_time_ms);
-static struct attribute *wakeup_source_attrs[] = {
+static const struct attribute *const wakeup_source_attrs[] = {
&dev_attr_name.attr,
&dev_attr_active_count.attr,
&dev_attr_event_count.attr,
@@ -135,6 +133,12 @@ static void device_create_release(struct device *dev)
kfree(dev);
}
+static const struct class wakeup_class = {
+ .name = "wakeup",
+ .dev_release = device_create_release,
+ .dev_groups = wakeup_source_groups,
+};
+
static struct device *wakeup_source_device_create(struct device *parent,
struct wakeup_source *ws)
{
@@ -149,10 +153,8 @@ static struct device *wakeup_source_device_create(struct device *parent,
device_initialize(dev);
dev->devt = MKDEV(0, 0);
- dev->class = wakeup_class;
+ dev->class = &wakeup_class;
dev->parent = parent;
- dev->groups = wakeup_source_groups;
- dev->release = device_create_release;
dev_set_drvdata(dev, ws);
device_set_pm_not_required(dev);
@@ -212,8 +214,6 @@ void wakeup_source_sysfs_remove(struct wakeup_source *ws)
static int __init wakeup_sources_sysfs_init(void)
{
- wakeup_class = class_create("wakeup");
-
- return PTR_ERR_OR_ZERO(wakeup_class);
+ return class_register(&wakeup_class);
}
postcore_initcall(wakeup_sources_sysfs_init);
--
2.53.0
next reply other threads:[~2026-03-29 16:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-29 16:14 Heiner Kallweit [this message]
2026-04-01 14:19 ` [PATCH] PM / wakeup: Allocate class wakeup_class statically Rafael J. Wysocki
2026-04-01 15:45 ` Heiner Kallweit
2026-04-01 17:32 ` Rafael J. Wysocki
2026-04-02 13:05 ` Heiner Kallweit
2026-04-03 10:45 ` Rafael J. Wysocki
2026-04-03 11:02 ` Heiner Kallweit
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=0fe1b679-ab28-4505-b0db-14e7ac3ba749@gmail.com \
--to=hkallweit1@gmail.com \
--cc=dakr@kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=lenb@kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=pavel@kernel.org \
--cc=rafael@kernel.org \
/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