aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2009-09-18 17:01:12 -0400
committerLive-CD User <linux@linux.site>2009-09-19 15:50:38 -0400
commite454cea20bdcff10ee698d11b8882662a0153a47 (patch)
treef44581fe57787aef0a4f4dc00993a90ea8e688f6
parent78f28b7c555359c67c2a0d23f7436e915329421e (diff)
Driver-Core: extend devnode callbacks to provide permissions
This allows subsytems to provide devtmpfs with non-default permissions for the device node. Instead of the default mode of 0600, null, zero, random, urandom, full, tty, ptmx now have a mode of 0666, which allows non-privileged processes to access standard device nodes in case no other userspace process applies the expected permissions. This also fixes a wrong assignment in pktcdvd and a checkpatch.pl complain. Signed-off-by: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--arch/x86/kernel/cpuid.c4
-rw-r--r--arch/x86/kernel/microcode_core.c2
-rw-r--r--arch/x86/kernel/msr.c4
-rw-r--r--block/bsg.c4
-rw-r--r--block/genhd.c8
-rw-r--r--drivers/base/core.c19
-rw-r--r--drivers/base/devtmpfs.c24
-rw-r--r--drivers/block/aoe/aoechr.c4
-rw-r--r--drivers/block/pktcdvd.c6
-rw-r--r--drivers/char/hw_random/core.c2
-rw-r--r--drivers/char/mem.c29
-rw-r--r--drivers/char/misc.c10
-rw-r--r--drivers/char/raw.c4
-rw-r--r--drivers/char/tty_io.c11
-rw-r--r--drivers/gpu/drm/drm_sysfs.c4
-rw-r--r--drivers/hid/usbhid/hiddev.c4
-rw-r--r--drivers/input/input.c4
-rw-r--r--drivers/md/dm-ioctl.c2
-rw-r--r--drivers/media/dvb/dvb-core/dvbdev.c4
-rw-r--r--drivers/net/tun.c2
-rw-r--r--drivers/usb/class/usblp.c4
-rw-r--r--drivers/usb/core/file.c8
-rw-r--r--drivers/usb/core/usb.c4
-rw-r--r--drivers/usb/misc/iowarrior.c4
-rw-r--r--drivers/usb/misc/legousbtower.c4
-rw-r--r--include/linux/device.h7
-rw-r--r--include/linux/genhd.h2
-rw-r--r--include/linux/miscdevice.h3
-rw-r--r--include/linux/usb.h4
-rw-r--r--sound/sound_core.c4
30 files changed, 116 insertions, 79 deletions
diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
index b07af8861244..6a52d4b36a30 100644
--- a/arch/x86/kernel/cpuid.c
+++ b/arch/x86/kernel/cpuid.c
@@ -182,7 +182,7 @@ static struct notifier_block __refdata cpuid_class_cpu_notifier =
182 .notifier_call = cpuid_class_cpu_callback, 182 .notifier_call = cpuid_class_cpu_callback,
183}; 183};
184 184
185static char *cpuid_nodename(struct device *dev) 185static char *cpuid_devnode(struct device *dev, mode_t *mode)
186{ 186{
187 return kasprintf(GFP_KERNEL, "cpu/%u/cpuid", MINOR(dev->devt)); 187 return kasprintf(GFP_KERNEL, "cpu/%u/cpuid", MINOR(dev->devt));
188} 188}
@@ -203,7 +203,7 @@ static int __init cpuid_init(void)
203 err = PTR_ERR(cpuid_class); 203 err = PTR_ERR(cpuid_class);
204 goto out_chrdev; 204 goto out_chrdev;
205 } 205 }
206 cpuid_class->nodename = cpuid_nodename; 206 cpuid_class->devnode = cpuid_devnode;
207 for_each_online_cpu(i) { 207 for_each_online_cpu(i) {
208 err = cpuid_device_create(i); 208 err = cpuid_device_create(i);
209 if (err != 0) 209 if (err != 0)
diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
index 9371448290ac..0db7969b0dde 100644
--- a/arch/x86/kernel/microcode_core.c
+++ b/arch/x86/kernel/microcode_core.c
@@ -236,7 +236,7 @@ static const struct file_operations microcode_fops = {
236static struct miscdevice microcode_dev = { 236static struct miscdevice microcode_dev = {
237 .minor = MICROCODE_MINOR, 237 .minor = MICROCODE_MINOR,
238 .name = "microcode", 238 .name = "microcode",
239 .devnode = "cpu/microcode", 239 .nodename = "cpu/microcode",
240 .fops = &microcode_fops, 240 .fops = &microcode_fops,
241}; 241};
242 242
diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
index 7dd950094178..6a3cefc7dda1 100644
--- a/arch/x86/kernel/msr.c
+++ b/arch/x86/kernel/msr.c
@@ -241,7 +241,7 @@ static struct notifier_block __refdata msr_class_cpu_notifier = {
241 .notifier_call = msr_class_cpu_callback, 241 .notifier_call = msr_class_cpu_callback,
242}; 242};
243 243
244static char *msr_nodename(struct device *dev) 244static char *msr_devnode(struct device *dev, mode_t *mode)
245{ 245{
246 return kasprintf(GFP_KERNEL, "cpu/%u/msr", MINOR(dev->devt)); 246 return kasprintf(GFP_KERNEL, "cpu/%u/msr", MINOR(dev->devt));
247} 247}
@@ -262,7 +262,7 @@ static int __init msr_init(void)
262 err = PTR_ERR(msr_class); 262 err = PTR_ERR(msr_class);
263 goto out_chrdev; 263 goto out_chrdev;
264 } 264 }
265 msr_class->nodename = msr_nodename; 265 msr_class->devnode = msr_devnode;
266 for_each_online_cpu(i) { 266 for_each_online_cpu(i) {
267 err = msr_device_create(i); 267 err = msr_device_create(i);
268 if (err != 0) 268 if (err != 0)
diff --git a/block/bsg.c b/block/bsg.c
index 5f184bb3ff9e..0676301f16d0 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -1062,7 +1062,7 @@ EXPORT_SYMBOL_GPL(bsg_register_queue);
1062 1062
1063static struct cdev bsg_cdev; 1063static struct cdev bsg_cdev;
1064 1064
1065static char *bsg_nodename(struct device *dev) 1065static char *bsg_devnode(struct device *dev, mode_t *mode)
1066{ 1066{
1067 return kasprintf(GFP_KERNEL, "bsg/%s", dev_name(dev)); 1067 return kasprintf(GFP_KERNEL, "bsg/%s", dev_name(dev));
1068} 1068}
@@ -1087,7 +1087,7 @@ static int __init bsg_init(void)
1087 ret = PTR_ERR(bsg_class); 1087 ret = PTR_ERR(bsg_class);
1088 goto destroy_kmemcache; 1088 goto destroy_kmemcache;
1089 } 1089 }
1090 bsg_class->nodename = bsg_nodename; 1090 bsg_class->devnode = bsg_devnode;
1091 1091
1092 ret = alloc_chrdev_region(&devid, 0, BSG_MAX_DEVS, "bsg"); 1092 ret = alloc_chrdev_region(&devid, 0, BSG_MAX_DEVS, "bsg");
1093 if (ret) 1093 if (ret)
diff --git a/block/genhd.c b/block/genhd.c
index 2ad91ddad8e2..517e4332cb37 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -998,12 +998,12 @@ struct class block_class = {
998 .name = "block", 998 .name = "block",
999}; 999};
1000 1000
1001static char *block_nodename(struct device *dev) 1001static char *block_devnode(struct device *dev, mode_t *mode)
1002{ 1002{
1003 struct gendisk *disk = dev_to_disk(dev); 1003 struct gendisk *disk = dev_to_disk(dev);
1004 1004
1005 if (disk->nodename) 1005 if (disk->devnode)
1006 return disk->nodename(disk); 1006 return disk->devnode(disk, mode);
1007 return NULL; 1007 return NULL;
1008} 1008}
1009 1009
@@ -1011,7 +1011,7 @@ static struct device_type disk_type = {
1011 .name = "disk", 1011 .name = "disk",
1012 .groups = disk_attr_groups, 1012 .groups = disk_attr_groups,
1013 .release = disk_release, 1013 .release = disk_release,
1014 .nodename = block_nodename, 1014 .devnode = block_devnode,
1015}; 1015};
1016 1016
1017#ifdef CONFIG_PROC_FS 1017#ifdef CONFIG_PROC_FS
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 390e664ec1c7..6bee6af8d8e1 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -166,13 +166,16 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
166 if (MAJOR(dev->devt)) { 166 if (MAJOR(dev->devt)) {
167 const char *tmp; 167 const char *tmp;
168 const char *name; 168 const char *name;
169 mode_t mode = 0;
169 170
170 add_uevent_var(env, "MAJOR=%u", MAJOR(dev->devt)); 171 add_uevent_var(env, "MAJOR=%u", MAJOR(dev->devt));
171 add_uevent_var(env, "MINOR=%u", MINOR(dev->devt)); 172 add_uevent_var(env, "MINOR=%u", MINOR(dev->devt));
172 name = device_get_nodename(dev, &tmp); 173 name = device_get_devnode(dev, &mode, &tmp);
173 if (name) { 174 if (name) {
174 add_uevent_var(env, "DEVNAME=%s", name); 175 add_uevent_var(env, "DEVNAME=%s", name);
175 kfree(tmp); 176 kfree(tmp);
177 if (mode)
178 add_uevent_var(env, "DEVMODE=%#o", mode & 0777);
176 } 179 }
177 } 180 }
178 181
@@ -1148,8 +1151,9 @@ static struct device *next_device(struct klist_iter *i)
1148} 1151}
1149 1152
1150/** 1153/**
1151 * device_get_nodename - path of device node file 1154 * device_get_devnode - path of device node file
1152 * @dev: device 1155 * @dev: device
1156 * @mode: returned file access mode
1153 * @tmp: possibly allocated string 1157 * @tmp: possibly allocated string
1154 * 1158 *
1155 * Return the relative path of a possible device node. 1159 * Return the relative path of a possible device node.
@@ -1157,21 +1161,22 @@ static struct device *next_device(struct klist_iter *i)
1157 * a name. This memory is returned in tmp and needs to be 1161 * a name. This memory is returned in tmp and needs to be
1158 * freed by the caller. 1162 * freed by the caller.
1159 */ 1163 */
1160const char *device_get_nodename(struct device *dev, const char **tmp) 1164const char *device_get_devnode(struct device *dev,
1165 mode_t *mode, const char **tmp)
1161{ 1166{
1162 char *s; 1167 char *s;
1163 1168
1164 *tmp = NULL; 1169 *tmp = NULL;
1165 1170
1166 /* the device type may provide a specific name */ 1171 /* the device type may provide a specific name */
1167 if (dev->type && dev->type->nodename) 1172 if (dev->type && dev->type->devnode)
1168 *tmp = dev->type->nodename(dev); 1173 *tmp = dev->type->devnode(dev, mode);
1169 if (*tmp) 1174 if (*tmp)
1170 return *tmp; 1175 return *tmp;
1171 1176
1172 /* the class may provide a specific name */ 1177 /* the class may provide a specific name */
1173 if (dev->class && dev->class->nodename) 1178 if (dev->class && dev->class->devnode)
1174 *tmp = dev->class->nodename(dev); 1179 *tmp = dev->class->devnode(dev, mode);
1175 if (*tmp) 1180 if (*tmp)
1176 return *tmp; 1181 return *tmp;
1177 1182
diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
index fd488ad4263a..a1cb5afe6801 100644
--- a/drivers/base/devtmpfs.c
+++ b/drivers/base/devtmpfs.c
@@ -6,9 +6,10 @@
6 * During bootup, before any driver core device is registered, 6 * During bootup, before any driver core device is registered,
7 * devtmpfs, a tmpfs-based filesystem is created. Every driver-core 7 * devtmpfs, a tmpfs-based filesystem is created. Every driver-core
8 * device which requests a device node, will add a node in this 8 * device which requests a device node, will add a node in this
9 * filesystem. The node is named after the the name of the device, 9 * filesystem.
10 * or the susbsytem can provide a custom name. All devices are 10 * By default, all devices are named after the the name of the
11 * owned by root and have a mode of 0600. 11 * device, owned by root and have a default mode of 0600. Subsystems
12 * can overwrite the default setting if needed.
12 */ 13 */
13 14
14#include <linux/kernel.h> 15#include <linux/kernel.h>
@@ -20,6 +21,7 @@
20#include <linux/fs.h> 21#include <linux/fs.h>
21#include <linux/shmem_fs.h> 22#include <linux/shmem_fs.h>
22#include <linux/cred.h> 23#include <linux/cred.h>
24#include <linux/sched.h>
23#include <linux/init_task.h> 25#include <linux/init_task.h>
24 26
25static struct vfsmount *dev_mnt; 27static struct vfsmount *dev_mnt;
@@ -134,7 +136,7 @@ int devtmpfs_create_node(struct device *dev)
134 const char *tmp = NULL; 136 const char *tmp = NULL;
135 const char *nodename; 137 const char *nodename;
136 const struct cred *curr_cred; 138 const struct cred *curr_cred;
137 mode_t mode; 139 mode_t mode = 0;
138 struct nameidata nd; 140 struct nameidata nd;
139 struct dentry *dentry; 141 struct dentry *dentry;
140 int err; 142 int err;
@@ -142,14 +144,16 @@ int devtmpfs_create_node(struct device *dev)
142 if (!dev_mnt) 144 if (!dev_mnt)
143 return 0; 145 return 0;
144 146
145 nodename = device_get_nodename(dev, &tmp); 147 nodename = device_get_devnode(dev, &mode, &tmp);
146 if (!nodename) 148 if (!nodename)
147 return -ENOMEM; 149 return -ENOMEM;
148 150
151 if (mode == 0)
152 mode = 0600;
149 if (is_blockdev(dev)) 153 if (is_blockdev(dev))
150 mode = S_IFBLK|0600; 154 mode |= S_IFBLK;
151 else 155 else
152 mode = S_IFCHR|0600; 156 mode |= S_IFCHR;
153 157
154 curr_cred = override_creds(&init_cred); 158 curr_cred = override_creds(&init_cred);
155 err = vfs_path_lookup(dev_mnt->mnt_root, dev_mnt, 159 err = vfs_path_lookup(dev_mnt->mnt_root, dev_mnt,
@@ -165,8 +169,12 @@ int devtmpfs_create_node(struct device *dev)
165 169
166 dentry = lookup_create(&nd, 0); 170 dentry = lookup_create(&nd, 0);
167 if (!IS_ERR(dentry)) { 171 if (!IS_ERR(dentry)) {
172 int umask;
173
174 umask = sys_umask(0000);
168 err = vfs_mknod(nd.path.dentry->d_inode, 175 err = vfs_mknod(nd.path.dentry->d_inode,
169 dentry, mode, dev->devt); 176 dentry, mode, dev->devt);
177 sys_umask(umask);
170 /* mark as kernel created inode */ 178 /* mark as kernel created inode */
171 if (!err) 179 if (!err)
172 dentry->d_inode->i_private = &dev_mnt; 180 dentry->d_inode->i_private = &dev_mnt;
@@ -271,7 +279,7 @@ int devtmpfs_delete_node(struct device *dev)
271 if (!dev_mnt) 279 if (!dev_mnt)
272 return 0; 280 return 0;
273 281
274 nodename = device_get_nodename(dev, &tmp); 282 nodename = device_get_devnode(dev, NULL, &tmp);
275 if (!nodename) 283 if (!nodename)
276 return -ENOMEM; 284 return -ENOMEM;
277 285
diff --git a/drivers/block/aoe/aoechr.c b/drivers/block/aoe/aoechr.c
index 19888354188f..62141ec09a22 100644
--- a/drivers/block/aoe/aoechr.c
+++ b/drivers/block/aoe/aoechr.c
@@ -266,7 +266,7 @@ static const struct file_operations aoe_fops = {
266 .owner = THIS_MODULE, 266 .owner = THIS_MODULE,
267}; 267};
268 268
269static char *aoe_nodename(struct device *dev) 269static char *aoe_devnode(struct device *dev, mode_t *mode)
270{ 270{
271 return kasprintf(GFP_KERNEL, "etherd/%s", dev_name(dev)); 271 return kasprintf(GFP_KERNEL, "etherd/%s", dev_name(dev));
272} 272}
@@ -288,7 +288,7 @@ aoechr_init(void)
288 unregister_chrdev(AOE_MAJOR, "aoechr"); 288 unregister_chrdev(AOE_MAJOR, "aoechr");
289 return PTR_ERR(aoe_class); 289 return PTR_ERR(aoe_class);
290 } 290 }
291 aoe_class->nodename = aoe_nodename; 291 aoe_class->devnode = aoe_devnode;
292 292
293 for (i = 0; i < ARRAY_SIZE(chardevs); ++i) 293 for (i = 0; i < ARRAY_SIZE(chardevs); ++i)
294 device_create(aoe_class, NULL, 294 device_create(aoe_class, NULL,
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 95f11cdef203..fd5bb8ad59a9 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -2857,7 +2857,7 @@ static struct block_device_operations pktcdvd_ops = {
2857 .media_changed = pkt_media_changed, 2857 .media_changed = pkt_media_changed,
2858}; 2858};
2859 2859
2860static char *pktcdvd_nodename(struct gendisk *gd) 2860static char *pktcdvd_devnode(struct gendisk *gd, mode_t *mode)
2861{ 2861{
2862 return kasprintf(GFP_KERNEL, "pktcdvd/%s", gd->disk_name); 2862 return kasprintf(GFP_KERNEL, "pktcdvd/%s", gd->disk_name);
2863} 2863}
@@ -2914,7 +2914,7 @@ static int pkt_setup_dev(dev_t dev, dev_t* pkt_dev)
2914 disk->fops = &pktcdvd_ops; 2914 disk->fops = &pktcdvd_ops;
2915 disk->flags = GENHD_FL_REMOVABLE; 2915 disk->flags = GENHD_FL_REMOVABLE;
2916 strcpy(disk->disk_name, pd->name); 2916 strcpy(disk->disk_name, pd->name);
2917 disk->nodename = pktcdvd_nodename; 2917 disk->devnode = pktcdvd_devnode;
2918 disk->private_data = pd; 2918 disk->private_data = pd;
2919 disk->queue = blk_alloc_queue(GFP_KERNEL); 2919 disk->queue = blk_alloc_queue(GFP_KERNEL);
2920 if (!disk->queue) 2920 if (!disk->queue)
@@ -3070,7 +3070,7 @@ static const struct file_operations pkt_ctl_fops = {
3070static struct miscdevice pkt_misc = { 3070static struct miscdevice pkt_misc = {
3071 .minor = MISC_DYNAMIC_MINOR, 3071 .minor = MISC_DYNAMIC_MINOR,
3072 .name = DRIVER_NAME, 3072 .name = DRIVER_NAME,
3073 .name = "pktcdvd/control", 3073 .nodename = "pktcdvd/control",
3074 .fops = &pkt_ctl_fops 3074 .fops = &pkt_ctl_fops
3075}; 3075};
3076 3076
diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index fc93e2fc7c71..1573aebd54b5 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -153,7 +153,7 @@ static const struct file_operations rng_chrdev_ops = {
153static struct miscdevice rng_miscdev = { 153static struct miscdevice rng_miscdev = {
154 .minor = RNG_MISCDEV_MINOR, 154 .minor = RNG_MISCDEV_MINOR,
155 .name = RNG_MODULE_NAME, 155 .name = RNG_MODULE_NAME,
156 .devnode = "hwrng", 156 .nodename = "hwrng",
157 .fops = &rng_chrdev_ops, 157 .fops = &rng_chrdev_ops,
158}; 158};
159 159
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 0491cdf63f2a..0aede1d6a9ea 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -866,24 +866,25 @@ static const struct file_operations kmsg_fops = {
866 866
867static const struct memdev { 867static const struct memdev {
868 const char *name; 868 const char *name;
869 mode_t mode;
869 const struct file_operations *fops; 870 const struct file_operations *fops;
870 struct backing_dev_info *dev_info; 871 struct backing_dev_info *dev_info;
871} devlist[] = { 872} devlist[] = {
872 [ 1] = { "mem", &mem_fops, &directly_mappable_cdev_bdi }, 873 [1] = { "mem", 0, &mem_fops, &directly_mappable_cdev_bdi },
873#ifdef CONFIG_DEVKMEM 874#ifdef CONFIG_DEVKMEM
874 [ 2] = { "kmem", &kmem_fops, &directly_mappable_cdev_bdi }, 875 [2] = { "kmem", 0, &kmem_fops, &directly_mappable_cdev_bdi },
875#endif 876#endif
876 [ 3] = {"null", &null_fops, NULL }, 877 [3] = { "null", 0666, &null_fops, NULL },
877#ifdef CONFIG_DEVPORT 878#ifdef CONFIG_DEVPORT
878 [ 4] = { "port", &port_fops, NULL }, 879 [4] = { "port", 0, &port_fops, NULL },
879#endif 880#endif
880 [ 5] = { "zero", &zero_fops, &zero_bdi }, 881 [5] = { "zero", 0666, &zero_fops, &zero_bdi },
881 [ 7] = { "full", &full_fops, NULL }, 882 [7] = { "full", 0666, &full_fops, NULL },
882 [ 8] = { "random", &random_fops, NULL }, 883 [8] = { "random", 0666, &random_fops, NULL },
883 [ 9] = { "urandom", &urandom_fops, NULL }, 884 [9] = { "urandom", 0666, &urandom_fops, NULL },
884 [11] = { "kmsg", &kmsg_fops, NULL }, 885 [11] = { "kmsg", 0, &kmsg_fops, NULL },
885#ifdef CONFIG_CRASH_DUMP 886#ifdef CONFIG_CRASH_DUMP
886 [12] = { "oldmem", &oldmem_fops, NULL }, 887 [12] = { "oldmem", 0, &oldmem_fops, NULL },
887#endif 888#endif
888}; 889};
889 890
@@ -920,6 +921,13 @@ static const struct file_operations memory_fops = {
920 .open = memory_open, 921 .open = memory_open,
921}; 922};
922 923
924static char *mem_devnode(struct device *dev, mode_t *mode)
925{
926 if (mode && devlist[MINOR(dev->devt)].mode)
927 *mode = devlist[MINOR(dev->devt)].mode;
928 return NULL;
929}
930
923static struct class *mem_class; 931static struct class *mem_class;
924 932
925static int __init chr_dev_init(void) 933static int __init chr_dev_init(void)
@@ -935,6 +943,7 @@ static int __init chr_dev_init(void)
935 printk("unable to get major %d for memory devs\n", MEM_MAJOR); 943 printk("unable to get major %d for memory devs\n", MEM_MAJOR);
936 944
937 mem_class = class_create(THIS_MODULE, "mem"); 945 mem_class = class_create(THIS_MODULE, "mem");
946 mem_class->devnode = mem_devnode;
938 for (minor = 1; minor < ARRAY_SIZE(devlist); minor++) { 947 for (minor = 1; minor < ARRAY_SIZE(devlist); minor++) {
939 if (!devlist[minor].name) 948 if (!devlist[minor].name)
940 continue; 949 continue;
diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index 62c99fa59e2b..1ee27cc23426 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -263,12 +263,14 @@ int misc_deregister(struct miscdevice *misc)
263EXPORT_SYMBOL(misc_register); 263EXPORT_SYMBOL(misc_register);
264EXPORT_SYMBOL(misc_deregister); 264EXPORT_SYMBOL(misc_deregister);
265 265
266static char *misc_nodename(struct device *dev) 266static char *misc_devnode(struct device *dev, mode_t *mode)
267{ 267{
268 struct miscdevice *c = dev_get_drvdata(dev); 268 struct miscdevice *c = dev_get_drvdata(dev);
269 269
270 if (c->devnode) 270 if (mode && c->mode)
271 return kstrdup(c->devnode, GFP_KERNEL); 271 *mode = c->mode;
272 if (c->nodename)
273 return kstrdup(c->nodename, GFP_KERNEL);
272 return NULL; 274 return NULL;
273} 275}
274 276
@@ -287,7 +289,7 @@ static int __init misc_init(void)
287 err = -EIO; 289 err = -EIO;
288 if (register_chrdev(MISC_MAJOR,"misc",&misc_fops)) 290 if (register_chrdev(MISC_MAJOR,"misc",&misc_fops))
289 goto fail_printk; 291 goto fail_printk;
290 misc_class->nodename = misc_nodename; 292 misc_class->devnode = misc_devnode;
291 return 0; 293 return 0;
292 294
293fail_printk: 295fail_printk:
diff --git a/drivers/char/raw.c b/drivers/char/raw.c
index 40268db02e22..64acd05f71c8 100644
--- a/drivers/char/raw.c
+++ b/drivers/char/raw.c
@@ -261,7 +261,7 @@ static const struct file_operations raw_ctl_fops = {
261 261
262static struct cdev raw_cdev; 262static struct cdev raw_cdev;
263 263
264static char *raw_nodename(struct device *dev) 264static char *raw_devnode(struct device *dev, mode_t *mode)
265{ 265{
266 return kasprintf(GFP_KERNEL, "raw/%s", dev_name(dev)); 266 return kasprintf(GFP_KERNEL, "raw/%s", dev_name(dev));
267} 267}
@@ -289,7 +289,7 @@ static int __init raw_init(void)
289 ret = PTR_ERR(raw_class); 289 ret = PTR_ERR(raw_class);
290 goto error_region; 290 goto error_region;
291 } 291 }
292 raw_class->nodename = raw_nodename; 292 raw_class->devnode = raw_devnode;
293 device_create(raw_class, NULL, MKDEV(RAW_MAJOR, 0), NULL, "rawctl"); 293 device_create(raw_class, NULL, MKDEV(RAW_MAJOR, 0), NULL, "rawctl");
294 294
295 return 0; 295 return 0;
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index a3afa0c387cd..c70d9dabefae 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -3056,11 +3056,22 @@ void __init console_init(void)
3056 } 3056 }
3057} 3057}
3058 3058
3059static char *tty_devnode(struct device *dev, mode_t *mode)
3060{
3061 if (!mode)
3062 return NULL;
3063 if (dev->devt == MKDEV(TTYAUX_MAJOR, 0) ||
3064 dev->devt == MKDEV(TTYAUX_MAJOR, 2))
3065 *mode = 0666;
3066 return NULL;
3067}
3068
3059static int __init tty_class_init(void) 3069static int __init tty_class_init(void)
3060{ 3070{
3061 tty_class = class_create(THIS_MODULE, "tty"); 3071 tty_class = class_create(THIS_MODULE, "tty");
3062 if (IS_ERR(tty_class)) 3072 if (IS_ERR(tty_class))
3063 return PTR_ERR(tty_class); 3073 return PTR_ERR(tty_class);
3074 tty_class->devnode = tty_devnode;
3064 return 0; 3075 return 0;
3065} 3076}
3066 3077
diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
index f7a615b80c70..5301f226cb1c 100644
--- a/drivers/gpu/drm/drm_sysfs.c
+++ b/drivers/gpu/drm/drm_sysfs.c
@@ -76,7 +76,7 @@ static ssize_t version_show(struct class *dev, char *buf)
76 CORE_MINOR, CORE_PATCHLEVEL, CORE_DATE); 76 CORE_MINOR, CORE_PATCHLEVEL, CORE_DATE);
77} 77}
78 78
79static char *drm_nodename(struct device *dev) 79static char *drm_devnode(struct device *dev, mode_t *mode)
80{ 80{
81 return kasprintf(GFP_KERNEL, "dri/%s", dev_name(dev)); 81 return kasprintf(GFP_KERNEL, "dri/%s", dev_name(dev));
82} 82}
@@ -112,7 +112,7 @@ struct class *drm_sysfs_create(struct module *owner, char *name)
112 if (err) 112 if (err)
113 goto err_out_class; 113 goto err_out_class;
114 114
115 class->nodename = drm_nodename; 115 class->devnode = drm_devnode;
116 116
117 return class; 117 return class;
118 118
diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
index 4d1dc0cf1401..8b6ee247bfe4 100644
--- a/drivers/hid/usbhid/hiddev.c
+++ b/drivers/hid/usbhid/hiddev.c
@@ -852,14 +852,14 @@ static const struct file_operations hiddev_fops = {
852#endif 852#endif
853}; 853};
854 854
855static char *hiddev_nodename(struct device *dev) 855static char *hiddev_devnode(struct device *dev, mode_t *mode)
856{ 856{
857 return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev)); 857 return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev));
858} 858}
859 859
860static struct usb_class_driver hiddev_class = { 860static struct usb_class_driver hiddev_class = {
861 .name = "hiddev%d", 861 .name = "hiddev%d",
862 .nodename = hiddev_nodename, 862 .devnode = hiddev_devnode,
863 .fops = &hiddev_fops, 863 .fops = &hiddev_fops,
864 .minor_base = HIDDEV_MINOR_BASE, 864 .minor_base = HIDDEV_MINOR_BASE,
865}; 865};
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 851791d955f3..556539d617a4 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -1265,14 +1265,14 @@ static struct device_type input_dev_type = {
1265 .uevent = input_dev_uevent, 1265 .uevent = input_dev_uevent,
1266}; 1266};
1267 1267
1268static char *input_nodename(struct device *dev) 1268static char *input_devnode(struct device *dev, mode_t *mode)
1269{ 1269{
1270 return kasprintf(GFP_KERNEL, "input/%s", dev_name(dev)); 1270 return kasprintf(GFP_KERNEL, "input/%s", dev_name(dev));
1271} 1271}
1272 1272
1273struct class input_class = { 1273struct class input_class = {
1274 .name = "input", 1274 .name = "input",
1275 .nodename = input_nodename, 1275 .devnode = input_devnode,
1276}; 1276};
1277EXPORT_SYMBOL_GPL(input_class); 1277EXPORT_SYMBOL_GPL(input_class);
1278 1278
diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
index 7f77f18fcafa..a67942931582 100644
--- a/drivers/md/dm-ioctl.c
+++ b/drivers/md/dm-ioctl.c
@@ -1532,7 +1532,7 @@ static const struct file_operations _ctl_fops = {
1532static struct miscdevice _dm_misc = { 1532static struct miscdevice _dm_misc = {
1533 .minor = MISC_DYNAMIC_MINOR, 1533 .minor = MISC_DYNAMIC_MINOR,
1534 .name = DM_NAME, 1534 .name = DM_NAME,
1535 .devnode = "mapper/control", 1535 .nodename = "mapper/control",
1536 .fops = &_ctl_fops 1536 .fops = &_ctl_fops
1537}; 1537};
1538 1538
diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
index 479dd05762a5..94159b90f733 100644
--- a/drivers/media/dvb/dvb-core/dvbdev.c
+++ b/drivers/media/dvb/dvb-core/dvbdev.c
@@ -447,7 +447,7 @@ static int dvb_uevent(struct device *dev, struct kobj_uevent_env *env)
447 return 0; 447 return 0;
448} 448}
449 449
450static char *dvb_nodename(struct device *dev) 450static char *dvb_devnode(struct device *dev, mode_t *mode)
451{ 451{
452 struct dvb_device *dvbdev = dev_get_drvdata(dev); 452 struct dvb_device *dvbdev = dev_get_drvdata(dev);
453 453
@@ -478,7 +478,7 @@ static int __init init_dvbdev(void)
478 goto error; 478 goto error;
479 } 479 }
480 dvb_class->dev_uevent = dvb_uevent; 480 dvb_class->dev_uevent = dvb_uevent;
481 dvb_class->nodename = dvb_nodename; 481 dvb_class->devnode = dvb_devnode;
482 return 0; 482 return 0;
483 483
484error: 484error:
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 3f5d28851aa2..d3ee1994b02f 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1370,7 +1370,7 @@ static const struct file_operations tun_fops = {
1370static struct miscdevice tun_miscdev = { 1370static struct miscdevice tun_miscdev = {
1371 .minor = TUN_MINOR, 1371 .minor = TUN_MINOR,
1372 .name = "tun", 1372 .name = "tun",
1373 .devnode = "net/tun", 1373 .nodename = "net/tun",
1374 .fops = &tun_fops, 1374 .fops = &tun_fops,
1375}; 1375};
1376 1376
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index 26c09f0257db..9bc112ee7803 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -1057,14 +1057,14 @@ static const struct file_operations usblp_fops = {
1057 .release = usblp_release, 1057 .release = usblp_release,
1058}; 1058};
1059 1059
1060static char *usblp_nodename(struct device *dev) 1060static char *usblp_devnode(struct device *dev, mode_t *mode)
1061{ 1061{
1062 return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev)); 1062 return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev));
1063} 1063}
1064 1064
1065static struct usb_class_driver usblp_class = { 1065static struct usb_class_driver usblp_class = {
1066 .name = "lp%d", 1066 .name = "lp%d",
1067 .nodename = usblp_nodename, 1067 .devnode = usblp_devnode,
1068 .fops = &usblp_fops, 1068 .fops = &usblp_fops,
1069 .minor_base = USBLP_MINOR_BASE, 1069 .minor_base = USBLP_MINOR_BASE,
1070}; 1070};
diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c
index 5cef88929b3e..222ee07ea680 100644
--- a/drivers/usb/core/file.c
+++ b/drivers/usb/core/file.c
@@ -67,14 +67,14 @@ static struct usb_class {
67 struct class *class; 67 struct class *class;
68} *usb_class; 68} *usb_class;
69 69
70static char *usb_nodename(struct device *dev) 70static char *usb_devnode(struct device *dev, mode_t *mode)
71{ 71{
72 struct usb_class_driver *drv; 72 struct usb_class_driver *drv;
73 73
74 drv = dev_get_drvdata(dev); 74 drv = dev_get_drvdata(dev);
75 if (!drv || !drv->nodename) 75 if (!drv || !drv->devnode)
76 return NULL; 76 return NULL;
77 return drv->nodename(dev); 77 return drv->devnode(dev, mode);
78} 78}
79 79
80static int init_usb_class(void) 80static int init_usb_class(void)
@@ -100,7 +100,7 @@ static int init_usb_class(void)
100 kfree(usb_class); 100 kfree(usb_class);
101 usb_class = NULL; 101 usb_class = NULL;
102 } 102 }
103 usb_class->class->nodename = usb_nodename; 103 usb_class->class->devnode = usb_devnode;
104 104
105exit: 105exit:
106 return result; 106 return result;
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index a26f73880c32..43ee943d757a 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -311,7 +311,7 @@ static struct dev_pm_ops usb_device_pm_ops = {
311#endif /* CONFIG_PM */ 311#endif /* CONFIG_PM */
312 312
313 313
314static char *usb_nodename(struct device *dev) 314static char *usb_devnode(struct device *dev, mode_t *mode)
315{ 315{
316 struct usb_device *usb_dev; 316 struct usb_device *usb_dev;
317 317
@@ -324,7 +324,7 @@ struct device_type usb_device_type = {
324 .name = "usb_device", 324 .name = "usb_device",
325 .release = usb_release_dev, 325 .release = usb_release_dev,
326 .uevent = usb_dev_uevent, 326 .uevent = usb_dev_uevent,
327 .nodename = usb_nodename, 327 .devnode = usb_devnode,
328 .pm = &usb_device_pm_ops, 328 .pm = &usb_device_pm_ops,
329}; 329};
330 330
diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c
index 90e1a8dedfa9..e75bb87ee92b 100644
--- a/drivers/usb/misc/iowarrior.c
+++ b/drivers/usb/misc/iowarrior.c
@@ -727,7 +727,7 @@ static const struct file_operations iowarrior_fops = {
727 .poll = iowarrior_poll, 727 .poll = iowarrior_poll,
728}; 728};
729 729
730static char *iowarrior_nodename(struct device *dev) 730static char *iowarrior_devnode(struct device *dev, mode_t *mode)
731{ 731{
732 return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev)); 732 return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev));
733} 733}
@@ -738,7 +738,7 @@ static char *iowarrior_nodename(struct device *dev)
738 */ 738 */
739static struct usb_class_driver iowarrior_class = { 739static struct usb_class_driver iowarrior_class = {
740 .name = "iowarrior%d", 740 .name = "iowarrior%d",
741 .nodename = iowarrior_nodename, 741 .devnode = iowarrior_devnode,
742 .fops = &iowarrior_fops, 742 .fops = &iowarrior_fops,
743 .minor_base = IOWARRIOR_MINOR_BASE, 743 .minor_base = IOWARRIOR_MINOR_BASE,
744}; 744};
diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index c1e2433f640d..97efeaec4d52 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -266,7 +266,7 @@ static const struct file_operations tower_fops = {
266 .llseek = tower_llseek, 266 .llseek = tower_llseek,
267}; 267};
268 268
269static char *legousbtower_nodename(struct device *dev) 269static char *legousbtower_devnode(struct device *dev, mode_t *mode)
270{ 270{
271 return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev)); 271 return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev));
272} 272}
@@ -277,7 +277,7 @@ static char *legousbtower_nodename(struct device *dev)
277 */ 277 */
278static struct usb_class_driver tower_class = { 278static struct usb_class_driver tower_class = {
279 .name = "legousbtower%d", 279 .name = "legousbtower%d",
280 .nodename = legousbtower_nodename, 280 .devnode = legousbtower_devnode,
281 .fops = &tower_fops, 281 .fops = &tower_fops,
282 .minor_base = LEGO_USB_TOWER_MINOR_BASE, 282 .minor_base = LEGO_USB_TOWER_MINOR_BASE,
283}; 283};
diff --git a/include/linux/device.h b/include/linux/device.h
index 847b763e40e9..aca31bf7d8ed 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -193,7 +193,7 @@ struct class {
193 struct kobject *dev_kobj; 193 struct kobject *dev_kobj;
194 194
195 int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env); 195 int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env);
196 char *(*nodename)(struct device *dev); 196 char *(*devnode)(struct device *dev, mode_t *mode);
197 197
198 void (*class_release)(struct class *class); 198 void (*class_release)(struct class *class);
199 void (*dev_release)(struct device *dev); 199 void (*dev_release)(struct device *dev);
@@ -298,7 +298,7 @@ struct device_type {
298 const char *name; 298 const char *name;
299 const struct attribute_group **groups; 299 const struct attribute_group **groups;
300 int (*uevent)(struct device *dev, struct kobj_uevent_env *env); 300 int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
301 char *(*nodename)(struct device *dev); 301 char *(*devnode)(struct device *dev, mode_t *mode);
302 void (*release)(struct device *dev); 302 void (*release)(struct device *dev);
303 303
304 const struct dev_pm_ops *pm; 304 const struct dev_pm_ops *pm;
@@ -487,7 +487,8 @@ extern struct device *device_find_child(struct device *dev, void *data,
487extern int device_rename(struct device *dev, char *new_name); 487extern int device_rename(struct device *dev, char *new_name);
488extern int device_move(struct device *dev, struct device *new_parent, 488extern int device_move(struct device *dev, struct device *new_parent,
489 enum dpm_order dpm_order); 489 enum dpm_order dpm_order);
490extern const char *device_get_nodename(struct device *dev, const char **tmp); 490extern const char *device_get_devnode(struct device *dev,
491 mode_t *mode, const char **tmp);
491extern void *dev_get_drvdata(const struct device *dev); 492extern void *dev_get_drvdata(const struct device *dev);
492extern void dev_set_drvdata(struct device *dev, void *data); 493extern void dev_set_drvdata(struct device *dev, void *data);
493 494
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 44263cb27121..109d179adb93 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -142,7 +142,7 @@ struct gendisk {
142 * disks that can't be partitioned. */ 142 * disks that can't be partitioned. */
143 143
144 char disk_name[DISK_NAME_LEN]; /* name of major driver */ 144 char disk_name[DISK_NAME_LEN]; /* name of major driver */
145 char *(*nodename)(struct gendisk *gd); 145 char *(*devnode)(struct gendisk *gd, mode_t *mode);
146 /* Array of pointers to partitions indexed by partno. 146 /* Array of pointers to partitions indexed by partno.
147 * Protected with matching bdev lock but stat and other 147 * Protected with matching bdev lock but stat and other
148 * non-critical accesses use RCU. Always access through 148 * non-critical accesses use RCU. Always access through
diff --git a/include/linux/miscdevice.h b/include/linux/miscdevice.h
index 052117744629..adaf3c15e449 100644
--- a/include/linux/miscdevice.h
+++ b/include/linux/miscdevice.h
@@ -41,7 +41,8 @@ struct miscdevice {
41 struct list_head list; 41 struct list_head list;
42 struct device *parent; 42 struct device *parent;
43 struct device *this_device; 43 struct device *this_device;
44 const char *devnode; 44 const char *nodename;
45 mode_t mode;
45}; 46};
46 47
47extern int misc_register(struct miscdevice * misc); 48extern int misc_register(struct miscdevice * misc);
diff --git a/include/linux/usb.h b/include/linux/usb.h
index b1e3c2fbfe11..a8fe05f224e5 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -922,7 +922,7 @@ extern struct bus_type usb_bus_type;
922/** 922/**
923 * struct usb_class_driver - identifies a USB driver that wants to use the USB major number 923 * struct usb_class_driver - identifies a USB driver that wants to use the USB major number
924 * @name: the usb class device name for this driver. Will show up in sysfs. 924 * @name: the usb class device name for this driver. Will show up in sysfs.
925 * @nodename: Callback to provide a naming hint for a possible 925 * @devnode: Callback to provide a naming hint for a possible
926 * device node to create. 926 * device node to create.
927 * @fops: pointer to the struct file_operations of this driver. 927 * @fops: pointer to the struct file_operations of this driver.
928 * @minor_base: the start of the minor range for this driver. 928 * @minor_base: the start of the minor range for this driver.
@@ -933,7 +933,7 @@ extern struct bus_type usb_bus_type;
933 */ 933 */
934struct usb_class_driver { 934struct usb_class_driver {
935 char *name; 935 char *name;
936 char *(*nodename)(struct device *dev); 936 char *(*devnode)(struct device *dev, mode_t *mode);
937 const struct file_operations *fops; 937 const struct file_operations *fops;
938 int minor_base; 938 int minor_base;
939}; 939};
diff --git a/sound/sound_core.c b/sound/sound_core.c
index bb4b88e606bb..49c998186592 100644
--- a/sound/sound_core.c
+++ b/sound/sound_core.c
@@ -29,7 +29,7 @@ MODULE_DESCRIPTION("Core sound module");
29MODULE_AUTHOR("Alan Cox"); 29MODULE_AUTHOR("Alan Cox");
30MODULE_LICENSE("GPL"); 30MODULE_LICENSE("GPL");
31 31
32static char *sound_nodename(struct device *dev) 32static char *sound_devnode(struct device *dev, mode_t *mode)
33{ 33{
34 if (MAJOR(dev->devt) == SOUND_MAJOR) 34 if (MAJOR(dev->devt) == SOUND_MAJOR)
35 return NULL; 35 return NULL;
@@ -50,7 +50,7 @@ static int __init init_soundcore(void)
50 return PTR_ERR(sound_class); 50 return PTR_ERR(sound_class);
51 } 51 }
52 52
53 sound_class->nodename = sound_nodename; 53 sound_class->devnode = sound_devnode;
54 54
55 return 0; 55 return 0;
56} 56}