Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rtc: class: make rtc_class constant

Since commit 43a7206b0963 ("driver core: class: make class_register() take
a const *"), the driver core allows for struct class to be in read-only
memory, so move the rtc_class structure to be declared at build time
placing it into read-only memory, instead of having to be dynamically
allocated at boot time.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ricardo B. Marliere <ricardo@marliere.net>
Link: https://lore.kernel.org/r/20240305-class_cleanup-abelloni-v1-1-944c026137c8@marliere.net
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

authored by

Ricardo B. Marliere and committed by
Alexandre Belloni
6b6ca096 32a6be08

+17 -12
+13 -8
drivers/rtc/class.c
··· 21 21 #include "rtc-core.h" 22 22 23 23 static DEFINE_IDA(rtc_ida); 24 - struct class *rtc_class; 25 24 26 25 static void rtc_device_release(struct device *dev) 27 26 { ··· 198 199 #define RTC_CLASS_DEV_PM_OPS NULL 199 200 #endif 200 201 202 + const struct class rtc_class = { 203 + .name = "rtc", 204 + .pm = RTC_CLASS_DEV_PM_OPS, 205 + }; 206 + 201 207 /* Ensure the caller will set the id before releasing the device */ 202 208 static struct rtc_device *rtc_allocate_device(void) 203 209 { ··· 224 220 225 221 rtc->irq_freq = 1; 226 222 rtc->max_user_freq = 64; 227 - rtc->dev.class = rtc_class; 223 + rtc->dev.class = &rtc_class; 228 224 rtc->dev.groups = rtc_get_dev_attribute_groups(); 229 225 rtc->dev.release = rtc_device_release; 230 226 ··· 479 475 480 476 static int __init rtc_init(void) 481 477 { 482 - rtc_class = class_create("rtc"); 483 - if (IS_ERR(rtc_class)) { 484 - pr_err("couldn't create class\n"); 485 - return PTR_ERR(rtc_class); 486 - } 487 - rtc_class->pm = RTC_CLASS_DEV_PM_OPS; 478 + int err; 479 + 480 + err = class_register(&rtc_class); 481 + if (err) 482 + return err; 483 + 488 484 rtc_dev_init(); 485 + 489 486 return 0; 490 487 } 491 488 subsys_initcall(rtc_init);
+1 -1
drivers/rtc/interface.c
··· 696 696 struct device *dev; 697 697 struct rtc_device *rtc = NULL; 698 698 699 - dev = class_find_device_by_name(rtc_class, name); 699 + dev = class_find_device_by_name(&rtc_class, name); 700 700 if (dev) 701 701 rtc = to_rtc_device(dev); 702 702
+1 -1
include/linux/rtc.h
··· 42 42 #include <linux/timerqueue.h> 43 43 #include <linux/workqueue.h> 44 44 45 - extern struct class *rtc_class; 45 + extern const struct class rtc_class; 46 46 47 47 /* 48 48 * For these RTC methods the device parameter is the physical device
+1 -1
kernel/power/suspend_test.c
··· 201 201 } 202 202 203 203 /* RTCs have initialized by now too ... can we use one? */ 204 - dev = class_find_device(rtc_class, NULL, NULL, has_wakealarm); 204 + dev = class_find_device(&rtc_class, NULL, NULL, has_wakealarm); 205 205 if (dev) { 206 206 rtc = rtc_class_open(dev_name(dev)); 207 207 put_device(dev);
+1 -1
kernel/time/alarmtimer.c
··· 134 134 135 135 static int alarmtimer_rtc_interface_setup(void) 136 136 { 137 - alarmtimer_rtc_interface.class = rtc_class; 137 + alarmtimer_rtc_interface.class = &rtc_class; 138 138 return class_interface_register(&alarmtimer_rtc_interface); 139 139 } 140 140 static void alarmtimer_rtc_interface_remove(void)