* [PATCH] remove tty class device logic [2/5]
@ 2003-12-23 21:27 Greg KH
0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2003-12-23 21:27 UTC (permalink / raw)
To: linux-hotplug
Remove the tty class device logic, as the simple class device interface
can now be used.
diff -Nru a/drivers/char/tty_io.c b/drivers/char/tty_io.c
--- a/drivers/char/tty_io.c Tue Dec 23 12:53:19 2003
+++ b/drivers/char/tty_io.c Tue Dec 23 12:53:19 2003
@@ -2069,80 +2069,10 @@
tty->driver->write(tty, 0, &ch, 1);
}
-struct tty_dev {
- struct list_head node;
- dev_t dev;
- struct class_device class_dev;
-};
-#define to_tty_dev(d) container_of(d, struct tty_dev, class_dev)
-
-static void release_tty_dev(struct class_device *class_dev)
-{
- struct tty_dev *tty_dev = to_tty_dev(class_dev);
- kfree(tty_dev);
-}
-
static struct class tty_class = {
- .name = "tty",
- .release = &release_tty_dev,
+ .name = "tty",
};
-static LIST_HEAD(tty_dev_list);
-static spinlock_t tty_dev_list_lock = SPIN_LOCK_UNLOCKED;
-
-static ssize_t show_dev(struct class_device *class_dev, char *buf)
-{
- struct tty_dev *tty_dev = to_tty_dev(class_dev);
- return print_dev_t(buf, tty_dev->dev);
-}
-static CLASS_DEVICE_ATTR(dev, S_IRUGO, show_dev, NULL);
-
-static void tty_add_class_device(char *name, dev_t dev, struct device *device)
-{
- struct tty_dev *tty_dev = NULL;
- int retval;
-
- tty_dev = kmalloc(sizeof(*tty_dev), GFP_KERNEL);
- if (!tty_dev)
- return;
- memset(tty_dev, 0x00, sizeof(*tty_dev));
-
- tty_dev->class_dev.dev = device;
- tty_dev->class_dev.class = &tty_class;
- snprintf(tty_dev->class_dev.class_id, BUS_ID_SIZE, "%s", name);
- retval = class_device_register(&tty_dev->class_dev);
- if (retval)
- goto error;
- class_device_create_file (&tty_dev->class_dev, &class_device_attr_dev);
- tty_dev->dev = dev;
- spin_lock(&tty_dev_list_lock);
- list_add(&tty_dev->node, &tty_dev_list);
- spin_unlock(&tty_dev_list_lock);
- return;
-error:
- kfree(tty_dev);
-}
-
-static void tty_remove_class_device(dev_t dev)
-{
- struct tty_dev *tty_dev = NULL;
- struct list_head *tmp;
- int found = 0;
-
- spin_lock(&tty_dev_list_lock);
- list_for_each (tmp, &tty_dev_list) {
- tty_dev = list_entry(tmp, struct tty_dev, node);
- if (tty_dev->dev = dev) {
- list_del(&tty_dev->node);
- found = 1;
- break;
- }
- }
- spin_unlock(&tty_dev_list_lock);
- if (found)
- class_device_unregister(&tty_dev->class_dev);
-}
-
/**
* tty_register_device - register a tty device
* @driver: the tty driver that describes the tty device
@@ -2174,7 +2104,7 @@
if (driver->type != TTY_DRIVER_TYPE_PTY) {
char name[64];
tty_line_name(driver, index, name);
- tty_add_class_device(name, dev, device);
+ simple_add_class_device(&tty_class, dev, device, name);
}
}
@@ -2189,7 +2119,7 @@
void tty_unregister_device(struct tty_driver *driver, unsigned index)
{
devfs_remove("%s%d", driver->devfs_name, index + driver->name_base);
- tty_remove_class_device(MKDEV(driver->major, driver->minor_start) + index);
+ simple_remove_class_device(MKDEV(driver->major, driver->minor_start) + index);
}
EXPORT_SYMBOL(tty_register_device);
@@ -2431,7 +2361,7 @@
register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0)
panic("Couldn't register /dev/tty driver\n");
devfs_mk_cdev(MKDEV(TTYAUX_MAJOR, 0), S_IFCHR|S_IRUGO|S_IWUGO, "tty");
- tty_add_class_device ("tty", MKDEV(TTYAUX_MAJOR, 0), NULL);
+ simple_add_class_device(&tty_class, MKDEV(TTYAUX_MAJOR, 0), NULL, "tty");
strcpy(console_cdev.kobj.name, "dev.console");
cdev_init(&console_cdev, &console_fops);
@@ -2439,7 +2369,7 @@
register_chrdev_region(MKDEV(TTYAUX_MAJOR, 1), 1, "/dev/console") < 0)
panic("Couldn't register /dev/console driver\n");
devfs_mk_cdev(MKDEV(TTYAUX_MAJOR, 1), S_IFCHR|S_IRUSR|S_IWUSR, "console");
- tty_add_class_device ("console", MKDEV(TTYAUX_MAJOR, 1), NULL);
+ simple_add_class_device(&tty_class, MKDEV(TTYAUX_MAJOR, 1), NULL, "console");
tty_kobj.kset = tty_cdev.kobj.kset;
kobject_register(&tty_kobj);
@@ -2451,7 +2381,7 @@
register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)
panic("Couldn't register /dev/ptmx driver\n");
devfs_mk_cdev(MKDEV(TTYAUX_MAJOR, 2), S_IFCHR|S_IRUGO|S_IWUGO, "ptmx");
- tty_add_class_device ("ptmx", MKDEV(TTYAUX_MAJOR, 2), NULL);
+ simple_add_class_device(&tty_class, MKDEV(TTYAUX_MAJOR, 2), NULL, "ptmx");
#endif
#ifdef CONFIG_VT
@@ -2461,7 +2391,7 @@
register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0)
panic("Couldn't register /dev/tty0 driver\n");
devfs_mk_cdev(MKDEV(TTY_MAJOR, 0), S_IFCHR|S_IRUSR|S_IWUSR, "vc/0");
- tty_add_class_device ("tty0", MKDEV(TTY_MAJOR, 0), NULL);
+ simple_add_class_device(&tty_class, MKDEV(TTY_MAJOR, 0), NULL, "tty0");
vty_init();
#endif
-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
Free Linux Tutorials. Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id\x1278&alloc_id371&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 2+ messages in thread* [PATCH] sysfs class patches - take 2 [0/5]
@ 2003-12-23 21:24 Greg KH
2003-12-23 21:26 ` [PATCH] add "simple" class device support [1/5] Greg KH
0 siblings, 1 reply; 2+ messages in thread
From: Greg KH @ 2003-12-23 21:24 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel, linux-hotplug-devel
Here are the sysfs class patches reworked against a clean 2.6.0 tree.
I've created a class_simple.c file that contains a "simple" class device
interface. I've then converted the tty core to use this interface (the
combo of these two patches makes for no extra code added).
Then there are 3 patches, adding class support for misc, mem, and vc
class devices. As the interface to add simple class support for devices
is now so low, I feel that we do need to have mem class support as to
not special case any char device.
With these patches, it's now much easier for others to implement class
support for remaining char drivers/subsystems that do not have it yet.
Andrew, can you please remove the following 3 patches from your
2.6.0-mm1 tree:
sysfs-mem-device-support.patch
sysfs-misc-device-support.patch
sysfs-vc-device-support.patch
and add these 5 patches instead? The sysfs-oops-fix.patch needs to
stay.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH] add "simple" class device support [1/5]
2003-12-23 21:24 [PATCH] sysfs class patches - take 2 [0/5] Greg KH
@ 2003-12-23 21:26 ` Greg KH
2003-12-23 21:27 ` [PATCH] remove tty class device logic [2/5] Greg KH
0 siblings, 1 reply; 2+ messages in thread
From: Greg KH @ 2003-12-23 21:26 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel, linux-hotplug-devel
Adds a "simple" class device interface to the kernel for char devices
that don't want to roll their own struct class_device handling logic.
diff -Nru a/drivers/base/Makefile b/drivers/base/Makefile
--- a/drivers/base/Makefile Tue Dec 23 12:53:40 2003
+++ b/drivers/base/Makefile Tue Dec 23 12:53:40 2003
@@ -1,7 +1,7 @@
# Makefile for the Linux device tree
obj-y := core.o sys.o interface.o bus.o \
- driver.o class.o platform.o \
+ driver.o class.o class_simple.o platform.o \
cpu.o firmware.o init.o map.o
obj-y += power/
obj-$(CONFIG_FW_LOADER) += firmware_class.o
diff -Nru a/drivers/base/class_simple.c b/drivers/base/class_simple.c
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/drivers/base/class_simple.c Tue Dec 23 12:53:48 2003
@@ -0,0 +1,123 @@
+/*
+ * class_simple.c - basic char device support
+ *
+ * Copyright (c) 2003 Greg Kroah-Hartman <greg@kroah.com>
+ * Copyright (c) 2003 IBM Corp.
+ *
+ * This file is released under the GPLv2
+ *
+ */
+
+#undef DEBUG
+
+#include <linux/device.h>
+#include <linux/kdev_t.h>
+#include <linux/err.h>
+
+struct simple_dev {
+ struct list_head node;
+ dev_t dev;
+ struct class_device class_dev;
+};
+#define to_simple_dev(d) container_of(d, struct simple_dev, class_dev)
+
+static LIST_HEAD(simple_dev_list);
+static spinlock_t simple_dev_list_lock = SPIN_LOCK_UNLOCKED;
+
+static void release_simple_dev(struct class_device *class_dev)
+{
+ struct simple_dev *s_dev = to_simple_dev(class_dev);
+ kfree(s_dev);
+}
+
+static ssize_t show_dev(struct class_device *class_dev, char *buf)
+{
+ struct simple_dev *s_dev = to_simple_dev(class_dev);
+ return print_dev_t(buf, s_dev->dev);
+}
+static CLASS_DEVICE_ATTR(dev, S_IRUGO, show_dev, NULL);
+
+/**
+ * simple_add_class_device - adds a class device to sysfs for a character driver
+ * @class: pointer to the struct class that this device should be registered to.
+ * @dev: the dev_t for the device to be added.
+ * @device: a pointer to a struct device that is assiociated with this class device.
+ * @fmt: string for the class device's name
+ *
+ * This function can be used by simple char device classes that do not
+ * implement their own class device registration. A struct class_device will
+ * be created in sysfs, registered to the specified class. A "dev" file will
+ * be created, showing the dev_t for the device. The pointer to the struct
+ * class_device will be returned from the call. Any further sysfs files that
+ * might be required can be created using this pointer.
+ * Note: the struct class passed to this function must have previously been
+ * registered with a call to register_class().
+ */
+struct class_device *simple_add_class_device(struct class *class, dev_t dev, struct device *device, const char *fmt, ...)
+{
+ va_list args;
+ struct simple_dev *s_dev;
+ int retval;
+
+ s_dev = kmalloc(sizeof(*s_dev), GFP_KERNEL);
+ if (!s_dev) {
+ retval = -ENOMEM;
+ goto error;
+ }
+ memset(s_dev, 0x00, sizeof(*s_dev));
+
+ class->release = &release_simple_dev;
+ s_dev->dev = dev;
+ s_dev->class_dev.dev = device;
+ s_dev->class_dev.class = class;
+
+ va_start(args,fmt);
+ vsnprintf(s_dev->class_dev.class_id, BUS_ID_SIZE, fmt, args);
+ va_end(args);
+ retval = class_device_register(&s_dev->class_dev);
+ if (retval)
+ goto error;
+ class_device_create_file(&s_dev->class_dev, &class_device_attr_dev);
+ spin_lock(&simple_dev_list_lock);
+ list_add(&s_dev->node, &simple_dev_list);
+ spin_unlock(&simple_dev_list_lock);
+
+ return &s_dev->class_dev;
+
+error:
+ kfree(s_dev);
+ return ERR_PTR(retval);
+}
+EXPORT_SYMBOL(simple_add_class_device);
+
+/**
+ * simple_remove_class_device - removes a class device that was created with simple_add_class_device()
+ * @dev: the dev_t of the device that was previously registered.
+ *
+ * This call unregisters and cleans up a class device that was created with a
+ * call to simple_add_class_device()
+ */
+void simple_remove_class_device(dev_t dev)
+{
+ struct simple_dev *s_dev = NULL;
+ struct list_head *tmp;
+ int found = 0;
+
+ spin_lock(&simple_dev_list_lock);
+ list_for_each(tmp, &simple_dev_list) {
+ s_dev = list_entry(tmp, struct simple_dev, node);
+ if (s_dev->dev == dev) {
+ found = 1;
+ break;
+ }
+ }
+ if (found) {
+ list_del(&s_dev->node);
+ spin_unlock(&simple_dev_list_lock);
+ class_device_unregister(&s_dev->class_dev);
+ } else {
+ spin_unlock(&simple_dev_list_lock);
+ }
+}
+EXPORT_SYMBOL(simple_remove_class_device);
+
diff -Nru a/include/linux/device.h b/include/linux/device.h
--- a/include/linux/device.h Tue Dec 23 12:53:36 2003
+++ b/include/linux/device.h Tue Dec 23 12:53:36 2003
@@ -246,6 +246,11 @@
extern int class_interface_register(struct class_interface *);
extern void class_interface_unregister(struct class_interface *);
+/* interface for simple class devices */
+extern struct class_device *simple_add_class_device(struct class *class, dev_t dev, struct device *device, const char *fmt, ...)
+ __attribute__((format(printf,4,5)));
+extern void simple_remove_class_device(dev_t dev);
+
struct device {
struct list_head node; /* node in sibling list */
^ permalink raw reply [flat|nested] 2+ messages in thread* [PATCH] remove tty class device logic [2/5]
2003-12-23 21:26 ` [PATCH] add "simple" class device support [1/5] Greg KH
@ 2003-12-23 21:27 ` Greg KH
0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2003-12-23 21:27 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel, linux-hotplug-devel
Remove the tty class device logic, as the simple class device interface
can now be used.
diff -Nru a/drivers/char/tty_io.c b/drivers/char/tty_io.c
--- a/drivers/char/tty_io.c Tue Dec 23 12:53:19 2003
+++ b/drivers/char/tty_io.c Tue Dec 23 12:53:19 2003
@@ -2069,80 +2069,10 @@
tty->driver->write(tty, 0, &ch, 1);
}
-struct tty_dev {
- struct list_head node;
- dev_t dev;
- struct class_device class_dev;
-};
-#define to_tty_dev(d) container_of(d, struct tty_dev, class_dev)
-
-static void release_tty_dev(struct class_device *class_dev)
-{
- struct tty_dev *tty_dev = to_tty_dev(class_dev);
- kfree(tty_dev);
-}
-
static struct class tty_class = {
- .name = "tty",
- .release = &release_tty_dev,
+ .name = "tty",
};
-static LIST_HEAD(tty_dev_list);
-static spinlock_t tty_dev_list_lock = SPIN_LOCK_UNLOCKED;
-
-static ssize_t show_dev(struct class_device *class_dev, char *buf)
-{
- struct tty_dev *tty_dev = to_tty_dev(class_dev);
- return print_dev_t(buf, tty_dev->dev);
-}
-static CLASS_DEVICE_ATTR(dev, S_IRUGO, show_dev, NULL);
-
-static void tty_add_class_device(char *name, dev_t dev, struct device *device)
-{
- struct tty_dev *tty_dev = NULL;
- int retval;
-
- tty_dev = kmalloc(sizeof(*tty_dev), GFP_KERNEL);
- if (!tty_dev)
- return;
- memset(tty_dev, 0x00, sizeof(*tty_dev));
-
- tty_dev->class_dev.dev = device;
- tty_dev->class_dev.class = &tty_class;
- snprintf(tty_dev->class_dev.class_id, BUS_ID_SIZE, "%s", name);
- retval = class_device_register(&tty_dev->class_dev);
- if (retval)
- goto error;
- class_device_create_file (&tty_dev->class_dev, &class_device_attr_dev);
- tty_dev->dev = dev;
- spin_lock(&tty_dev_list_lock);
- list_add(&tty_dev->node, &tty_dev_list);
- spin_unlock(&tty_dev_list_lock);
- return;
-error:
- kfree(tty_dev);
-}
-
-static void tty_remove_class_device(dev_t dev)
-{
- struct tty_dev *tty_dev = NULL;
- struct list_head *tmp;
- int found = 0;
-
- spin_lock(&tty_dev_list_lock);
- list_for_each (tmp, &tty_dev_list) {
- tty_dev = list_entry(tmp, struct tty_dev, node);
- if (tty_dev->dev == dev) {
- list_del(&tty_dev->node);
- found = 1;
- break;
- }
- }
- spin_unlock(&tty_dev_list_lock);
- if (found)
- class_device_unregister(&tty_dev->class_dev);
-}
-
/**
* tty_register_device - register a tty device
* @driver: the tty driver that describes the tty device
@@ -2174,7 +2104,7 @@
if (driver->type != TTY_DRIVER_TYPE_PTY) {
char name[64];
tty_line_name(driver, index, name);
- tty_add_class_device(name, dev, device);
+ simple_add_class_device(&tty_class, dev, device, name);
}
}
@@ -2189,7 +2119,7 @@
void tty_unregister_device(struct tty_driver *driver, unsigned index)
{
devfs_remove("%s%d", driver->devfs_name, index + driver->name_base);
- tty_remove_class_device(MKDEV(driver->major, driver->minor_start) + index);
+ simple_remove_class_device(MKDEV(driver->major, driver->minor_start) + index);
}
EXPORT_SYMBOL(tty_register_device);
@@ -2431,7 +2361,7 @@
register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0)
panic("Couldn't register /dev/tty driver\n");
devfs_mk_cdev(MKDEV(TTYAUX_MAJOR, 0), S_IFCHR|S_IRUGO|S_IWUGO, "tty");
- tty_add_class_device ("tty", MKDEV(TTYAUX_MAJOR, 0), NULL);
+ simple_add_class_device(&tty_class, MKDEV(TTYAUX_MAJOR, 0), NULL, "tty");
strcpy(console_cdev.kobj.name, "dev.console");
cdev_init(&console_cdev, &console_fops);
@@ -2439,7 +2369,7 @@
register_chrdev_region(MKDEV(TTYAUX_MAJOR, 1), 1, "/dev/console") < 0)
panic("Couldn't register /dev/console driver\n");
devfs_mk_cdev(MKDEV(TTYAUX_MAJOR, 1), S_IFCHR|S_IRUSR|S_IWUSR, "console");
- tty_add_class_device ("console", MKDEV(TTYAUX_MAJOR, 1), NULL);
+ simple_add_class_device(&tty_class, MKDEV(TTYAUX_MAJOR, 1), NULL, "console");
tty_kobj.kset = tty_cdev.kobj.kset;
kobject_register(&tty_kobj);
@@ -2451,7 +2381,7 @@
register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)
panic("Couldn't register /dev/ptmx driver\n");
devfs_mk_cdev(MKDEV(TTYAUX_MAJOR, 2), S_IFCHR|S_IRUGO|S_IWUGO, "ptmx");
- tty_add_class_device ("ptmx", MKDEV(TTYAUX_MAJOR, 2), NULL);
+ simple_add_class_device(&tty_class, MKDEV(TTYAUX_MAJOR, 2), NULL, "ptmx");
#endif
#ifdef CONFIG_VT
@@ -2461,7 +2391,7 @@
register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0)
panic("Couldn't register /dev/tty0 driver\n");
devfs_mk_cdev(MKDEV(TTY_MAJOR, 0), S_IFCHR|S_IRUSR|S_IWUSR, "vc/0");
- tty_add_class_device ("tty0", MKDEV(TTY_MAJOR, 0), NULL);
+ simple_add_class_device(&tty_class, MKDEV(TTY_MAJOR, 0), NULL, "tty0");
vty_init();
#endif
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-12-23 21:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-12-23 21:27 [PATCH] remove tty class device logic [2/5] Greg KH
-- strict thread matches above, loose matches on Subject: below --
2003-12-23 21:24 [PATCH] sysfs class patches - take 2 [0/5] Greg KH
2003-12-23 21:26 ` [PATCH] add "simple" class device support [1/5] Greg KH
2003-12-23 21:27 ` [PATCH] remove tty class device logic [2/5] Greg KH
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.