Skip to content

Commit 5726fb2

Browse files
David BrownellLinus Torvalds
authored andcommitted
rtc: remove /sys/class/rtc-dev/*
This simplifies the /dev support by removing a superfluous class_device (the /sys/class/rtc-dev stuff) and the class_interface that hooks it into the rtc core. Accordingly, if it's configured then /dev support is now part of the RTC core, and is never a separate module. It's another step towards being able to remove "struct class_device". [bunk@stusta.de: drivers/rtc/rtc-dev.c should #include "rtc-core.h"] Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Acked-by: Greg Kroah-Hartman <gregkh@suse.de> Acked-By: Alessandro Zummo <a.zummo@towertech.it> Signed-off-by: Adrian Bunk <bunk@stusta.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 1c710c8 commit 5726fb2

6 files changed

Lines changed: 46 additions & 89 deletions

File tree

‎drivers/rtc/Kconfig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ config RTC_INTF_PROC
7171
will be called rtc-proc.
7272

7373
config RTC_INTF_DEV
74-
tristate "dev"
74+
boolean "dev"
7575
depends on RTC_CLASS
7676
default RTC_CLASS
7777
help

‎drivers/rtc/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ obj-$(CONFIG_RTC_HCTOSYS) += hctosys.o
1111
obj-$(CONFIG_RTC_CLASS) += rtc-core.o
1212
rtc-core-y := class.o interface.o
1313

14+
rtc-core-$(CONFIG_RTC_INTF_DEV) += rtc-dev.o
15+
1416
obj-$(CONFIG_RTC_INTF_SYSFS) += rtc-sysfs.o
1517
obj-$(CONFIG_RTC_INTF_PROC) += rtc-proc.o
16-
obj-$(CONFIG_RTC_INTF_DEV) += rtc-dev.o
1718

1819
obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o
1920
obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o

‎drivers/rtc/class.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#include <linux/kdev_t.h>
1717
#include <linux/idr.h>
1818

19+
#include "rtc-core.h"
20+
21+
1922
static DEFINE_IDR(rtc_idr);
2023
static DEFINE_MUTEX(idr_lock);
2124
struct class *rtc_class;
@@ -85,6 +88,8 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
8588
if (err)
8689
goto exit_kfree;
8790

91+
rtc_dev_add_device(rtc);
92+
8893
dev_info(dev, "rtc core: registered %s as %s\n",
8994
rtc->name, rtc->class_dev.class_id);
9095

@@ -118,6 +123,7 @@ void rtc_device_unregister(struct rtc_device *rtc)
118123
/* remove innards of this RTC, then disable it, before
119124
* letting any rtc_class_open() users access it again
120125
*/
126+
rtc_dev_del_device(rtc);
121127
class_device_unregister(&rtc->class_dev);
122128
rtc->ops = NULL;
123129
mutex_unlock(&rtc->ops_lock);
@@ -140,11 +146,13 @@ static int __init rtc_init(void)
140146
printk(KERN_ERR "%s: couldn't create class\n", __FILE__);
141147
return PTR_ERR(rtc_class);
142148
}
149+
rtc_dev_init();
143150
return 0;
144151
}
145152

146153
static void __exit rtc_exit(void)
147154
{
155+
rtc_dev_exit();
148156
class_destroy(rtc_class);
149157
}
150158

‎drivers/rtc/rtc-core.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifdef CONFIG_RTC_INTF_DEV
2+
3+
extern void __init rtc_dev_init(void);
4+
extern void __exit rtc_dev_exit(void);
5+
extern void rtc_dev_add_device(struct rtc_device *rtc);
6+
extern void rtc_dev_del_device(struct rtc_device *rtc);
7+
8+
#else
9+
10+
#define rtc_dev_init() do{}while(0)
11+
#define rtc_dev_exit() do{}while(0)
12+
#define rtc_dev_add_device(r) do{}while(0)
13+
#define rtc_dev_del_device(r) do{}while(0)
14+
15+
#endif

‎drivers/rtc/rtc-dev.c‎

Lines changed: 20 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
#include <linux/module.h>
1515
#include <linux/rtc.h>
16+
#include "rtc-core.h"
1617

17-
static struct class *rtc_dev_class;
1818
static dev_t rtc_devt;
1919

