Skip to content

Commit a57c21c

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core-2.6: Driver-Core: extend devnode callbacks to provide permissions
2 parents e11c675 + e454cea commit a57c21c

File tree

30 files changed

+116
-79
lines changed

30 files changed

+116
-79
lines changed

arch/x86/kernel/cpuid.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ static struct notifier_block __refdata cpuid_class_cpu_notifier =
182182
.notifier_call = cpuid_class_cpu_callback,
183183
};
184184

185-
static char *cpuid_nodename(struct device *dev)
185+
static char *cpuid_devnode(struct device *dev, mode_t *mode)
186186
{
187187
return kasprintf(GFP_KERNEL, "cpu/%u/cpuid", MINOR(dev->devt));
188188
}
@@ -203,7 +203,7 @@ static int __init cpuid_init(void)
203203
err = PTR_ERR(cpuid_class);
204204
goto out_chrdev;
205205
}
206-
cpuid_class->nodename = cpuid_nodename;
206+
cpuid_class->devnode = cpuid_devnode;
207207
for_each_online_cpu(i) {
208208
err = cpuid_device_create(i);
209209
if (err != 0)

arch/x86/kernel/microcode_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ static const struct file_operations microcode_fops = {
236236
static struct miscdevice microcode_dev = {
237237
.minor = MICROCODE_MINOR,
238238
.name = "microcode",
239-
.devnode = "cpu/microcode",
239+
.nodename = "cpu/microcode",
240240
.fops = &microcode_fops,
241241
};
242242

arch/x86/kernel/msr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ static struct notifier_block __refdata msr_class_cpu_notifier = {
241241
.notifier_call = msr_class_cpu_callback,
242242
};
243243

244-
static char *msr_nodename(struct device *dev)
244+
static char *msr_devnode(struct device *dev, mode_t *mode)
245245
{
246246
return kasprintf(GFP_KERNEL, "cpu/%u/msr", MINOR(dev->devt));
247247
}
@@ -262,7 +262,7 @@ static int __init msr_init(void)
262262
err = PTR_ERR(msr_class);
263263
goto out_chrdev;
264264
}
265-
msr_class->nodename = msr_nodename;
265+
msr_class->devnode = msr_devnode;
266266
for_each_online_cpu(i) {
267267
err = msr_device_create(i);
268268
if (err != 0)

block/bsg.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ EXPORT_SYMBOL_GPL(bsg_register_queue);
10621062

10631063
static struct cdev bsg_cdev;
10641064

1065-
static char *bsg_nodename(struct device *dev)
1065+
static char *bsg_devnode(struct device *dev, mode_t *mode)
10661066
{
10671067
return kasprintf(GFP_KERNEL, "bsg/%s", dev_name(dev));
10681068
}
@@ -1087,7 +1087,7 @@ static int __init bsg_init(void)
10871087
ret = PTR_ERR(bsg_class);
10881088
goto destroy_kmemcache;
10891089
}
1090-
bsg_class->nodename = bsg_nodename;
1090+
bsg_class->devnode = bsg_devnode;
10911091

10921092
ret = alloc_chrdev_region(&devid, 0, BSG_MAX_DEVS, "bsg");
10931093
if (ret)

block/genhd.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -998,20 +998,20 @@ struct class block_class = {
998998
.name = "block",
999999
};
10001000

1001-
static char *block_nodename(struct device *dev)
1001+
static char *block_devnode(struct device *dev, mode_t *mode)
10021002
{
10031003
struct gendisk *disk = dev_to_disk(dev);
10041004

1005-
if (disk->nodename)
1006-
return disk->nodename(disk);
1005+
if (disk->devnode)
1006+
return disk->devnode(disk, mode);
10071007
return NULL;
10081008
}
10091009

10101010
static struct device_type disk_type = {
10111011
.name = "disk",
10121012
.groups = disk_attr_groups,
10131013
.release = disk_release,
1014-
.nodename = block_nodename,
1014+
.devnode = block_devnode,
10151015
};
10161016

10171017
#ifdef CONFIG_PROC_FS

drivers/base/core.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,16 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
166166
if (MAJOR(dev->devt)) {
167167
const char *tmp;
168168
const char *name;
169+
mode_t mode = 0;
169170

170171
add_uevent_var(env, "MAJOR=%u", MAJOR(dev->devt));
171172
add_uevent_var(env, "MINOR=%u", MINOR(dev->devt));
172-
name = device_get_nodename(dev, &tmp);
173+
name = device_get_devnode(dev, &mode, &tmp);
173174
if (name) {
174175
add_uevent_var(env, "DEVNAME=%s", name);
175176
kfree(tmp);
177+
if (mode)
178+
add_uevent_var(env, "DEVMODE=%#o", mode & 0777);
176179
}
177180
}
178181

@@ -1148,30 +1151,32 @@ static struct device *next_device(struct klist_iter *i)
11481151
}
11491152

