Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: (27 commits)
Driver core: fix race in dev_driver_string
Driver Core: Early platform driver buffer
sysfs: sysfs_setattr remove unnecessary permission check.
sysfs: Factor out sysfs_rename from sysfs_rename_dir and sysfs_move_dir
sysfs: Propagate renames to the vfs on demand
sysfs: Gut sysfs_addrm_start and sysfs_addrm_finish
sysfs: In sysfs_chmod_file lazily propagate the mode change.
sysfs: Implement sysfs_getattr & sysfs_permission
sysfs: Nicely indent sysfs_symlink_inode_operations
sysfs: Update s_iattr on link and unlink.
sysfs: Fix locking and factor out sysfs_sd_setattr
sysfs: Simplify iattr time assignments
sysfs: Simplify sysfs_chmod_file semantics
sysfs: Use dentry_ops instead of directly playing with the dcache
sysfs: Rename sysfs_d_iput to sysfs_dentry_iput
sysfs: Update sysfs_setxattr so it updates secdata under the sysfs_mutex
debugfs: fix create mutex racy fops and private data
Driver core: Don't remove kobjects in device_shutdown.
firmware_class: make request_firmware_nowait more useful
Driver-Core: devtmpfs - set root directory mode to 0755
...

+430 -508
+10 -4
drivers/base/core.c
··· 56 56 */ 57 57 const char *dev_driver_string(const struct device *dev) 58 58 { 59 - return dev->driver ? dev->driver->name : 59 + struct device_driver *drv; 60 + 61 + /* dev->driver can change to NULL underneath us because of unbinding, 62 + * so be careful about accessing it. dev->bus and dev->class should 63 + * never change once they are set, so they don't need special care. 64 + */ 65 + drv = ACCESS_ONCE(dev->driver); 66 + return drv ? drv->name : 60 67 (dev->bus ? dev->bus->name : 61 68 (dev->class ? dev->class->name : "")); 62 69 } ··· 994 987 device_remove_class_symlinks(dev); 995 988 SymlinkError: 996 989 if (MAJOR(dev->devt)) 990 + devtmpfs_delete_node(dev); 991 + if (MAJOR(dev->devt)) 997 992 device_remove_sys_dev_entry(dev); 998 993 devtattrError: 999 994 if (MAJOR(dev->devt)) ··· 1737 1728 dev->driver->shutdown(dev); 1738 1729 } 1739 1730 } 1740 - kobject_put(sysfs_dev_char_kobj); 1741 - kobject_put(sysfs_dev_block_kobj); 1742 - kobject_put(dev_kobj); 1743 1731 async_synchronize_full(); 1744 1732 }
+50 -50
drivers/base/devtmpfs.c
··· 32 32 static int dev_mount; 33 33 #endif 34 34 35 + static rwlock_t dirlock; 36 + 35 37 static int __init mount_param(char *str) 36 38 { 37 39 dev_mount = simple_strtoul(str, NULL, 0); ··· 76 74 dentry = lookup_create(&nd, 1); 77 75 if (!IS_ERR(dentry)) { 78 76 err = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode); 77 + if (!err) 78 + /* mark as kernel-created inode */ 79 + dentry->d_inode->i_private = &dev_mnt; 79 80 dput(dentry); 80 81 } else { 81 82 err = PTR_ERR(dentry); 82 83 } 83 - mutex_unlock(&nd.path.dentry->d_inode->i_mutex); 84 84 85 + mutex_unlock(&nd.path.dentry->d_inode->i_mutex); 85 86 path_put(&nd.path); 86 87 return err; 87 88 } 88 89 89 90 static int create_path(const char *nodepath) 90 91 { 91 - char *path; 92 - struct nameidata nd; 93 - int err = 0; 92 + int err; 94 93 95 - path = kstrdup(nodepath, GFP_KERNEL); 96 - if (!path) 97 - return -ENOMEM; 98 - 99 - err = vfs_path_lookup(dev_mnt->mnt_root, dev_mnt, 100 - path, LOOKUP_PARENT, &nd); 101 - if (err == 0) { 102 - struct dentry *dentry; 103 - 104 - /* create directory right away */ 105 - dentry = lookup_create(&nd, 1); 106 - if (!IS_ERR(dentry)) { 107 - err = vfs_mkdir(nd.path.dentry->d_inode, 108 - dentry, 0755); 109 - dput(dentry); 110 - } 111 - mutex_unlock(&nd.path.dentry->d_inode->i_mutex); 112 - 113 - path_put(&nd.path); 114 - } else if (err == -ENOENT) { 94 + read_lock(&dirlock); 95 + err = dev_mkdir(nodepath, 0755); 96 + if (err == -ENOENT) { 97 + char *path; 115 98 char *s; 116 99 117 100 /* parent directories do not exist, create them */ 101 + path = kstrdup(nodepath, GFP_KERNEL); 102 + if (!path) 103 + return -ENOMEM; 118 104 s = path; 119 - while (1) { 105 + for (;;) { 120 106 s = strchr(s, '/'); 121 107 if (!s) 122 108 break; ··· 115 125 s[0] = '/'; 116 126 s++; 117 127 } 128 + kfree(path); 118 129 } 119 - 120 - kfree(path); 130 + read_unlock(&dirlock); 121 131 return err; 122 132 } 123 133 ··· 146 156 mode |= S_IFCHR; 147 157 148 158 curr_cred = override_creds(&init_cred); 159 + 149 160 err = vfs_path_lookup(dev_mnt->mnt_root, dev_mnt, 150 161 nodename, LOOKUP_PARENT, &nd); 151 162 if (err == -ENOENT) { 152 - /* create missing parent directories */ 153 163 create_path(nodename); 154 164 err = vfs_path_lookup(dev_mnt->mnt_root, dev_mnt, 155 165 nodename, LOOKUP_PARENT, &nd); 156 - if (err) 157 - goto out; 158 166 } 167 + if (err) 168 + goto out; 159 169 160 170 dentry = lookup_create(&nd, 0); 161 171 if (!IS_ERR(dentry)) { 162 - int umask; 163 - 164 - umask = sys_umask(0000); 165 172 err = vfs_mknod(nd.path.dentry->d_inode, 166 173 dentry, mode, dev->devt); 167 - sys_umask(umask); 168 - /* mark as kernel created inode */ 169 - if (!err) 174 + if (!err) { 175 + struct iattr newattrs; 176 + 177 + /* fixup possibly umasked mode */ 178 + newattrs.ia_mode = mode; 179 + newattrs.ia_valid = ATTR_MODE; 180 + mutex_lock(&dentry->d_inode->i_mutex); 181 + notify_change(dentry, &newattrs); 182 + mutex_unlock(&dentry->d_inode->i_mutex); 183 + 184 + /* mark as kernel-created inode */ 170 185 dentry->d_inode->i_private = &dev_mnt; 186 + } 171 187 dput(dentry); 172 188 } else { 173 189 err = PTR_ERR(dentry); 174 190 } 175 - mutex_unlock(&nd.path.dentry->d_inode->i_mutex); 176 191 192 + mutex_unlock(&nd.path.dentry->d_inode->i_mutex); 177 193 path_put(&nd.path); 178 194 out: 179 195 kfree(tmp); ··· 201 205 mutex_lock_nested(&nd.path.dentry->d_inode->i_mutex, I_MUTEX_PARENT); 202 206 dentry = lookup_one_len(nd.last.name, nd.path.dentry, nd.last.len); 203 207 if (!IS_ERR(dentry)) { 204 - if (dentry->d_inode) 205 - err = vfs_rmdir(nd.path.dentry->d_inode, dentry); 206 - else 208 + if (dentry->d_inode) { 209 + if (dentry->d_inode->i_private == &dev_mnt) 210 + err = vfs_rmdir(nd.path.dentry->d_inode, 211 + dentry); 212 + else 213 + err = -EPERM; 214 + } else { 207 215 err = -ENOENT; 216 + } 208 217 dput(dentry); 209 218 } else { 210 219 err = PTR_ERR(dentry); 211 220 } 212 - mutex_unlock(&nd.path.dentry->d_inode->i_mutex); 213 221 222 + mutex_unlock(&nd.path.dentry->d_inode->i_mutex); 214 223 path_put(&nd.path); 215 224 return err; 216 225 } ··· 229 228 if (!path) 230 229 return -ENOMEM; 231 230 232 - while (1) { 231 + write_lock(&dirlock); 232 + for (;;) { 233 233 char *base; 234 234 235 235 base = strrchr(path, '/'); ··· 241 239 if (err) 242 240 break; 243 241 } 242 + write_unlock(&dirlock); 244 243 245 244 kfree(path); 246 245 return err; ··· 325 322 * If configured, or requested by the commandline, devtmpfs will be 326 323 * auto-mounted after the kernel mounted the root filesystem. 327 324 */ 328 - int devtmpfs_mount(const char *mountpoint) 325 + int devtmpfs_mount(const char *mntdir) 329 326 { 330 - struct path path; 331 327 int err; 332 328 333 329 if (!dev_mount) ··· 335 333 if (!dev_mnt) 336 334 return 0; 337 335 338 - err = kern_path(mountpoint, LOOKUP_FOLLOW, &path); 339 - if (err) 340 - return err; 341 - err = do_add_mount(dev_mnt, &path, 0, NULL); 336 + err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL); 342 337 if (err) 343 338 printk(KERN_INFO "devtmpfs: error mounting %i\n", err); 344 339 else 345 340 printk(KERN_INFO "devtmpfs: mounted\n"); 346 - path_put(&path); 347 341 return err; 348 342 } 349 343 ··· 352 354 int err; 353 355 struct vfsmount *mnt; 354 356 357 + rwlock_init(&dirlock); 358 + 355 359 err = register_filesystem(&dev_fs_type); 356 360 if (err) { 357 361 printk(KERN_ERR "devtmpfs: unable to register devtmpfs " ··· 361 361 return err; 362 362 } 363 363 364 - mnt = kern_mount(&dev_fs_type); 364 + mnt = kern_mount_data(&dev_fs_type, "mode=0755"); 365 365 if (IS_ERR(mnt)) { 366 366 err = PTR_ERR(mnt); 367 367 printk(KERN_ERR "devtmpfs: unable to create devtmpfs %i\n", err);
+6 -8
drivers/base/firmware_class.c
··· 601 601 } 602 602 ret = _request_firmware(&fw, fw_work->name, fw_work->device, 603 603 fw_work->uevent); 604 - if (ret < 0) 605 - fw_work->cont(NULL, fw_work->context); 606 - else { 607 - fw_work->cont(fw, fw_work->context); 608 - release_firmware(fw); 609 - } 604 + 605 + fw_work->cont(fw, fw_work->context); 606 + 610 607 module_put(fw_work->module); 611 608 kfree(fw_work); 612 609 return ret; ··· 616 619 * is non-zero else the firmware copy must be done manually. 617 620 * @name: name of firmware file 618 621 * @device: device for which firmware is being loaded 622 + * @gfp: allocation flags 619 623 * @context: will be passed over to @cont, and 620 624 * @fw may be %NULL if firmware request fails. 621 625 * @cont: function will be called asynchronously when the firmware ··· 629 631 int 630 632 request_firmware_nowait( 631 633 struct module *module, int uevent, 632 - const char *name, struct device *device, void *context, 634 + const char *name, struct device *device, gfp_t gfp, void *context, 633 635 void (*cont)(const struct firmware *fw, void *context)) 634 636 { 635 637 struct task_struct *task; 636 638 struct firmware_work *fw_work = kmalloc(sizeof (struct firmware_work), 637 - GFP_ATOMIC); 639 + gfp); 638 640 639 641 if (!fw_work) 640 642 return -ENOMEM;
+22 -7
drivers/base/platform.c
··· 1000 1000 int __init early_platform_driver_register(struct early_platform_driver *epdrv, 1001 1001 char *buf) 1002 1002 { 1003 - unsigned long index; 1003 + char *tmp; 1004 1004 int n; 1005 1005 1006 1006 /* Simply add the driver to the end of the global list. ··· 1019 1019 if (buf && !strncmp(buf, epdrv->pdrv->driver.name, n)) { 1020 1020 list_move(&epdrv->list, &early_platform_driver_list); 1021 1021 1022 - if (!strcmp(buf, epdrv->pdrv->driver.name)) 1022 + /* Allow passing parameters after device name */ 1023 + if (buf[n] == '\0' || buf[n] == ',') 1023 1024 epdrv->requested_id = -1; 1024 - else if (buf[n] == '.' && strict_strtoul(&buf[n + 1], 10, 1025 - &index) == 0) 1026 - epdrv->requested_id = index; 1027 - else 1028 - epdrv->requested_id = EARLY_PLATFORM_ID_ERROR; 1025 + else { 1026 + epdrv->requested_id = simple_strtoul(&buf[n + 1], 1027 + &tmp, 10); 1028 + 1029 + if (buf[n] != '.' || (tmp == &buf[n + 1])) { 1030 + epdrv->requested_id = EARLY_PLATFORM_ID_ERROR; 1031 + n = 0; 1032 + } else 1033 + n += strcspn(&buf[n + 1], ",") + 1; 1034 + } 1035 + 1036 + if (buf[n] == ',') 1037 + n++; 1038 + 1039 + if (epdrv->bufsize) { 1040 + memcpy(epdrv->buffer, &buf[n], 1041 + min_t(int, epdrv->bufsize, strlen(&buf[n]) + 1)); 1042 + epdrv->buffer[epdrv->bufsize - 1] = '\0'; 1043 + } 1029 1044 } 1030 1045 1031 1046 return 0;
+7 -2
drivers/firmware/dell_rbu.c
··· 544 544 { 545 545 rbu_data.entry_created = 0; 546 546 547 - if (!fw || !fw->size) 547 + if (!fw) 548 548 return; 549 + 550 + if (!fw->size) 551 + goto out; 549 552 550 553 spin_lock(&rbu_data.lock); 551 554 if (!strcmp(image_type, "mono")) { ··· 571 568 } else 572 569 pr_debug("invalid image type specified.\n"); 573 570 spin_unlock(&rbu_data.lock); 571 + out: 572 + release_firmware(fw); 574 573 } 575 574 576 575 static ssize_t read_rbu_image_type(struct kobject *kobj, ··· 620 615 spin_unlock(&rbu_data.lock); 621 616 req_firm_rc = request_firmware_nowait(THIS_MODULE, 622 617 FW_ACTION_NOHOTPLUG, "dell_rbu", 623 - &rbu_device->dev, &context, 618 + &rbu_device->dev, GFP_KERNEL, &context, 624 619 callbackfn_rbu); 625 620 if (req_firm_rc) { 626 621 printk(KERN_ERR
+12 -1
drivers/misc/hpilo.h
··· 44 44 45 45 struct pci_dev *ilo_dev; 46 46 47 + /* 48 + * open_lock serializes ccb_cnt during open and close 49 + * [ irq disabled ] 50 + * -> alloc_lock used when adding/removing/searching ccb_alloc, 51 + * which represents all ccbs open on the device 52 + * --> fifo_lock controls access to fifo queues shared with hw 53 + * 54 + * Locks must be taken in this order, but open_lock and alloc_lock 55 + * are optional, they do not need to be held in order to take a 56 + * lower level lock. 57 + */ 58 + spinlock_t open_lock; 47 59 spinlock_t alloc_lock; 48 60 spinlock_t fifo_lock; 49 - spinlock_t open_lock; 50 61 51 62 struct cdev cdev; 52 63 };
+5 -3
drivers/serial/ucc_uart.c
··· 1179 1179 1180 1180 if (firmware->header.length != fw->size) { 1181 1181 dev_err(dev, "invalid firmware\n"); 1182 - return; 1182 + goto out; 1183 1183 } 1184 1184 1185 1185 ret = qe_upload_firmware(firmware); 1186 1186 if (ret) { 1187 1187 dev_err(dev, "could not load firmware\n"); 1188 - return; 1188 + goto out; 1189 1189 } 1190 1190 1191 1191 firmware_loaded = 1; 1192 + out: 1193 + release_firmware(fw); 1192 1194 } 1193 1195 1194 1196 static int ucc_uart_probe(struct of_device *ofdev, ··· 1249 1247 */ 1250 1248 ret = request_firmware_nowait(THIS_MODULE, 1251 1249 FW_ACTION_HOTPLUG, filename, &ofdev->dev, 1252 - &ofdev->dev, uart_firmware_cont); 1250 + GFP_KERNEL, &ofdev->dev, uart_firmware_cont); 1253 1251 if (ret) { 1254 1252 dev_err(&ofdev->dev, 1255 1253 "could not load firmware %s\n",
+4 -1
drivers/staging/comedi/drivers/usbdux.c
··· 2327 2327 if (ret) { 2328 2328 dev_err(&usbdev->dev, 2329 2329 "Could not upload firmware (err=%d)\n", ret); 2330 - return; 2330 + goto out; 2331 2331 } 2332 2332 comedi_usb_auto_config(usbdev, BOARDNAME); 2333 + out: 2334 + release_firmware(fw); 2333 2335 } 2334 2336 2335 2337 /* allocate memory for the urbs and initialise them */ ··· 2582 2580 FW_ACTION_HOTPLUG, 2583 2581 "usbdux_firmware.bin", 2584 2582 &udev->dev, 2583 + GFP_KERNEL, 2585 2584 usbduxsub + index, 2586 2585 usbdux_firmware_request_complete_handler); 2587 2586
+4 -1
drivers/staging/comedi/drivers/usbduxfast.c
··· 1451 1451 if (ret) { 1452 1452 dev_err(&usbdev->dev, 1453 1453 "Could not upload firmware (err=%d)\n", ret); 1454 - return; 1454 + goto out; 1455 1455 } 1456 1456 1457 1457 comedi_usb_auto_config(usbdev, BOARDNAME); 1458 + out: 1459 + release_firmware(fw); 1458 1460 } 1459 1461 1460 1462 /* ··· 1571 1569 FW_ACTION_HOTPLUG, 1572 1570 "usbduxfast_firmware.bin", 1573 1571 &udev->dev, 1572 + GFP_KERNEL, 1574 1573 usbduxfastsub + index, 1575 1574 usbduxfast_firmware_request_complete_handler); 1576 1575
+4 -3
drivers/usb/atm/ueagle-atm.c
··· 667 667 else 668 668 uea_info(usb, "firmware uploaded\n"); 669 669 670 - uea_leaves(usb); 671 - return; 670 + goto err; 672 671 673 672 err_fw_corrupted: 674 673 uea_err(usb, "firmware is corrupted\n"); 675 674 err: 675 + release_firmware(fw_entry); 676 676 uea_leaves(usb); 677 677 } 678 678 ··· 705 705 break; 706 706 } 707 707 708 - ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev, usb, uea_upload_pre_firmware); 708 + ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev, 709 + GFP_KERNEL, usb, uea_upload_pre_firmware); 709 710 if (ret) 710 711 uea_err(usb, "firmware %s is not available\n", fw_name); 711 712 else
+32 -23
fs/debugfs/inode.c
··· 32 32 static int debugfs_mount_count; 33 33 static bool debugfs_registered; 34 34 35 - static struct inode *debugfs_get_inode(struct super_block *sb, int mode, dev_t dev) 35 + static struct inode *debugfs_get_inode(struct super_block *sb, int mode, dev_t dev, 36 + void *data, const struct file_operations *fops) 37 + 36 38 { 37 39 struct inode *inode = new_inode(sb); 38 40 ··· 46 44 init_special_inode(inode, mode, dev); 47 45 break; 48 46 case S_IFREG: 49 - inode->i_fop = &debugfs_file_operations; 47 + inode->i_fop = fops ? fops : &debugfs_file_operations; 48 + inode->i_private = data; 50 49 break; 51 50 case S_IFLNK: 52 51 inode->i_op = &debugfs_link_operations; 52 + inode->i_fop = fops; 53 + inode->i_private = data; 53 54 break; 54 55 case S_IFDIR: 55 56 inode->i_op = &simple_dir_inode_operations; 56 - inode->i_fop = &simple_dir_operations; 57 + inode->i_fop = fops ? fops : &simple_dir_operations; 58 + inode->i_private = data; 57 59 58 60 /* directory inodes start off with i_nlink == 2 59 61 * (for "." entry) */ ··· 70 64 71 65 /* SMP-safe */ 72 66 static int debugfs_mknod(struct inode *dir, struct dentry *dentry, 73 - int mode, dev_t dev) 67 + int mode, dev_t dev, void *data, 68 + const struct file_operations *fops) 74 69 { 75 70 struct inode *inode; 76 71 int error = -EPERM; ··· 79 72 if (dentry->d_inode) 80 73 return -EEXIST; 81 74 82 - inode = debugfs_get_inode(dir->i_sb, mode, dev); 75 + inode = debugfs_get_inode(dir->i_sb, mode, dev, data, fops); 83 76 if (inode) { 84 77 d_instantiate(dentry, inode); 85 78 dget(dentry); ··· 88 81 return error; 89 82 } 90 83 91 - static int debugfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) 84 + static int debugfs_mkdir(struct inode *dir, struct dentry *dentry, int mode, 85 + void *data, const struct file_operations *fops) 92 86 { 93 87 int res; 94 88 95 89 mode = (mode & (S_IRWXUGO | S_ISVTX)) | S_IFDIR; 96 - res = debugfs_mknod(dir, dentry, mode, 0); 90 + res = debugfs_mknod(dir, dentry, mode, 0, data, fops); 97 91 if (!res) { 98 92 inc_nlink(dir); 99 93 fsnotify_mkdir(dir, dentry); ··· 102 94 return res; 103 95 } 104 96 105 - static int debugfs_link(struct inode *dir, struct dentry *dentry, int mode) 97 + static int debugfs_link(struct inode *dir, struct dentry *dentry, int mode, 98 + void *data, const struct file_operations *fops) 106 99 { 107 100 mode = (mode & S_IALLUGO) | S_IFLNK; 108 - return debugfs_mknod(dir, dentry, mode, 0); 101 + return debugfs_mknod(dir, dentry, mode, 0, data, fops); 109 102 } 110 103 111 - static int debugfs_create(struct inode *dir, struct dentry *dentry, int mode) 104 + static int debugfs_create(struct inode *dir, struct dentry *dentry, int mode, 105 + void *data, const struct file_operations *fops) 112 106 { 113 107 int res; 114 108 115 109 mode = (mode & S_IALLUGO) | S_IFREG; 116 - res = debugfs_mknod(dir, dentry, mode, 0); 110 + res = debugfs_mknod(dir, dentry, mode, 0, data, fops); 117 111 if (!res) 118 112 fsnotify_create(dir, dentry); 119 113 return res; ··· 149 139 150 140 static int debugfs_create_by_name(const char *name, mode_t mode, 151 141 struct dentry *parent, 152 - struct dentry **dentry) 142 + struct dentry **dentry, 143 + void *data, 144 + const struct file_operations *fops) 153 145 { 154 146 int error = 0; 155 147 ··· 176 164 if (!IS_ERR(*dentry)) { 177 165 switch (mode & S_IFMT) { 178 166 case S_IFDIR: 179 - error = debugfs_mkdir(parent->d_inode, *dentry, mode); 167 + error = debugfs_mkdir(parent->d_inode, *dentry, mode, 168 + data, fops); 180 169 break; 181 170 case S_IFLNK: 182 - error = debugfs_link(parent->d_inode, *dentry, mode); 171 + error = debugfs_link(parent->d_inode, *dentry, mode, 172 + data, fops); 183 173 break; 184 174 default: 185 - error = debugfs_create(parent->d_inode, *dentry, mode); 175 + error = debugfs_create(parent->d_inode, *dentry, mode, 176 + data, fops); 186 177 break; 187 178 } 188 179 dput(*dentry); ··· 236 221 if (error) 237 222 goto exit; 238 223 239 - error = debugfs_create_by_name(name, mode, parent, &dentry); 224 + error = debugfs_create_by_name(name, mode, parent, &dentry, 225 + data, fops); 240 226 if (error) { 241 227 dentry = NULL; 242 228 simple_release_fs(&debugfs_mount, &debugfs_mount_count); 243 229 goto exit; 244 - } 245 - 246 - if (dentry->d_inode) { 247 - if (data) 248 - dentry->d_inode->i_private = data; 249 - if (fops) 250 - dentry->d_inode->i_fop = fops; 251 230 } 252 231 exit: 253 232 return dentry;
-22
fs/namei.c
··· 1279 1279 return __lookup_hash(&this, base, NULL); 1280 1280 } 1281 1281 1282 - /** 1283 - * lookup_one_noperm - bad hack for sysfs 1284 - * @name: pathname component to lookup 1285 - * @base: base directory to lookup from 1286 - * 1287 - * This is a variant of lookup_one_len that doesn't perform any permission 1288 - * checks. It's a horrible hack to work around the braindead sysfs 1289 - * architecture and should not be used anywhere else. 1290 - * 1291 - * DON'T USE THIS FUNCTION EVER, thanks. 1292 - */ 1293 - struct dentry *lookup_one_noperm(const char *name, struct dentry *base) 1294 - { 1295 - int err; 1296 - struct qstr this; 1297 - 1298 - err = __lookup_one_len(name, &this, base, strlen(name)); 1299 - if (err) 1300 - return ERR_PTR(err); 1301 - return __lookup_hash(&this, base, NULL); 1302 - } 1303 - 1304 1282 int user_path_at(int dfd, const char __user *name, unsigned flags, 1305 1283 struct path *path) 1306 1284 {
+125 -267
fs/sysfs/dir.c
··· 25 25 #include "sysfs.h" 26 26 27 27 DEFINE_MUTEX(sysfs_mutex); 28 - DEFINE_MUTEX(sysfs_rename_mutex); 29 28 DEFINE_SPINLOCK(sysfs_assoc_lock); 30 29 31 30 static DEFINE_SPINLOCK(sysfs_ino_lock); ··· 81 82 break; 82 83 } 83 84 } 84 - } 85 - 86 - /** 87 - * sysfs_get_dentry - get dentry for the given sysfs_dirent 88 - * @sd: sysfs_dirent of interest 89 - * 90 - * Get dentry for @sd. Dentry is looked up if currently not 91 - * present. This function descends from the root looking up 92 - * dentry for each step. 93 - * 94 - * LOCKING: 95 - * mutex_lock(sysfs_rename_mutex) 96 - * 97 - * RETURNS: 98 - * Pointer to found dentry on success, ERR_PTR() value on error. 99 - */ 100 - struct dentry *sysfs_get_dentry(struct sysfs_dirent *sd) 101 - { 102 - struct dentry *dentry = dget(sysfs_sb->s_root); 103 - 104 - while (dentry->d_fsdata != sd) { 105 - struct sysfs_dirent *cur; 106 - struct dentry *parent; 107 - 108 - /* find the first ancestor which hasn't been looked up */ 109 - cur = sd; 110 - while (cur->s_parent != dentry->d_fsdata) 111 - cur = cur->s_parent; 112 - 113 - /* look it up */ 114 - parent = dentry; 115 - mutex_lock(&parent->d_inode->i_mutex); 116 - dentry = lookup_one_noperm(cur->s_name, parent); 117 - mutex_unlock(&parent->d_inode->i_mutex); 118 - dput(parent); 119 - 120 - if (IS_ERR(dentry)) 121 - break; 122 - } 123 - return dentry; 124 85 } 125 86 126 87 /** ··· 257 298 goto repeat; 258 299 } 259 300 260 - static void sysfs_d_iput(struct dentry * dentry, struct inode * inode) 301 + static int sysfs_dentry_delete(struct dentry *dentry) 302 + { 303 + struct sysfs_dirent *sd = dentry->d_fsdata; 304 + return !!(sd->s_flags & SYSFS_FLAG_REMOVED); 305 + } 306 + 307 + static int sysfs_dentry_revalidate(struct dentry *dentry, struct nameidata *nd) 308 + { 309 + struct sysfs_dirent *sd = dentry->d_fsdata; 310 + int is_dir; 311 + 312 + mutex_lock(&sysfs_mutex); 313 + 314 + /* The sysfs dirent has been deleted */ 315 + if (sd->s_flags & SYSFS_FLAG_REMOVED) 316 + goto out_bad; 317 + 318 + /* The sysfs dirent has been moved? */ 319 + if (dentry->d_parent->d_fsdata != sd->s_parent) 320 + goto out_bad; 321 + 322 + /* The sysfs dirent has been renamed */ 323 + if (strcmp(dentry->d_name.name, sd->s_name) != 0) 324 + goto out_bad; 325 + 326 + mutex_unlock(&sysfs_mutex); 327 + out_valid: 328 + return 1; 329 + out_bad: 330 + /* Remove the dentry from the dcache hashes. 331 + * If this is a deleted dentry we use d_drop instead of d_delete 332 + * so sysfs doesn't need to cope with negative dentries. 333 + * 334 + * If this is a dentry that has simply been renamed we 335 + * use d_drop to remove it from the dcache lookup on its 336 + * old parent. If this dentry persists later when a lookup 337 + * is performed at its new name the dentry will be readded 338 + * to the dcache hashes. 339 + */ 340 + is_dir = (sysfs_type(sd) == SYSFS_DIR); 341 + mutex_unlock(&sysfs_mutex); 342 + if (is_dir) { 343 + /* If we have submounts we must allow the vfs caches 344 + * to lie about the state of the filesystem to prevent 345 + * leaks and other nasty things. 346 + */ 347 + if (have_submounts(dentry)) 348 + goto out_valid; 349 + shrink_dcache_parent(dentry); 350 + } 351 + d_drop(dentry); 352 + return 0; 353 + } 354 + 355 + static void sysfs_dentry_iput(struct dentry *dentry, struct inode *inode) 261 356 { 262 357 struct sysfs_dirent * sd = dentry->d_fsdata; 263 358 ··· 320 307 } 321 308 322 309 static const struct dentry_operations sysfs_dentry_ops = { 323 - .d_iput = sysfs_d_iput, 310 + .d_revalidate = sysfs_dentry_revalidate, 311 + .d_delete = sysfs_dentry_delete, 312 + .d_iput = sysfs_dentry_iput, 324 313 }; 325 314 326 315 struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type) ··· 359 344 return NULL; 360 345 } 361 346 362 - static int sysfs_ilookup_test(struct inode *inode, void *arg) 363 - { 364 - struct sysfs_dirent *sd = arg; 365 - return inode->i_ino == sd->s_ino; 366 - } 367 - 368 347 /** 369 348 * sysfs_addrm_start - prepare for sysfs_dirent add/remove 370 349 * @acxt: pointer to sysfs_addrm_cxt to be used ··· 366 357 * 367 358 * This function is called when the caller is about to add or 368 359 * remove sysfs_dirent under @parent_sd. This function acquires 369 - * sysfs_mutex, grabs inode for @parent_sd if available and lock 370 - * i_mutex of it. @acxt is used to keep and pass context to 360 + * sysfs_mutex. @acxt is used to keep and pass context to 371 361 * other addrm functions. 372 362 * 373 363 * LOCKING: 374 364 * Kernel thread context (may sleep). sysfs_mutex is locked on 375 - * return. i_mutex of parent inode is locked on return if 376 - * available. 365 + * return. 377 366 */ 378 367 void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt, 379 368 struct sysfs_dirent *parent_sd) 380 369 { 381 - struct inode *inode; 382 - 383 370 memset(acxt, 0, sizeof(*acxt)); 384 371 acxt->parent_sd = parent_sd; 385 372 386 - /* Lookup parent inode. inode initialization is protected by 387 - * sysfs_mutex, so inode existence can be determined by 388 - * looking up inode while holding sysfs_mutex. 389 - */ 390 373 mutex_lock(&sysfs_mutex); 391 - 392 - inode = ilookup5(sysfs_sb, parent_sd->s_ino, sysfs_ilookup_test, 393 - parent_sd); 394 - if (inode) { 395 - WARN_ON(inode->i_state & I_NEW); 396 - 397 - /* parent inode available */ 398 - acxt->parent_inode = inode; 399 - 400 - /* sysfs_mutex is below i_mutex in lock hierarchy. 401 - * First, trylock i_mutex. If fails, unlock 402 - * sysfs_mutex and lock them in order. 403 - */ 404 - if (!mutex_trylock(&inode->i_mutex)) { 405 - mutex_unlock(&sysfs_mutex); 406 - mutex_lock(&inode->i_mutex); 407 - mutex_lock(&sysfs_mutex); 408 - } 409 - } 410 374 } 411 375 412 376 /** ··· 404 422 */ 405 423 int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd) 406 424 { 425 + struct sysfs_inode_attrs *ps_iattr; 426 + 407 427 if (sysfs_find_dirent(acxt->parent_sd, sd->s_name)) 408 428 return -EEXIST; 409 429 410 430 sd->s_parent = sysfs_get(acxt->parent_sd); 411 431 412 - if (sysfs_type(sd) == SYSFS_DIR && acxt->parent_inode) 413 - inc_nlink(acxt->parent_inode); 414 - 415 - acxt->cnt++; 416 - 417 432 sysfs_link_sibling(sd); 433 + 434 + /* Update timestamps on the parent */ 435 + ps_iattr = acxt->parent_sd->s_iattr; 436 + if (ps_iattr) { 437 + struct iattr *ps_iattrs = &ps_iattr->ia_iattr; 438 + ps_iattrs->ia_ctime = ps_iattrs->ia_mtime = CURRENT_TIME; 439 + } 418 440 419 441 return 0; 420 442 } ··· 498 512 */ 499 513 void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd) 500 514 { 515 + struct sysfs_inode_attrs *ps_iattr; 516 + 501 517 BUG_ON(sd->s_flags & SYSFS_FLAG_REMOVED); 502 518 503 519 sysfs_unlink_sibling(sd); 504 520 521 + /* Update timestamps on the parent */ 522 + ps_iattr = acxt->parent_sd->s_iattr; 523 + if (ps_iattr) { 524 + struct iattr *ps_iattrs = &ps_iattr->ia_iattr; 525 + ps_iattrs->ia_ctime = ps_iattrs->ia_mtime = CURRENT_TIME; 526 + } 527 + 505 528 sd->s_flags |= SYSFS_FLAG_REMOVED; 506 529 sd->s_sibling = acxt->removed; 507 530 acxt->removed = sd; 508 - 509 - if (sysfs_type(sd) == SYSFS_DIR && acxt->parent_inode) 510 - drop_nlink(acxt->parent_inode); 511 - 512 - acxt->cnt++; 513 - } 514 - 515 - /** 516 - * sysfs_drop_dentry - drop dentry for the specified sysfs_dirent 517 - * @sd: target sysfs_dirent 518 - * 519 - * Drop dentry for @sd. @sd must have been unlinked from its 520 - * parent on entry to this function such that it can't be looked 521 - * up anymore. 522 - */ 523 - static void sysfs_drop_dentry(struct sysfs_dirent *sd) 524 - { 525 - struct inode *inode; 526 - struct dentry *dentry; 527 - 528 - inode = ilookup(sysfs_sb, sd->s_ino); 529 - if (!inode) 530 - return; 531 - 532 - /* Drop any existing dentries associated with sd. 533 - * 534 - * For the dentry to be properly freed we need to grab a 535 - * reference to the dentry under the dcache lock, unhash it, 536 - * and then put it. The playing with the dentry count allows 537 - * dput to immediately free the dentry if it is not in use. 538 - */ 539 - repeat: 540 - spin_lock(&dcache_lock); 541 - list_for_each_entry(dentry, &inode->i_dentry, d_alias) { 542 - if (d_unhashed(dentry)) 543 - continue; 544 - dget_locked(dentry); 545 - spin_lock(&dentry->d_lock); 546 - __d_drop(dentry); 547 - spin_unlock(&dentry->d_lock); 548 - spin_unlock(&dcache_lock); 549 - dput(dentry); 550 - goto repeat; 551 - } 552 - spin_unlock(&dcache_lock); 553 - 554 - /* adjust nlink and update timestamp */ 555 - mutex_lock(&inode->i_mutex); 556 - 557 - inode->i_ctime = CURRENT_TIME; 558 - drop_nlink(inode); 559 - if (sysfs_type(sd) == SYSFS_DIR) 560 - drop_nlink(inode); 561 - 562 - mutex_unlock(&inode->i_mutex); 563 - 564 - iput(inode); 565 531 } 566 532 567 533 /** ··· 522 584 * 523 585 * Finish up sysfs_dirent add/remove. Resources acquired by 524 586 * sysfs_addrm_start() are released and removed sysfs_dirents are 525 - * cleaned up. Timestamps on the parent inode are updated. 587 + * cleaned up. 526 588 * 527 589 * LOCKING: 528 - * All mutexes acquired by sysfs_addrm_start() are released. 590 + * sysfs_mutex is released. 529 591 */ 530 592 void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt) 531 593 { 532 594 /* release resources acquired by sysfs_addrm_start() */ 533 595 mutex_unlock(&sysfs_mutex); 534 - if (acxt->parent_inode) { 535 - struct inode *inode = acxt->parent_inode; 536 - 537 - /* if added/removed, update timestamps on the parent */ 538 - if (acxt->cnt) 539 - inode->i_ctime = inode->i_mtime = CURRENT_TIME; 540 - 541 - mutex_unlock(&inode->i_mutex); 542 - iput(inode); 543 - } 544 596 545 597 /* kill removed sysfs_dirents */ 546 598 while (acxt->removed) { ··· 539 611 acxt->removed = sd->s_sibling; 540 612 sd->s_sibling = NULL; 541 613 542 - sysfs_drop_dentry(sd); 543 614 sysfs_deactivate(sd); 544 615 unmap_bin_file(sd); 545 616 sysfs_put(sd); ··· 678 751 } 679 752 680 753 /* instantiate and hash dentry */ 681 - dentry->d_op = &sysfs_dentry_ops; 682 - dentry->d_fsdata = sysfs_get(sd); 683 - d_instantiate(dentry, inode); 684 - d_rehash(dentry); 754 + ret = d_find_alias(inode); 755 + if (!ret) { 756 + dentry->d_op = &sysfs_dentry_ops; 757 + dentry->d_fsdata = sysfs_get(sd); 758 + d_add(dentry, inode); 759 + } else { 760 + d_move(ret, dentry); 761 + iput(inode); 762 + } 685 763 686 764 out_unlock: 687 765 mutex_unlock(&sysfs_mutex); ··· 695 763 696 764 const struct inode_operations sysfs_dir_inode_operations = { 697 765 .lookup = sysfs_lookup, 766 + .permission = sysfs_permission, 698 767 .setattr = sysfs_setattr, 768 + .getattr = sysfs_getattr, 699 769 .setxattr = sysfs_setxattr, 700 770 }; 701 771 ··· 760 826 __sysfs_remove_dir(sd); 761 827 } 762 828 763 - int sysfs_rename_dir(struct kobject * kobj, const char *new_name) 829 + int sysfs_rename(struct sysfs_dirent *sd, 830 + struct sysfs_dirent *new_parent_sd, const char *new_name) 764 831 { 765 - struct sysfs_dirent *sd = kobj->sd; 766 - struct dentry *parent = NULL; 767 - struct dentry *old_dentry = NULL, *new_dentry = NULL; 768 832 const char *dup_name = NULL; 769 833 int error; 770 834 771 - mutex_lock(&sysfs_rename_mutex); 772 - 773 - error = 0; 774 - if (strcmp(sd->s_name, new_name) == 0) 775 - goto out; /* nothing to rename */ 776 - 777 - /* get the original dentry */ 778 - old_dentry = sysfs_get_dentry(sd); 779 - if (IS_ERR(old_dentry)) { 780 - error = PTR_ERR(old_dentry); 781 - old_dentry = NULL; 782 - goto out; 783 - } 784 - 785 - parent = old_dentry->d_parent; 786 - 787 - /* lock parent and get dentry for new name */ 788 - mutex_lock(&parent->d_inode->i_mutex); 789 835 mutex_lock(&sysfs_mutex); 790 836 791 - error = -EEXIST; 792 - if (sysfs_find_dirent(sd->s_parent, new_name)) 793 - goto out_unlock; 837 + error = 0; 838 + if ((sd->s_parent == new_parent_sd) && 839 + (strcmp(sd->s_name, new_name) == 0)) 840 + goto out; /* nothing to rename */ 794 841 795 - error = -ENOMEM; 796 - new_dentry = d_alloc_name(parent, new_name); 797 - if (!new_dentry) 798 - goto out_unlock; 842 + error = -EEXIST; 843 + if (sysfs_find_dirent(new_parent_sd, new_name)) 844 + goto out; 799 845 800 846 /* rename sysfs_dirent */ 801 - error = -ENOMEM; 802 - new_name = dup_name = kstrdup(new_name, GFP_KERNEL); 803 - if (!new_name) 804 - goto out_unlock; 847 + if (strcmp(sd->s_name, new_name) != 0) { 848 + error = -ENOMEM; 849 + new_name = dup_name = kstrdup(new_name, GFP_KERNEL); 850 + if (!new_name) 851 + goto out; 805 852 806 - dup_name = sd->s_name; 807 - sd->s_name = new_name; 853 + dup_name = sd->s_name; 854 + sd->s_name = new_name; 855 + } 808 856 809 - /* rename */ 810 - d_add(new_dentry, NULL); 811 - d_move(old_dentry, new_dentry); 857 + /* Remove from old parent's list and insert into new parent's list. */ 858 + if (sd->s_parent != new_parent_sd) { 859 + sysfs_unlink_sibling(sd); 860 + sysfs_get(new_parent_sd); 861 + sysfs_put(sd->s_parent); 862 + sd->s_parent = new_parent_sd; 863 + sysfs_link_sibling(sd); 864 + } 812 865 813 866 error = 0; 814 - out_unlock: 815 - mutex_unlock(&sysfs_mutex); 816 - mutex_unlock(&parent->d_inode->i_mutex); 817 - kfree(dup_name); 818 - dput(old_dentry); 819 - dput(new_dentry); 820 867 out: 821 - mutex_unlock(&sysfs_rename_mutex); 868 + mutex_unlock(&sysfs_mutex); 869 + kfree(dup_name); 822 870 return error; 871 + } 872 + 873 + int sysfs_rename_dir(struct kobject *kobj, const char *new_name) 874 + { 875 + return sysfs_rename(kobj->sd, kobj->sd->s_parent, new_name); 823 876 } 824 877 825 878 int sysfs_move_dir(struct kobject *kobj, struct kobject *new_parent_kobj) 826 879 { 827 880 struct sysfs_dirent *sd = kobj->sd; 828 881 struct sysfs_dirent *new_parent_sd; 829 - struct dentry *old_parent, *new_parent = NULL; 830 - struct dentry *old_dentry = NULL, *new_dentry = NULL; 831 - int error; 832 882 833 - mutex_lock(&sysfs_rename_mutex); 834 883 BUG_ON(!sd->s_parent); 835 - new_parent_sd = (new_parent_kobj && new_parent_kobj->sd) ? 884 + new_parent_sd = new_parent_kobj && new_parent_kobj->sd ? 836 885 new_parent_kobj->sd : &sysfs_root; 837 886 838 - error = 0; 839 - if (sd->s_parent == new_parent_sd) 840 - goto out; /* nothing to move */ 841 - 842 - /* get dentries */ 843 - old_dentry = sysfs_get_dentry(sd); 844 - if (IS_ERR(old_dentry)) { 845 - error = PTR_ERR(old_dentry); 846 - old_dentry = NULL; 847 - goto out; 848 - } 849 - old_parent = old_dentry->d_parent; 850 - 851 - new_parent = sysfs_get_dentry(new_parent_sd); 852 - if (IS_ERR(new_parent)) { 853 - error = PTR_ERR(new_parent); 854 - new_parent = NULL; 855 - goto out; 856 - } 857 - 858 - again: 859 - mutex_lock(&old_parent->d_inode->i_mutex); 860 - if (!mutex_trylock(&new_parent->d_inode->i_mutex)) { 861 - mutex_unlock(&old_parent->d_inode->i_mutex); 862 - goto again; 863 - } 864 - mutex_lock(&sysfs_mutex); 865 - 866 - error = -EEXIST; 867 - if (sysfs_find_dirent(new_parent_sd, sd->s_name)) 868 - goto out_unlock; 869 - 870 - error = -ENOMEM; 871 - new_dentry = d_alloc_name(new_parent, sd->s_name); 872 - if (!new_dentry) 873 - goto out_unlock; 874 - 875 - error = 0; 876 - d_add(new_dentry, NULL); 877 - d_move(old_dentry, new_dentry); 878 - 879 - /* Remove from old parent's list and insert into new parent's list. */ 880 - sysfs_unlink_sibling(sd); 881 - sysfs_get(new_parent_sd); 882 - drop_nlink(old_parent->d_inode); 883 - sysfs_put(sd->s_parent); 884 - sd->s_parent = new_parent_sd; 885 - inc_nlink(new_parent->d_inode); 886 - sysfs_link_sibling(sd); 887 - 888 - out_unlock: 889 - mutex_unlock(&sysfs_mutex); 890 - mutex_unlock(&new_parent->d_inode->i_mutex); 891 - mutex_unlock(&old_parent->d_inode->i_mutex); 892 - out: 893 - dput(new_parent); 894 - dput(old_dentry); 895 - dput(new_dentry); 896 - mutex_unlock(&sysfs_rename_mutex); 897 - return error; 887 + return sysfs_rename(sd, new_parent_sd, sd->s_name); 898 888 } 899 889 900 890 /* Relationship between s_mode and the DT_xxx types */
+9 -32
fs/sysfs/file.c
··· 579 579 */ 580 580 int sysfs_chmod_file(struct kobject *kobj, struct attribute *attr, mode_t mode) 581 581 { 582 - struct sysfs_dirent *victim_sd = NULL; 583 - struct dentry *victim = NULL; 584 - struct inode * inode; 582 + struct sysfs_dirent *sd; 585 583 struct iattr newattrs; 586 584 int rc; 587 585 586 + mutex_lock(&sysfs_mutex); 587 + 588 588 rc = -ENOENT; 589 - victim_sd = sysfs_get_dirent(kobj->sd, attr->name); 590 - if (!victim_sd) 589 + sd = sysfs_find_dirent(kobj->sd, attr->name); 590 + if (!sd) 591 591 goto out; 592 592 593 - mutex_lock(&sysfs_rename_mutex); 594 - victim = sysfs_get_dentry(victim_sd); 595 - mutex_unlock(&sysfs_rename_mutex); 596 - if (IS_ERR(victim)) { 597 - rc = PTR_ERR(victim); 598 - victim = NULL; 599 - goto out; 600 - } 593 + newattrs.ia_mode = (mode & S_IALLUGO) | (sd->s_mode & ~S_IALLUGO); 594 + newattrs.ia_valid = ATTR_MODE; 595 + rc = sysfs_sd_setattr(sd, &newattrs); 601 596 602 - inode = victim->d_inode; 603 - 604 - mutex_lock(&inode->i_mutex); 605 - 606 - newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO); 607 - newattrs.ia_valid = ATTR_MODE | ATTR_CTIME; 608 - newattrs.ia_ctime = current_fs_time(inode->i_sb); 609 - rc = sysfs_setattr(victim, &newattrs); 610 - 611 - if (rc == 0) { 612 - fsnotify_change(victim, newattrs.ia_valid); 613 - mutex_lock(&sysfs_mutex); 614 - victim_sd->s_mode = newattrs.ia_mode; 615 - mutex_unlock(&sysfs_mutex); 616 - } 617 - 618 - mutex_unlock(&inode->i_mutex); 619 597 out: 620 - dput(victim); 621 - sysfs_put(victim_sd); 598 + mutex_unlock(&sysfs_mutex); 622 599 return rc; 623 600 } 624 601 EXPORT_SYMBOL_GPL(sysfs_chmod_file);
+108 -68
fs/sysfs/inode.c
··· 37 37 }; 38 38 39 39 static const struct inode_operations sysfs_inode_operations ={ 40 + .permission = sysfs_permission, 40 41 .setattr = sysfs_setattr, 42 + .getattr = sysfs_getattr, 41 43 .setxattr = sysfs_setxattr, 42 44 }; 43 45 ··· 48 46 return bdi_init(&sysfs_backing_dev_info); 49 47 } 50 48 51 - struct sysfs_inode_attrs *sysfs_init_inode_attrs(struct sysfs_dirent *sd) 49 + static struct sysfs_inode_attrs *sysfs_init_inode_attrs(struct sysfs_dirent *sd) 52 50 { 53 51 struct sysfs_inode_attrs *attrs; 54 52 struct iattr *iattrs; ··· 66 64 67 65 return attrs; 68 66 } 69 - int sysfs_setattr(struct dentry * dentry, struct iattr * iattr) 67 + 68 + int sysfs_sd_setattr(struct sysfs_dirent *sd, struct iattr * iattr) 70 69 { 71 - struct inode * inode = dentry->d_inode; 72 - struct sysfs_dirent * sd = dentry->d_fsdata; 73 70 struct sysfs_inode_attrs *sd_attrs; 74 71 struct iattr *iattrs; 75 72 unsigned int ia_valid = iattr->ia_valid; 76 - int error; 77 - 78 - if (!sd) 79 - return -EINVAL; 80 73 81 74 sd_attrs = sd->s_iattr; 82 - 83 - error = inode_change_ok(inode, iattr); 84 - if (error) 85 - return error; 86 - 87 - iattr->ia_valid &= ~ATTR_SIZE; /* ignore size changes */ 88 - 89 - error = inode_setattr(inode, iattr); 90 - if (error) 91 - return error; 92 75 93 76 if (!sd_attrs) { 94 77 /* setting attributes for the first time, allocate now */ ··· 90 103 if (ia_valid & ATTR_GID) 91 104 iattrs->ia_gid = iattr->ia_gid; 92 105 if (ia_valid & ATTR_ATIME) 93 - iattrs->ia_atime = timespec_trunc(iattr->ia_atime, 94 - inode->i_sb->s_time_gran); 106 + iattrs->ia_atime = iattr->ia_atime; 95 107 if (ia_valid & ATTR_MTIME) 96 - iattrs->ia_mtime = timespec_trunc(iattr->ia_mtime, 97 - inode->i_sb->s_time_gran); 108 + iattrs->ia_mtime = iattr->ia_mtime; 98 109 if (ia_valid & ATTR_CTIME) 99 - iattrs->ia_ctime = timespec_trunc(iattr->ia_ctime, 100 - inode->i_sb->s_time_gran); 110 + iattrs->ia_ctime = iattr->ia_ctime; 101 111 if (ia_valid & ATTR_MODE) { 102 112 umode_t mode = iattr->ia_mode; 103 - 104 - if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID)) 105 - mode &= ~S_ISGID; 106 113 iattrs->ia_mode = sd->s_mode = mode; 107 114 } 108 115 } 116 + return 0; 117 + } 118 + 119 + int sysfs_setattr(struct dentry *dentry, struct iattr *iattr) 120 + { 121 + struct inode *inode = dentry->d_inode; 122 + struct sysfs_dirent *sd = dentry->d_fsdata; 123 + int error; 124 + 125 + if (!sd) 126 + return -EINVAL; 127 + 128 + error = inode_change_ok(inode, iattr); 129 + if (error) 130 + return error; 131 + 132 + iattr->ia_valid &= ~ATTR_SIZE; /* ignore size changes */ 133 + 134 + error = inode_setattr(inode, iattr); 135 + if (error) 136 + return error; 137 + 138 + mutex_lock(&sysfs_mutex); 139 + error = sysfs_sd_setattr(sd, iattr); 140 + mutex_unlock(&sysfs_mutex); 141 + 109 142 return error; 143 + } 144 + 145 + static int sysfs_sd_setsecdata(struct sysfs_dirent *sd, void **secdata, u32 *secdata_len) 146 + { 147 + struct sysfs_inode_attrs *iattrs; 148 + void *old_secdata; 149 + size_t old_secdata_len; 150 + 151 + iattrs = sd->s_iattr; 152 + if (!iattrs) 153 + iattrs = sysfs_init_inode_attrs(sd); 154 + if (!iattrs) 155 + return -ENOMEM; 156 + 157 + old_secdata = iattrs->ia_secdata; 158 + old_secdata_len = iattrs->ia_secdata_len; 159 + 160 + iattrs->ia_secdata = *secdata; 161 + iattrs->ia_secdata_len = *secdata_len; 162 + 163 + *secdata = old_secdata; 164 + *secdata_len = old_secdata_len; 165 + return 0; 110 166 } 111 167 112 168 int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value, 113 169 size_t size, int flags) 114 170 { 115 171 struct sysfs_dirent *sd = dentry->d_fsdata; 116 - struct sysfs_inode_attrs *iattrs; 117 172 void *secdata; 118 173 int error; 119 174 u32 secdata_len = 0; 120 175 121 176 if (!sd) 122 177 return -EINVAL; 123 - if (!sd->s_iattr) 124 - sd->s_iattr = sysfs_init_inode_attrs(sd); 125 - if (!sd->s_iattr) 126 - return -ENOMEM; 127 - 128 - iattrs = sd->s_iattr; 129 178 130 179 if (!strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN)) { 131 180 const char *suffix = name + XATTR_SECURITY_PREFIX_LEN; ··· 173 150 &secdata, &secdata_len); 174 151 if (error) 175 152 goto out; 176 - if (iattrs->ia_secdata) 177 - security_release_secctx(iattrs->ia_secdata, 178 - iattrs->ia_secdata_len); 179 - iattrs->ia_secdata = secdata; 180 - iattrs->ia_secdata_len = secdata_len; 181 153 154 + mutex_lock(&sysfs_mutex); 155 + error = sysfs_sd_setsecdata(sd, &secdata, &secdata_len); 156 + mutex_unlock(&sysfs_mutex); 157 + 158 + if (secdata) 159 + security_release_secctx(secdata, secdata_len); 182 160 } else 183 161 return -EINVAL; 184 162 out: ··· 194 170 195 171 static inline void set_inode_attr(struct inode * inode, struct iattr * iattr) 196 172 { 197 - inode->i_mode = iattr->ia_mode; 198 173 inode->i_uid = iattr->ia_uid; 199 174 inode->i_gid = iattr->ia_gid; 200 175 inode->i_atime = iattr->ia_atime; 201 176 inode->i_mtime = iattr->ia_mtime; 202 177 inode->i_ctime = iattr->ia_ctime; 203 178 } 204 - 205 - 206 - /* 207 - * sysfs has a different i_mutex lock order behavior for i_mutex than other 208 - * filesystems; sysfs i_mutex is called in many places with subsystem locks 209 - * held. At the same time, many of the VFS locking rules do not apply to 210 - * sysfs at all (cross directory rename for example). To untangle this mess 211 - * (which gives false positives in lockdep), we're giving sysfs inodes their 212 - * own class for i_mutex. 213 - */ 214 - static struct lock_class_key sysfs_inode_imutex_key; 215 179 216 180 static int sysfs_count_nlink(struct sysfs_dirent *sd) 217 181 { ··· 213 201 return nr + 2; 214 202 } 215 203 204 + static void sysfs_refresh_inode(struct sysfs_dirent *sd, struct inode *inode) 205 + { 206 + struct sysfs_inode_attrs *iattrs = sd->s_iattr; 207 + 208 + inode->i_mode = sd->s_mode; 209 + if (iattrs) { 210 + /* sysfs_dirent has non-default attributes 211 + * get them from persistent copy in sysfs_dirent 212 + */ 213 + set_inode_attr(inode, &iattrs->ia_iattr); 214 + security_inode_notifysecctx(inode, 215 + iattrs->ia_secdata, 216 + iattrs->ia_secdata_len); 217 + } 218 + 219 + if (sysfs_type(sd) == SYSFS_DIR) 220 + inode->i_nlink = sysfs_count_nlink(sd); 221 + } 222 + 223 + int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) 224 + { 225 + struct sysfs_dirent *sd = dentry->d_fsdata; 226 + struct inode *inode = dentry->d_inode; 227 + 228 + mutex_lock(&sysfs_mutex); 229 + sysfs_refresh_inode(sd, inode); 230 + mutex_unlock(&sysfs_mutex); 231 + 232 + generic_fillattr(inode, stat); 233 + return 0; 234 + } 235 + 216 236 static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode) 217 237 { 218 238 struct bin_attribute *bin_attr; 219 - struct sysfs_inode_attrs *iattrs; 220 239 221 240 inode->i_private = sysfs_get(sd); 222 241 inode->i_mapping->a_ops = &sysfs_aops; 223 242 inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info; 224 243 inode->i_op = &sysfs_inode_operations; 225 - inode->i_ino = sd->s_ino; 226 - lockdep_set_class(&inode->i_mutex, &sysfs_inode_imutex_key); 227 244 228 - iattrs = sd->s_iattr; 229 - if (iattrs) { 230 - /* sysfs_dirent has non-default attributes 231 - * get them for the new inode from persistent copy 232 - * in sysfs_dirent 233 - */ 234 - set_inode_attr(inode, &iattrs->ia_iattr); 235 - if (iattrs->ia_secdata) 236 - security_inode_notifysecctx(inode, 237 - iattrs->ia_secdata, 238 - iattrs->ia_secdata_len); 239 - } else 240 - set_default_inode_attr(inode, sd->s_mode); 245 + set_default_inode_attr(inode, sd->s_mode); 246 + sysfs_refresh_inode(sd, inode); 241 247 242 248 /* initialize inode according to type */ 243 249 switch (sysfs_type(sd)) { 244 250 case SYSFS_DIR: 245 251 inode->i_op = &sysfs_dir_inode_operations; 246 252 inode->i_fop = &sysfs_dir_operations; 247 - inode->i_nlink = sysfs_count_nlink(sd); 248 253 break; 249 254 case SYSFS_KOBJ_ATTR: 250 255 inode->i_size = PAGE_SIZE; ··· 343 314 return 0; 344 315 else 345 316 return -ENOENT; 317 + } 318 + 319 + int sysfs_permission(struct inode *inode, int mask) 320 + { 321 + struct sysfs_dirent *sd = inode->i_private; 322 + 323 + mutex_lock(&sysfs_mutex); 324 + sysfs_refresh_inode(sd, inode); 325 + mutex_unlock(&sysfs_mutex); 326 + 327 + return generic_permission(inode, mask, NULL); 346 328 }
+7 -4
fs/sysfs/symlink.c
··· 210 210 } 211 211 212 212 const struct inode_operations sysfs_symlink_inode_operations = { 213 - .setxattr = sysfs_setxattr, 214 - .readlink = generic_readlink, 215 - .follow_link = sysfs_follow_link, 216 - .put_link = sysfs_put_link, 213 + .setxattr = sysfs_setxattr, 214 + .readlink = generic_readlink, 215 + .follow_link = sysfs_follow_link, 216 + .put_link = sysfs_put_link, 217 + .setattr = sysfs_setattr, 218 + .getattr = sysfs_getattr, 219 + .permission = sysfs_permission, 217 220 }; 218 221 219 222
+6 -3
fs/sysfs/sysfs.h
··· 89 89 */ 90 90 struct sysfs_addrm_cxt { 91 91 struct sysfs_dirent *parent_sd; 92 - struct inode *parent_inode; 93 92 struct sysfs_dirent *removed; 94 - int cnt; 95 93 }; 96 94 97 95 /* ··· 103 105 * dir.c 104 106 */ 105 107 extern struct mutex sysfs_mutex; 106 - extern struct mutex sysfs_rename_mutex; 107 108 extern spinlock_t sysfs_assoc_lock; 108 109 109 110 extern const struct file_operations sysfs_dir_operations; ··· 130 133 struct sysfs_dirent **p_sd); 131 134 void sysfs_remove_subdir(struct sysfs_dirent *sd); 132 135 136 + int sysfs_rename(struct sysfs_dirent *sd, 137 + struct sysfs_dirent *new_parent_sd, const char *new_name); 138 + 133 139 static inline struct sysfs_dirent *__sysfs_get(struct sysfs_dirent *sd) 134 140 { 135 141 if (sd) { ··· 155 155 */ 156 156 struct inode *sysfs_get_inode(struct sysfs_dirent *sd); 157 157 void sysfs_delete_inode(struct inode *inode); 158 + int sysfs_sd_setattr(struct sysfs_dirent *sd, struct iattr *iattr); 159 + int sysfs_permission(struct inode *inode, int mask); 158 160 int sysfs_setattr(struct dentry *dentry, struct iattr *iattr); 161 + int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat); 159 162 int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value, 160 163 size_t size, int flags); 161 164 int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name);
+1 -1
include/linux/device.h
··· 558 558 #ifdef CONFIG_DEVTMPFS 559 559 extern int devtmpfs_create_node(struct device *dev); 560 560 extern int devtmpfs_delete_node(struct device *dev); 561 - extern int devtmpfs_mount(const char *mountpoint); 561 + extern int devtmpfs_mount(const char *mntdir); 562 562 #else 563 563 static inline int devtmpfs_create_node(struct device *dev) { return 0; } 564 564 static inline int devtmpfs_delete_node(struct device *dev) { return 0; }
+3 -2
include/linux/firmware.h
··· 4 4 #include <linux/module.h> 5 5 #include <linux/types.h> 6 6 #include <linux/compiler.h> 7 + #include <linux/gfp.h> 7 8 8 9 #define FW_ACTION_NOHOTPLUG 0 9 10 #define FW_ACTION_HOTPLUG 1 ··· 39 38 struct device *device); 40 39 int request_firmware_nowait( 41 40 struct module *module, int uevent, 42 - const char *name, struct device *device, void *context, 41 + const char *name, struct device *device, gfp_t gfp, void *context, 43 42 void (*cont)(const struct firmware *fw, void *context)); 44 43 45 44 void release_firmware(const struct firmware *fw); ··· 52 51 } 53 52 static inline int request_firmware_nowait( 54 53 struct module *module, int uevent, 55 - const char *name, struct device *device, void *context, 54 + const char *name, struct device *device, gfp_t gfp, void *context, 56 55 void (*cont)(const struct firmware *fw, void *context)) 57 56 { 58 57 return -EINVAL;
-1
include/linux/namei.h
··· 76 76 extern void release_open_intent(struct nameidata *); 77 77 78 78 extern struct dentry *lookup_one_len(const char *, struct dentry *, int); 79 - extern struct dentry *lookup_one_noperm(const char *, struct dentry *); 80 79 81 80 extern int follow_down(struct path *); 82 81 extern int follow_up(struct path *);
+15 -5
include/linux/platform_device.h
··· 83 83 struct platform_driver *pdrv; 84 84 struct list_head list; 85 85 int requested_id; 86 + char *buffer; 87 + int bufsize; 86 88 }; 87 89 88 90 #define EARLY_PLATFORM_ID_UNSET -2 ··· 104 102 int nr_probe, int user_only); 105 103 extern void early_platform_cleanup(void); 106 104 105 + #define early_platform_init(class_string, platdrv) \ 106 + early_platform_init_buffer(class_string, platdrv, NULL, 0) 107 107 108 108 #ifndef MODULE 109 - #define early_platform_init(class_string, platform_driver) \ 109 + #define early_platform_init_buffer(class_string, platdrv, buf, bufsiz) \ 110 110 static __initdata struct early_platform_driver early_driver = { \ 111 111 .class_str = class_string, \ 112 - .pdrv = platform_driver, \ 112 + .buffer = buf, \ 113 + .bufsize = bufsiz, \ 114 + .pdrv = platdrv, \ 113 115 .requested_id = EARLY_PLATFORM_ID_UNSET, \ 114 116 }; \ 115 - static int __init early_platform_driver_setup_func(char *buf) \ 117 + static int __init early_platform_driver_setup_func(char *buffer) \ 116 118 { \ 117 - return early_platform_driver_register(&early_driver, buf); \ 119 + return early_platform_driver_register(&early_driver, buffer); \ 118 120 } \ 119 121 early_param(class_string, early_platform_driver_setup_func) 120 122 #else /* MODULE */ 121 - #define early_platform_init(class_string, platform_driver) 123 + #define early_platform_init_buffer(class_string, platdrv, buf, bufsiz) \ 124 + static inline char *early_platform_driver_setup_func(void) \ 125 + { \ 126 + return bufsiz ? buf : NULL; \ 127 + } 122 128 #endif /* MODULE */ 123 129 124 130 #endif /* _PLATFORM_DEVICE_H_ */