diff options
| author | Takashi Iwai <tiwai@suse.de> | 2015-02-05 05:07:42 -0500 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2015-03-26 11:10:10 -0400 |
| commit | 1083a7be4504df8149015894c982ebaf69766ddc (patch) | |
| tree | 5381249a652590bb700d1f08cb504bec0a952c7e /drivers/tty/vt | |
| parent | 1569039db0062c47c97ca0bf0c86210d26b8f412 (diff) | |
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>
Diffstat (limited to 'drivers/tty/vt')
| -rw-r--r-- | drivers/tty/vt/vt.c | 70 |
1 files changed, 31 insertions, 39 deletions
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index edf17b4e385f..4a24eb2b0ede 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c | |||
| @@ -3041,17 +3041,24 @@ static ssize_t show_tty_active(struct device *dev, | |||
| 3041 | } | 3041 | } |
| 3042 | static DEVICE_ATTR(active, S_IRUGO, show_tty_active, NULL); | 3042 | static DEVICE_ATTR(active, S_IRUGO, show_tty_active, NULL); |
| 3043 | 3043 | ||
| 3044 | static struct attribute *vt_dev_attrs[] = { | ||
| 3045 | &dev_attr_active.attr, | ||
| 3046 | NULL | ||
| 3047 | }; | ||
| 3048 | |||
| 3049 | ATTRIBUTE_GROUPS(vt_dev); | ||
| 3050 | |||
| 3044 | int __init vty_init(const struct file_operations *console_fops) | 3051 | int __init vty_init(const struct file_operations *console_fops) |
| 3045 | { | 3052 | { |
| 3046 | cdev_init(&vc0_cdev, console_fops); | 3053 | cdev_init(&vc0_cdev, console_fops); |
| 3047 | if (cdev_add(&vc0_cdev, MKDEV(TTY_MAJOR, 0), 1) || | 3054 | if (cdev_add(&vc0_cdev, MKDEV(TTY_MAJOR, 0), 1) || |
| 3048 | register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0) | 3055 | register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0) |
| 3049 | panic("Couldn't register /dev/tty0 driver\n"); | 3056 | panic("Couldn't register /dev/tty0 driver\n"); |
| 3050 | tty0dev = device_create(tty_class, NULL, MKDEV(TTY_MAJOR, 0), NULL, "tty0"); | 3057 | tty0dev = device_create_with_groups(tty_class, NULL, |
| 3058 | MKDEV(TTY_MAJOR, 0), NULL, | ||
| 3059 | vt_dev_groups, "tty0"); | ||
| 3051 | if (IS_ERR(tty0dev)) | 3060 | if (IS_ERR(tty0dev)) |
| 3052 | tty0dev = NULL; | 3061 | tty0dev = NULL; |
| 3053 | else | ||
| 3054 | WARN_ON(device_create_file(tty0dev, &dev_attr_active) < 0); | ||
| 3055 | 3062 | ||
| 3056 | vcs_init(); | 3063 | vcs_init(); |
| 3057 | 3064 | ||
| @@ -3423,42 +3430,26 @@ static ssize_t show_name(struct device *dev, struct device_attribute *attr, | |||
| 3423 | 3430 | ||
| 3424 | } | 3431 | } |
| 3425 | 3432 | ||
| 3426 | static struct device_attribute device_attrs[] = { | 3433 | static DEVICE_ATTR(bind, S_IRUGO|S_IWUSR, show_bind, store_bind); |
| 3427 | __ATTR(bind, S_IRUGO|S_IWUSR, show_bind, store_bind), | 3434 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); |
| 3428 | __ATTR(name, S_IRUGO, show_name, NULL), | 3435 | |
| 3436 | static struct attribute *con_dev_attrs[] = { | ||
| 3437 | &dev_attr_bind.attr, | ||
| 3438 | &dev_attr_name.attr, | ||
| 3439 | NULL | ||
| 3429 | }; | 3440 | }; |
| 3430 | 3441 | ||
| 3442 | ATTRIBUTE_GROUPS(con_dev); | ||
| 3443 | |||
| 3431 | static int vtconsole_init_device(struct con_driver *con) | 3444 | static int vtconsole_init_device(struct con_driver *con) |
| 3432 | { | 3445 | { |
| 3433 | int i; | ||
| 3434 | int error = 0; | ||
| 3435 | |||
| 3436 | con->flag |= CON_DRIVER_FLAG_ATTR; | 3446 | con->flag |= CON_DRIVER_FLAG_ATTR; |
| 3437 | dev_set_drvdata(con->dev, con); | 3447 | return 0; |
| 3438 | for (i = 0; i < ARRAY_SIZE(device_attrs); i++) { | ||
| 3439 | error = device_create_file(con->dev, &device_attrs[i]); | ||
| 3440 | if (error) | ||
| 3441 | break; | ||
| 3442 | } | ||
| 3443 | |||
| 3444 | if (error) { | ||
| 3445 | while (--i >= 0) | ||
| 3446 | device_remove_file(con->dev, &device_attrs[i]); | ||
| 3447 | con->flag &= ~CON_DRIVER_FLAG_ATTR; | ||
| 3448 | } | ||
| 3449 | |||
| 3450 | return error; | ||
| 3451 | } | 3448 | } |
| 3452 | 3449 | ||
| 3453 | static void vtconsole_deinit_device(struct con_driver *con) | 3450 | static void vtconsole_deinit_device(struct con_driver *con) |
| 3454 | { | 3451 | { |
| 3455 | int i; | 3452 | con->flag &= ~CON_DRIVER_FLAG_ATTR; |
| 3456 | |||
| 3457 | if (con->flag & CON_DRIVER_FLAG_ATTR) { | ||
| 3458 | for (i = 0; i < ARRAY_SIZE(device_attrs); i++) | ||
| 3459 | device_remove_file(con->dev, &device_attrs[i]); | ||
| 3460 | con->flag &= ~CON_DRIVER_FLAG_ATTR; | ||
| 3461 | } | ||
| 3462 | } | 3453 | } |
| 3463 | 3454 | ||
| 3464 | /** | 3455 | /** |
| @@ -3621,11 +3612,11 @@ static int do_register_con_driver(const struct consw *csw, int first, int last) | |||
| 3621 | if (retval) | 3612 | if (retval) |
| 3622 | goto err; | 3613 | goto err; |
| 3623 | 3614 | ||
| 3624 | con_driver->dev = device_create(vtconsole_class, NULL, | 3615 | con_driver->dev = |
| 3625 | MKDEV(0, con_driver->node), | 3616 | device_create_with_groups(vtconsole_class, NULL, |
| 3626 | NULL, "vtcon%i", | 3617 | MKDEV(0, con_driver->node), |
| 3627 | con_driver->node); | 3618 | con_driver, con_dev_groups, |
| 3628 | 3619 | "vtcon%i", con_driver->node); | |
| 3629 | if (IS_ERR(con_driver->dev)) { | 3620 | if (IS_ERR(con_driver->dev)) { |
| 3630 | printk(KERN_WARNING "Unable to create device for %s; " | 3621 | printk(KERN_WARNING "Unable to create device for %s; " |
| 3631 | "errno = %ld\n", con_driver->desc, | 3622 | "errno = %ld\n", con_driver->desc, |
| @@ -3739,10 +3730,11 @@ static int __init vtconsole_class_init(void) | |||
| 3739 | struct con_driver *con = ®istered_con_driver[i]; | 3730 | struct con_driver *con = ®istered_con_driver[i]; |
| 3740 | 3731 | ||
| 3741 | if (con->con && !con->dev) { | 3732 | if (con->con && !con->dev) { |
| 3742 | con->dev = device_create(vtconsole_class, NULL, | 3733 | con->dev = |
| 3743 | MKDEV(0, con->node), | 3734 | device_create_with_groups(vtconsole_class, NULL, |
| 3744 | NULL, "vtcon%i", | 3735 | MKDEV(0, con->node), |
| 3745 | con->node); | 3736 | con, con_dev_groups, |
| 3737 | "vtcon%i", con->node); | ||
| 3746 | 3738 | ||
| 3747 | if (IS_ERR(con->dev)) { | 3739 | if (IS_ERR(con->dev)) { |
| 3748 | printk(KERN_WARNING "Unable to create " | 3740 | printk(KERN_WARNING "Unable to create " |