11501153
/**
1151-
* device_get_nodename - path of device node file
1154+
* device_get_devnode - path of device node file
11521155
* @dev: device
1156+
* @mode: returned file access mode
11531157
* @tmp: possibly allocated string
11541158
*
11551159
* Return the relative path of a possible device node.
11561160
* Non-default names may need to allocate a memory to compose
11571161
* a name. This memory is returned in tmp and needs to be
11581162
* freed by the caller.
11591163
*/
1160-
const char *device_get_nodename(struct device *dev, const char **tmp)
1164+
const char *device_get_devnode(struct device *dev,
1165+
mode_t *mode, const char **tmp)
11611166
{
11621167
char *s;
11631168

11641169
*tmp = NULL;
11651170

11661171
/* the device type may provide a specific name */
1167-
if (dev->type && dev->type->nodename)
1168-
*tmp = dev->type->nodename(dev);
1172+
if (dev->type && dev->type->devnode)
1173+
*tmp = dev->type->devnode(dev, mode);
11691174
if (*tmp)
11701175
return *tmp;
11711176

11721177
/* the class may provide a specific name */
1173-
if (dev->class && dev->class->nodename)
1174-
*tmp = dev->class->nodename(dev);
1178+
if (dev->class && dev->class->devnode)
1179+
*tmp = dev->class->devnode(dev, mode);
11751180
if (*tmp)
11761181
return *tmp;
11771182

drivers/base/devtmpfs.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
* During bootup, before any driver core device is registered,
77
* devtmpfs, a tmpfs-based filesystem is created. Every driver-core
88
* 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,
10-
* or the susbsytem can provide a custom name. All devices are
11-
* owned by root and have a mode of 0600.
9+
* filesystem.
10+
* By default, all devices are named after the the name of the
11+
* device, owned by root and have a default mode of 0600. Subsystems
12+
* can overwrite the default setting if needed.
1213
*/
1314

1415
#include <linux/kernel.h>
@@ -20,6 +21,7 @@
2021
#include <linux/fs.h>
2122
#include <linux/shmem_fs.h>
2223
#include <linux/cred.h>
24+
#include <linux/sched.h>
2325
#include <linux/init_task.h>
2426

2527
static struct vfsmount *dev_mnt;
@@ -134,22 +136,24 @@ int devtmpfs_create_node(struct device *dev)
134136
const char *tmp = NULL;
135137
const char *nodename;
136138
const struct cred *curr_cred;
137-
mode_t mode;
139+
mode_t mode = 0;
138140
struct nameidata nd;
139141
struct dentry *dentry;
140142
int err;
141143

142144
if (!dev_mnt)
143145
return 0;
144146

145-
nodename = device_get_nodename(dev, &tmp);
147+
nodename = device_get_devnode(dev, &mode, &tmp);
146148
if (!nodename)
147149
return -ENOMEM;
148150

151+
if (mode == 0)
152+
mode = 0600;
149153
if (is_blockdev(dev))
150-
mode = S_IFBLK|0600;
154+
mode |= S_IFBLK;
151155
else
152-
mode = S_IFCHR|0600;
156+
mode |= S_IFCHR;
153157

154158
curr_cred = override_creds(&init_cred);
155159
err = vfs_path_lookup(dev_mnt->mnt_root, dev_mnt,
@@ -165,8 +169,12 @@ int devtmpfs_create_node(struct device *dev)
165169

166170
dentry = lookup_create(&nd, 0);
167171
if (!IS_ERR(dentry)) {
172+
int umask;
173+
174+
umask = sys_umask(0000);
168175
err = vfs_mknod(nd.path.dentry->d_inode,
169176
dentry, mode, dev->devt);
177+
sys_umask(umask);
170178
/* mark as kernel created inode */
171179
if (!err)
172180
dentry->d_inode->i_private = &dev_mnt;
@@ -271,7 +279,7 @@ int devtmpfs_delete_node(struct device *dev)
271279
if (!dev_mnt)
272280
return 0;
273281

274-
nodename = device_get_nodename(dev, &tmp);
282+
nodename = device_get_devnode(dev, NULL, &tmp);
275283
if (!nodename)
276284
return -ENOMEM;
277285

drivers/block/aoe/aoechr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ static const struct file_operations aoe_fops = {
266266
.owner = THIS_MODULE,
267267
};
268268

269-
static char *aoe_nodename(struct device *dev)
269+
static char *aoe_devnode(struct device *dev, mode_t *mode)
270270
{
271271
return kasprintf(GFP_KERNEL, "etherd/%s", dev_name(dev));
272272
}
@@ -288,7 +288,7 @@ aoechr_init(void)
288288
unregister_chrdev(AOE_MAJOR, "aoechr");
289289
return PTR_ERR(aoe_class);
290290
}
291-
aoe_class->nodename = aoe_nodename;
291+
aoe_class->devnode = aoe_devnode;
292292

293293
for (i = 0; i < ARRAY_SIZE(chardevs); ++i)
294294
device_create(aoe_class, NULL,

drivers/block/pktcdvd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2857,7 +2857,7 @@ static struct block_device_operations pktcdvd_ops = {
28572857
.media_changed = pkt_media_changed,
28582858
};
28592859

2860-
static char *pktcdvd_nodename(struct gendisk *gd)
2860+
static char *pktcdvd_devnode(struct gendisk *gd, mode_t *mode)
28612861
{
28622862
return kasprintf(GFP_KERNEL, "pktcdvd/%s", gd->disk_name);
28632863
}
@@ -2914,7 +2914,7 @@ static int pkt_setup_dev(dev_t dev, dev_t* pkt_dev)
29142914
disk->fops = &pktcdvd_ops;
29152915
disk->flags = GENHD_FL_REMOVABLE;
29162916
strcpy(disk->disk_name, pd->name);
2917-
disk->nodename = pktcdvd_nodename;
2917+
disk->devnode = pktcdvd_devnode;
29182918
disk->private_data = pd;
29192919
disk->queue = blk_alloc_queue(GFP_KERNEL);
29202920
if (!disk->queue)
@@ -3070,7 +3070,7 @@ static const struct file_operations pkt_ctl_fops = {
30703070
static struct miscdevice pkt_misc = {
30713071
.minor = MISC_DYNAMIC_MINOR,
30723072
.name = DRIVER_NAME,
3073-
.name = "pktcdvd/control",
3073+
.nodename = "pktcdvd/control",
30743074
.fops = &pkt_ctl_fops
30753075
};
30763076

drivers/char/hw_random/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ static const struct file_operations rng_chrdev_ops = {
153153
static struct miscdevice rng_miscdev = {
154154
.minor = RNG_MISCDEV_MINOR,
155155
.name = RNG_MODULE_NAME,
156-
.devnode = "hwrng",
156+
.nodename = "hwrng",
157157
.fops = &rng_chrdev_ops,
158158
};
159159

drivers/char/mem.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -866,24 +866,25 @@ static const struct file_operations kmsg_fops = {
866866

867867
static const struct memdev {
868868
const char *name;
869+
mode_t mode;
869870
const struct file_operations *fops;
870871
struct backing_dev_info *dev_info;
871872
} devlist[] = {
872-
[ 1] = { "mem", &mem_fops, &directly_mappable_cdev_bdi },
873+
[1] = { "mem", 0, &mem_fops, &directly_mappable_cdev_bdi },
873874
#ifdef CONFIG_DEVKMEM
874-
[ 2] = { "kmem", &kmem_fops, &directly_mappable_cdev_bdi },
875+
[2] = { "kmem", 0, &kmem_fops, &directly_mappable_cdev_bdi },
875876
#endif
876-
[ 3] = {"null", &null_fops, NULL },
877+
[3] = { "null", 0666, &null_fops, NULL },
877878
#ifdef CONFIG_DEVPORT
878-
[ 4] = { "port", &port_fops, NULL },
879+
[4] = { "port", 0, &port_fops, NULL },
879880
#endif
880-
[ 5] = { "zero", &zero_fops, &zero_bdi },
881-
[ 7] = { "full", &full_fops, NULL },
882-
[ 8] = { "random", &random_fops, NULL },
883-
[ 9] = { "urandom", &urandom_fops, NULL },
884-
[11] = { "kmsg", &kmsg_fops, NULL },
881+
[5] = { "zero", 0666, &zero_fops, &zero_bdi },
882+
[7] = { "full", 0666, &full_fops, NULL },
883+
[8] = { "random", 0666, &random_fops, NULL },
884+
[9] = { "urandom", 0666, &urandom_fops, NULL },
885+
[11] = { "kmsg", 0, &kmsg_fops, NULL },
885886
#ifdef CONFIG_CRASH_DUMP
886-
[12] = { "oldmem", &oldmem_fops, NULL },
887+
[12] = { "oldmem", 0, &oldmem_fops, NULL },
887888
#endif
888889
};
889890

@@ -920,6 +921,13 @@ static const struct file_operations memory_fops = {
920921
.open = memory_open,
921922
};
922923

924+
static 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+
923931
static struct class *mem_class;
924932

925933
static int __init chr_dev_init(void)
@@ -935,6 +943,7 @@ static int __init chr_dev_init(void)
935943
printk("unable to get major %d for memory devs\n", MEM_MAJOR);
936944

937945
mem_class = class_create(THIS_MODULE, "mem");
946+
mem_class->devnode = mem_devnode;
938947
for (minor = 1; minor < ARRAY_SIZE(devlist); minor++) {
939948
if (!devlist[minor].name)
940949
continue;

drivers/char/misc.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,14 @@ int misc_deregister(struct miscdevice *misc)
263263
EXPORT_SYMBOL(misc_register);
264264
EXPORT_SYMBOL(misc_deregister);
265265

266-
static char *misc_nodename(struct device *dev)
266+
static char *misc_devnode(struct device *dev, mode_t *mode)
267267
{
268268
struct miscdevice *c = dev_get_drvdata(dev);
269269

270-
if (c->devnode)
271-
return kstrdup(c->devnode, GFP_KERNEL);
270+
if (mode && c->mode)
271+
*mode = c->mode;
272+
if (c->nodename)
273+
return kstrdup(c->nodename, GFP_KERNEL);
272274
return NULL;
273275
}
274276

@@ -287,7 +289,7 @@ static int __init misc_init(void)
287289
err = -EIO;
288290
if (register_chrdev(MISC_MAJOR,"misc",&misc_fops))
289291
goto fail_printk;
290-
misc_class->nodename = misc_nodename;
292+
misc_class->devnode = misc_devnode;
291293
return 0;
292294

293295
fail_printk:

drivers/char/raw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ static const struct file_operations raw_ctl_fops = {
261261

262262
static struct cdev raw_cdev;
263263

264-
static char *raw_nodename(struct device *dev)
264+
static char *raw_devnode(struct device *dev, mode_t *mode)
265265
{
266266
return kasprintf(GFP_KERNEL, "raw/%s", dev_name(dev));
267267
}
@@ -289,7 +289,7 @@ static int __init raw_init(void)
289289
ret = PTR_ERR(raw_class);
290290
goto error_region;
291291
}
292-
raw_class->nodename = raw_nodename;
292+
raw_class->devnode = raw_devnode;
293293
device_create(raw_class, NULL, MKDEV(RAW_MAJOR, 0), NULL, "rawctl");
294294

295295
return 0;

drivers/char/tty_io.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3070,11 +3070,22 @@ void __init console_init(void)
30703070
}
30713071
}
30723072

3073+
static char *tty_devnode(struct device *dev, mode_t *mode)
3074+
{
3075+
if (!mode)
3076+
return NULL;
3077+
if (dev->devt == MKDEV(TTYAUX_MAJOR, 0) ||
3078+
dev->devt == MKDEV(TTYAUX_MAJOR, 2))
3079+
*mode = 0666;
3080+
return NULL;
3081+
}
3082+
30733083
static int __init tty_class_init(void)
30743084
{
30753085
tty_class = class_create(THIS_MODULE, "tty");
30763086
if (IS_ERR(tty_class))
30773087
return PTR_ERR(tty_class);
3088+
tty_class->devnode = tty_devnode;
30783089
return 0;
30793090
}
30803091

0 commit comments

Comments
 (0)