2020
#define RTC_DEV_MAX 16 /* 16 RTCs should be enough for everyone... */
@@ -397,17 +397,18 @@ static const struct file_operations rtc_dev_fops = {
397397

398398
/* insertion/removal hooks */
399399

400-
static int rtc_dev_add_device(struct class_device *class_dev,
401-
struct class_interface *class_intf)
400+
void rtc_dev_add_device(struct rtc_device *rtc)
402401
{
403-
int err = 0;
404-
struct rtc_device *rtc = to_rtc_device(class_dev);
402+
if (!rtc_devt)
403+
return;
405404

406405
if (rtc->id >= RTC_DEV_MAX) {
407-
dev_err(class_dev->dev, "too many RTCs\n");
408-
return -EINVAL;
406+
pr_debug("%s: too many RTC devices\n", rtc->name);
407+
return;
409408
}
410409

410+
rtc->class_dev.devt = MKDEV(MAJOR(rtc_devt), rtc->id);
411+
411412
mutex_init(&rtc->char_lock);
412413
spin_lock_init(&rtc->irq_lock);
413414
init_waitqueue_head(&rtc->irq_queue);
@@ -419,99 +420,32 @@ static int rtc_dev_add_device(struct class_device *class_dev,
419420
cdev_init(&rtc->char_dev, &rtc_dev_fops);
420421
rtc->char_dev.owner = rtc->owner;
421422

422-
if (cdev_add(&rtc->char_dev, MKDEV(MAJOR(rtc_devt), rtc->id), 1)) {
423-
dev_err(class_dev->dev,
424-
"failed to add char device %d:%d\n",
423+
if (cdev_add(&rtc->char_dev, rtc->class_dev.devt, 1))
424+
printk(KERN_WARNING "%s: failed to add char device %d:%d\n",
425+
rtc->name, MAJOR(rtc_devt), rtc->id);
426+
else
427+
pr_debug("%s: dev (%d:%d)\n", rtc->name,
425428
MAJOR(rtc_devt), rtc->id);
426-
return -ENODEV;
427-
}
428-
429-
rtc->rtc_dev = class_device_create(rtc_dev_class, NULL,
430-
MKDEV(MAJOR(rtc_devt), rtc->id),
431-
class_dev->dev, "rtc%d", rtc->id);
432-
if (IS_ERR(rtc->rtc_dev)) {
433-
dev_err(class_dev->dev, "cannot create rtc_dev device\n");
434-
err = PTR_ERR(rtc->rtc_dev);
435-
goto err_cdev_del;
436-
}
437-
438-
dev_dbg(class_dev->dev, "rtc intf: dev (%d:%d)\n",
439-
MAJOR(rtc->rtc_dev->devt),
440-
MINOR(rtc->rtc_dev->devt));
441-
442-
return 0;
443-
444-
err_cdev_del:
445-
446-
cdev_del(&rtc->char_dev);
447-
return err;
448429
}
449430

450-
static void rtc_dev_remove_device(struct class_device *class_dev,
451-
struct class_interface *class_intf)
431+
void rtc_dev_del_device(struct rtc_device *rtc)
452432
{
453-
struct rtc_device *rtc = to_rtc_device(class_dev);
454-
455-
if (rtc->rtc_dev) {
456-
dev_dbg(class_dev->dev, "removing char %d:%d\n",
457-
MAJOR(rtc->rtc_dev->devt),
458-
MINOR(rtc->rtc_dev->devt));
459-
460-
class_device_unregister(rtc->rtc_dev);
433+
if (rtc->class_dev.devt)
461434
cdev_del(&rtc->char_dev);
462-
}
463435
}
464436

465-
/* interface registration */
466-
467-
static struct class_interface rtc_dev_interface = {
468-
.add = &rtc_dev_add_device,
469-
.remove = &rtc_dev_remove_device,
470-
};
471-
472-
static int __init rtc_dev_init(void)
437+
void __init rtc_dev_init(void)
473438
{
474439
int err;
475440

476-
rtc_dev_class = class_create(THIS_MODULE, "rtc-dev");
477-
if (IS_ERR(rtc_dev_class))
478-
return PTR_ERR(rtc_dev_class);
479-
480441
err = alloc_chrdev_region(&rtc_devt, 0, RTC_DEV_MAX, "rtc");
481-
if (err < 0) {
442+
if (err < 0)
482443
printk(KERN_ERR "%s: failed to allocate char dev region\n",
483444
__FILE__);
484-
goto err_destroy_class;
485-
}
486-
487-
err = rtc_interface_register(&rtc_dev_interface);
488-
if (err < 0) {
489-
printk(KERN_ERR "%s: failed to register the interface\n",
490-
__FILE__);
491-
goto err_unregister_chrdev;
492-
}
493-
494-
return 0;
495-
496-
err_unregister_chrdev:
497-
unregister_chrdev_region(rtc_devt, RTC_DEV_MAX);
498-
499-
err_destroy_class:
500-
class_destroy(rtc_dev_class);
501-
502-
return err;
503445
}
504446

505-
static void __exit rtc_dev_exit(void)
447+
void __exit rtc_dev_exit(void)
506448
{
507-
class_interface_unregister(&rtc_dev_interface);
508-
class_destroy(rtc_dev_class);
509-
unregister_chrdev_region(rtc_devt, RTC_DEV_MAX);
449+
if (rtc_devt)
450+
unregister_chrdev_region(rtc_devt, RTC_DEV_MAX);
510451
}
511-
512-
subsys_initcall(rtc_dev_init);
513-
module_exit(rtc_dev_exit);
514-
515-
MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
516-
MODULE_DESCRIPTION("RTC class dev interface");
517-
MODULE_LICENSE("GPL");

‎include/linux/rtc.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ struct rtc_device
145145
const struct rtc_class_ops *ops;
146146
struct mutex ops_lock;
147147

148-
struct class_device *rtc_dev;
149148
struct cdev char_dev;
150149
struct mutex char_lock;
151150

0 commit comments

Comments
 (0)