···166166 if (MAJOR(dev->devt)) {167167 const char *tmp;168168 const char *name;169169+ mode_t mode = 0;169170170171 add_uevent_var(env, "MAJOR=%u", MAJOR(dev->devt));171172 add_uevent_var(env, "MINOR=%u", MINOR(dev->devt));172172- name = device_get_nodename(dev, &tmp);173173+ name = device_get_devnode(dev, &mode, &tmp);173174 if (name) {174175 add_uevent_var(env, "DEVNAME=%s", name);175176 kfree(tmp);177177+ if (mode)178178+ add_uevent_var(env, "DEVMODE=%#o", mode & 0777);176179 }177180 }178181···11511148}1152114911531150/**11541154- * device_get_nodename - path of device node file11511151+ * device_get_devnode - path of device node file11551152 * @dev: device11531153+ * @mode: returned file access mode11561154 * @tmp: possibly allocated string11571155 *11581156 * Return the relative path of a possible device node.···11611157 * a name. This memory is returned in tmp and needs to be11621158 * freed by the caller.11631159 */11641164-const char *device_get_nodename(struct device *dev, const char **tmp)11601160+const char *device_get_devnode(struct device *dev,11611161+ mode_t *mode, const char **tmp)11651162{11661163 char *s;1167116411681165 *tmp = NULL;1169116611701167 /* the device type may provide a specific name */11711171- if (dev->type && dev->type->nodename)11721172- *tmp = dev->type->nodename(dev);11681168+ if (dev->type && dev->type->devnode)11691169+ *tmp = dev->type->devnode(dev, mode);11731170 if (*tmp)11741171 return *tmp;1175117211761173 /* the class may provide a specific name */11771177- if (dev->class && dev->class->nodename)11781178- *tmp = dev->class->nodename(dev);11741174+ if (dev->class && dev->class->devnode)11751175+ *tmp = dev->class->devnode(dev, mode);11791176 if (*tmp)11801177 return *tmp;11811178
+16-8
drivers/base/devtmpfs.c
···66 * During bootup, before any driver core device is registered,77 * devtmpfs, a tmpfs-based filesystem is created. Every driver-core88 * device which requests a device node, will add a node in this99- * filesystem. The node is named after the the name of the device,1010- * or the susbsytem can provide a custom name. All devices are1111- * owned by root and have a mode of 0600.99+ * filesystem.1010+ * By default, all devices are named after the the name of the1111+ * device, owned by root and have a default mode of 0600. Subsystems1212+ * can overwrite the default setting if needed.1213 */13141415#include <linux/kernel.h>···2120#include <linux/fs.h>2221#include <linux/shmem_fs.h>2322#include <linux/cred.h>2323+#include <linux/sched.h>2424#include <linux/init_task.h>25252626static struct vfsmount *dev_mnt;···136134 const char *tmp = NULL;137135 const char *nodename;138136 const struct cred *curr_cred;139139- mode_t mode;137137+ mode_t mode = 0;140138 struct nameidata nd;141139 struct dentry *dentry;142140 int err;···144142 if (!dev_mnt)145143 return 0;146144147147- nodename = device_get_nodename(dev, &tmp);145145+ nodename = device_get_devnode(dev, &mode, &tmp);148146 if (!nodename)149147 return -ENOMEM;150148149149+ if (mode == 0)150150+ mode = 0600;151151 if (is_blockdev(dev))152152- mode = S_IFBLK|0600;152152+ mode |= S_IFBLK;153153 else154154- mode = S_IFCHR|0600;154154+ mode |= S_IFCHR;155155156156 curr_cred = override_creds(&init_cred);157157 err = vfs_path_lookup(dev_mnt->mnt_root, dev_mnt,···169165170166 dentry = lookup_create(&nd, 0);171167 if (!IS_ERR(dentry)) {168168+ int umask;169169+170170+ umask = sys_umask(0000);172171 err = vfs_mknod(nd.path.dentry->d_inode,173172 dentry, mode, dev->devt);173173+ sys_umask(umask);174174 /* mark as kernel created inode */175175 if (!err)176176 dentry->d_inode->i_private = &dev_mnt;···279271 if (!dev_mnt)280272 return 0;281273282282- nodename = device_get_nodename(dev, &tmp);274274+ nodename = device_get_devnode(dev, NULL, &tmp);283275 if (!nodename)284276 return -ENOMEM;285277
···142142 * disks that can't be partitioned. */143143144144 char disk_name[DISK_NAME_LEN]; /* name of major driver */145145- char *(*nodename)(struct gendisk *gd);145145+ char *(*devnode)(struct gendisk *gd, mode_t *mode);146146 /* Array of pointers to partitions indexed by partno.147147 * Protected with matching bdev lock but stat and other148148 * non-critical accesses use RCU. Always access through
···922922/**923923 * struct usb_class_driver - identifies a USB driver that wants to use the USB major number924924 * @name: the usb class device name for this driver. Will show up in sysfs.925925- * @nodename: Callback to provide a naming hint for a possible925925+ * @devnode: Callback to provide a naming hint for a possible926926 * device node to create.927927 * @fops: pointer to the struct file_operations of this driver.928928 * @minor_base: the start of the minor range for this driver.···933933 */934934struct usb_class_driver {935935 char *name;936936- char *(*nodename)(struct device *dev);936936+ char *(*devnode)(struct device *dev, mode_t *mode);937937 const struct file_operations *fops;938938 int minor_base;939939};