mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
synced 2025-09-03 01:28:04 +00:00
tty: Use static attribute groups for sysfs entries
Instead of manual calls of device_create_file() and device_remove_file(), pass the static attribute groups using device_create_with_groups(). Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
1569039db0
commit
1083a7be45
@ -3593,6 +3593,13 @@ static ssize_t show_cons_active(struct device *dev,
|
|||||||
}
|
}
|
||||||
static DEVICE_ATTR(active, S_IRUGO, show_cons_active, NULL);
|
static DEVICE_ATTR(active, S_IRUGO, show_cons_active, NULL);
|
||||||
|
|
||||||
|
static struct attribute *cons_dev_attrs[] = {
|
||||||
|
&dev_attr_active.attr,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
ATTRIBUTE_GROUPS(cons_dev);
|
||||||
|
|
||||||
static struct device *consdev;
|
static struct device *consdev;
|
||||||
|
|
||||||
void console_sysfs_notify(void)
|
void console_sysfs_notify(void)
|
||||||
@ -3617,12 +3624,11 @@ int __init tty_init(void)
|
|||||||
if (cdev_add(&console_cdev, MKDEV(TTYAUX_MAJOR, 1), 1) ||
|
if (cdev_add(&console_cdev, MKDEV(TTYAUX_MAJOR, 1), 1) ||
|
||||||
register_chrdev_region(MKDEV(TTYAUX_MAJOR, 1), 1, "/dev/console") < 0)
|
register_chrdev_region(MKDEV(TTYAUX_MAJOR, 1), 1, "/dev/console") < 0)
|
||||||
panic("Couldn't register /dev/console driver\n");
|
panic("Couldn't register /dev/console driver\n");
|
||||||
consdev = device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 1), NULL,
|
consdev = device_create_with_groups(tty_class, NULL,
|
||||||
"console");
|
MKDEV(TTYAUX_MAJOR, 1), NULL,
|
||||||
|
cons_dev_groups, "console");
|
||||||
if (IS_ERR(consdev))
|
if (IS_ERR(consdev))
|
||||||
consdev = NULL;
|
consdev = NULL;
|
||||||
else
|
|
||||||
WARN_ON(device_create_file(consdev, &dev_attr_active) < 0);
|
|
||||||
|
|
||||||
#ifdef CONFIG_VT
|
#ifdef CONFIG_VT
|
||||||
vty_init(&console_fops);
|
vty_init(&console_fops);
|
||||||
|
@ -3041,17 +3041,24 @@ static ssize_t show_tty_active(struct device *dev,
|
|||||||
}
|
}
|
||||||
static DEVICE_ATTR(active, S_IRUGO, show_tty_active, NULL);
|
static DEVICE_ATTR(active, S_IRUGO, show_tty_active, NULL);
|
||||||
|
|
||||||
|
static struct attribute *vt_dev_attrs[] = {
|
||||||
|
&dev_attr_active.attr,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
ATTRIBUTE_GROUPS(vt_dev);
|
||||||
|
|
||||||
int __init vty_init(const struct file_operations *console_fops)
|
int __init vty_init(const struct file_operations *console_fops)
|
||||||
{
|
{
|
||||||
cdev_init(&vc0_cdev, console_fops);
|
cdev_init(&vc0_cdev, console_fops);
|
||||||
if (cdev_add(&vc0_cdev, MKDEV(TTY_MAJOR, 0), 1) ||
|
if (cdev_add(&vc0_cdev, MKDEV(TTY_MAJOR, 0), 1) ||
|
||||||
register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0)
|
register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0)
|
||||||
panic("Couldn't register /dev/tty0 driver\n");
|
panic("Couldn't register /dev/tty0 driver\n");
|
||||||
tty0dev = device_create(tty_class, NULL, MKDEV(TTY_MAJOR, 0), NULL, "tty0");
|
tty0dev = device_create_with_groups(tty_class, NULL,
|
||||||
|
MKDEV(TTY_MAJOR, 0), NULL,
|
||||||
|
vt_dev_groups, "tty0");
|
||||||
if (IS_ERR(tty0dev))
|
if (IS_ERR(tty0dev))
|
||||||
tty0dev = NULL;
|
tty0dev = NULL;
|
||||||
else
|
|
||||||
WARN_ON(device_create_file(tty0dev, &dev_attr_active) < 0);
|
|
||||||
|
|
||||||
vcs_init();
|
vcs_init();
|
||||||
|
|
||||||
@ -3423,42 +3430,26 @@ static ssize_t show_name(struct device *dev, struct device_attribute *attr,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct device_attribute device_attrs[] = {
|
static DEVICE_ATTR(bind, S_IRUGO|S_IWUSR, show_bind, store_bind);
|
||||||
__ATTR(bind, S_IRUGO|S_IWUSR, show_bind, store_bind),
|
static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
|
||||||
__ATTR(name, S_IRUGO, show_name, NULL),
|
|
||||||
|
static struct attribute *con_dev_attrs[] = {
|
||||||
|
&dev_attr_bind.attr,
|
||||||
|
&dev_attr_name.attr,
|
||||||
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ATTRIBUTE_GROUPS(con_dev);
|
||||||
|
|
||||||
static int vtconsole_init_device(struct con_driver *con)
|
static int vtconsole_init_device(struct con_driver *con)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
int error = 0;
|
|
||||||
|
|
||||||
con->flag |= CON_DRIVER_FLAG_ATTR;
|
con->flag |= CON_DRIVER_FLAG_ATTR;
|
||||||
dev_set_drvdata(con->dev, con);
|
return 0;
|
||||||
for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
|
|
||||||
error = device_create_file(con->dev, &device_attrs[i]);
|
|
||||||
if (error)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error) {
|
|
||||||
while (--i >= 0)
|
|
||||||
device_remove_file(con->dev, &device_attrs[i]);
|
|
||||||
con->flag &= ~CON_DRIVER_FLAG_ATTR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vtconsole_deinit_device(struct con_driver *con)
|
static void vtconsole_deinit_device(struct con_driver *con)
|
||||||
{
|
{
|
||||||
int i;
|
con->flag &= ~CON_DRIVER_FLAG_ATTR;
|
||||||
|
|
||||||
if (con->flag & CON_DRIVER_FLAG_ATTR) {
|
|
||||||
for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
|
|
||||||
device_remove_file(con->dev, &device_attrs[i]);
|
|
||||||
con->flag &= ~CON_DRIVER_FLAG_ATTR;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -3621,11 +3612,11 @@ static int do_register_con_driver(const struct consw *csw, int first, int last)
|
|||||||
if (retval)
|
if (retval)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
con_driver->dev = device_create(vtconsole_class, NULL,
|
con_driver->dev =
|
||||||
MKDEV(0, con_driver->node),
|
device_create_with_groups(vtconsole_class, NULL,
|
||||||
NULL, "vtcon%i",
|
MKDEV(0, con_driver->node),
|
||||||
con_driver->node);
|
con_driver, con_dev_groups,
|
||||||
|
"vtcon%i", con_driver->node);
|
||||||
if (IS_ERR(con_driver->dev)) {
|
if (IS_ERR(con_driver->dev)) {
|
||||||
printk(KERN_WARNING "Unable to create device for %s; "
|
printk(KERN_WARNING "Unable to create device for %s; "
|
||||||
"errno = %ld\n", con_driver->desc,
|
"errno = %ld\n", con_driver->desc,
|
||||||
@ -3739,10 +3730,11 @@ static int __init vtconsole_class_init(void)
|
|||||||
struct con_driver *con = ®istered_con_driver[i];
|
struct con_driver *con = ®istered_con_driver[i];
|
||||||
|
|
||||||
if (con->con && !con->dev) {
|
if (con->con && !con->dev) {
|
||||||
con->dev = device_create(vtconsole_class, NULL,
|
con->dev =
|
||||||
MKDEV(0, con->node),
|
device_create_with_groups(vtconsole_class, NULL,
|
||||||
NULL, "vtcon%i",
|
MKDEV(0, con->node),
|
||||||
con->node);
|
con, con_dev_groups,
|
||||||
|
"vtcon%i", con->node);
|
||||||
|
|
||||||
if (IS_ERR(con->dev)) {
|
if (IS_ERR(con->dev)) {
|
||||||
printk(KERN_WARNING "Unable to create "
|
printk(KERN_WARNING "Unable to create "
|
||||||
|
Loading…
Reference in New Issue
Block a user