aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-10-16 15:40:26 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-10-16 15:40:26 -0400
commitc813b4e16ead3c3df98ac84419d4df2adf33fe01 (patch)
tree2ca4a5b6966d833b6149e3dda7a4e85d1255779c /fs
parentc8d8a2321f9c4ee18fbcc399fdc2a77e580a03b9 (diff)
parent02683ffdf655b4ae15245376ba6fea6d9e5829a6 (diff)
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: (46 commits) UIO: Fix mapping of logical and virtual memory UIO: add automata sercos3 pci card support UIO: Change driver name of uio_pdrv UIO: Add alignment warnings for uio-mem Driver core: add bus_sort_breadthfirst() function NET: convert the phy_device file to use bus_find_device_by_name kobject: Cleanup kobject_rename and !CONFIG_SYSFS kobject: Fix kobject_rename and !CONFIG_SYSFS sysfs: Make dir and name args to sysfs_notify() const platform: add new device registration helper sysfs: use ilookup5() instead of ilookup5_nowait() PNP: create device attributes via default device attributes Driver core: make bus_find_device_by_name() more robust usb: turn dev_warn+WARN_ON combos into dev_WARN debug: use dev_WARN() rather than WARN_ON() in device_pm_add() debug: Introduce a dev_WARN() function sysfs: fix deadlock device model: Do a quickcheck for driver binding before doing an expensive check Driver core: Fix cleanup in device_create_vargs(). Driver core: Clarify device cleanup. ...
Diffstat (limited to 'fs')
-rw-r--r--fs/coda/psdev.c5
-rw-r--r--fs/sysfs/bin.c42
-rw-r--r--fs/sysfs/dir.c24
-rw-r--r--fs/sysfs/file.c46
-rw-r--r--fs/sysfs/mount.c15
-rw-r--r--fs/sysfs/sysfs.h6
6 files changed, 94 insertions, 44 deletions
diff --git a/fs/coda/psdev.c b/fs/coda/psdev.c
index 0d9b80ec689c..cfd29da714d1 100644
--- a/fs/coda/psdev.c
+++ b/fs/coda/psdev.c
@@ -362,9 +362,8 @@ static int init_coda_psdev(void)
362 goto out_chrdev; 362 goto out_chrdev;
363 } 363 }
364 for (i = 0; i < MAX_CODADEVS; i++) 364 for (i = 0; i < MAX_CODADEVS; i++)
365 device_create_drvdata(coda_psdev_class, NULL, 365 device_create(coda_psdev_class, NULL,
366 MKDEV(CODA_PSDEV_MAJOR, i), 366 MKDEV(CODA_PSDEV_MAJOR, i), NULL, "cfs%d", i);
367 NULL, "cfs%d", i);
368 coda_sysctl_init(); 367 coda_sysctl_init();
369 goto out; 368 goto out;
370 369
diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
index 006fc64227dd..66f6e58a7e4b 100644
--- a/fs/sysfs/bin.c
+++ b/fs/sysfs/bin.c
@@ -61,6 +61,7 @@ read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off)
61 int size = dentry->d_inode->i_size; 61 int size = dentry->d_inode->i_size;
62 loff_t offs = *off; 62 loff_t offs = *off;
63 int count = min_t(size_t, bytes, PAGE_SIZE); 63 int count = min_t(size_t, bytes, PAGE_SIZE);
64 char *temp;
64 65
65 if (size) { 66 if (size) {
66 if (offs > size) 67 if (offs > size)
@@ -69,23 +70,33 @@ read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off)
69 count = size - offs; 70 count = size - offs;
70 } 71 }
71 72
73 temp = kmalloc(count, GFP_KERNEL);
74 if (!temp)
75 return -ENOMEM;
76
72 mutex_lock(&bb->mutex); 77 mutex_lock(&bb->mutex);
73 78
74 count = fill_read(dentry, bb->buffer, offs, count); 79 count = fill_read(dentry, bb->buffer, offs, count);
75 if (count < 0) 80 if (count < 0) {
76 goto out_unlock; 81 mutex_unlock(&bb->mutex);
82 goto out_free;
83 }
77 84
78 if (copy_to_user(userbuf, bb->buffer, count)) { 85 memcpy(temp, bb->buffer, count);
86
87 mutex_unlock(&bb->mutex);
88
89 if (copy_to_user(userbuf, temp, count)) {
79 count = -EFAULT; 90 count = -EFAULT;
80 goto out_unlock; 91 goto out_free;
81 } 92 }
82 93
83 pr_debug("offs = %lld, *off = %lld, count = %d\n", offs, *off, count); 94 pr_debug("offs = %lld, *off = %lld, count = %d\n", offs, *off, count);
84 95
85 *off = offs + count; 96 *off = offs + count;
86 97
87 out_unlock: 98 out_free:
88 mutex_unlock(&bb->mutex); 99 kfree(temp);
89 return count; 100 return count;
90} 101}
91 102
@@ -118,6 +129,7 @@ static ssize_t write(struct file *file, const char __user *userbuf,
118 int size = dentry->d_inode->i_size; 129 int size = dentry->d_inode->i_size;
119 loff_t offs = *off; 130 loff_t offs = *off;
120 int count = min_t(size_t, bytes, PAGE_SIZE); 131 int count = min_t(size_t, bytes, PAGE_SIZE);
132 char *temp;
121 133
122 if (size) { 134 if (size) {
123 if (offs > size) 135 if (offs > size)
@@ -126,19 +138,27 @@ static ssize_t write(struct file *file, const char __user *userbuf,
126 count = size - offs; 138 count = size - offs;
127 } 139 }
128 140
129 mutex_lock(&bb->mutex); 141 temp = kmalloc(count, GFP_KERNEL);
142 if (!temp)
143 return -ENOMEM;
130 144
131 if (copy_from_user(bb->buffer, userbuf, count)) { 145 if (copy_from_user(temp, userbuf, count)) {
132 count = -EFAULT; 146 count = -EFAULT;
133 goto out_unlock; 147 goto out_free;
134 } 148 }
135 149
150 mutex_lock(&bb->mutex);
151
152 memcpy(bb->buffer, temp, count);
153
136 count = flush_write(dentry, bb->buffer, offs, count); 154 count = flush_write(dentry, bb->buffer, offs, count);
155 mutex_unlock(&bb->mutex);
156
137 if (count > 0) 157 if (count > 0)
138 *off = offs + count; 158 *off = offs + count;
139 159
140 out_unlock: 160out_free:
141 mutex_unlock(&bb->mutex); 161 kfree(temp);
142 return count; 162 return count;
143} 163}
144 164
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index aedaeba82ae5..3a05a596e3b4 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -370,17 +370,17 @@ void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt,
370 memset(acxt, 0, sizeof(*acxt)); 370 memset(acxt, 0, sizeof(*acxt));
371 acxt->parent_sd = parent_sd; 371 acxt->parent_sd = parent_sd;
372 372
373 /* Lookup parent inode. inode initialization and I_NEW 373 /* Lookup parent inode. inode initialization is protected by
374 * clearing are protected by sysfs_mutex. By grabbing it and 374 * sysfs_mutex, so inode existence can be determined by
375 * looking up with _nowait variant, inode state can be 375 * looking up inode while holding sysfs_mutex.
376 * determined reliably.
377 */ 376 */
378 mutex_lock(&sysfs_mutex); 377 mutex_lock(&sysfs_mutex);
379 378
380 inode = ilookup5_nowait(sysfs_sb, parent_sd->s_ino, sysfs_ilookup_test, 379 inode = ilookup5(sysfs_sb, parent_sd->s_ino, sysfs_ilookup_test,
381 parent_sd); 380 parent_sd);
381 if (inode) {
382 WARN_ON(inode->i_state & I_NEW);
382 383
383 if (inode && !(inode->i_state & I_NEW)) {
384 /* parent inode available */ 384 /* parent inode available */
385 acxt->parent_inode = inode; 385 acxt->parent_inode = inode;
386 386
@@ -393,8 +393,7 @@ void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt,
393 mutex_lock(&inode->i_mutex); 393 mutex_lock(&inode->i_mutex);
394 mutex_lock(&sysfs_mutex); 394 mutex_lock(&sysfs_mutex);
395 } 395 }
396 } else 396 }
397 iput(inode);
398} 397}
399 398
400/** 399/**
@@ -636,6 +635,7 @@ struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
636 635
637 return sd; 636 return sd;
638} 637}
638EXPORT_SYMBOL_GPL(sysfs_get_dirent);
639 639
640static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd, 640static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
641 const char *name, struct sysfs_dirent **p_sd) 641 const char *name, struct sysfs_dirent **p_sd)
@@ -829,16 +829,12 @@ int sysfs_rename_dir(struct kobject * kobj, const char *new_name)
829 if (!new_dentry) 829 if (!new_dentry)
830 goto out_unlock; 830 goto out_unlock;
831 831
832 /* rename kobject and sysfs_dirent */ 832 /* rename sysfs_dirent */
833 error = -ENOMEM; 833 error = -ENOMEM;
834 new_name = dup_name = kstrdup(new_name, GFP_KERNEL); 834 new_name = dup_name = kstrdup(new_name, GFP_KERNEL);
835 if (!new_name) 835 if (!new_name)
836 goto out_unlock; 836 goto out_unlock;
837 837
838 error = kobject_set_name(kobj, "%s", new_name);
839 if (error)
840 goto out_unlock;
841
842 dup_name = sd->s_name; 838 dup_name = sd->s_name;
843 sd->s_name = new_name; 839 sd->s_name = new_name;
844 840
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index c9e4e5091da1..1f4a3f877262 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -19,10 +19,18 @@
19#include <linux/poll.h> 19#include <linux/poll.h>
20#include <linux/list.h> 20#include <linux/list.h>
21#include <linux/mutex.h> 21#include <linux/mutex.h>
22#include <linux/limits.h>
22#include <asm/uaccess.h> 23#include <asm/uaccess.h>
23 24
24#include "sysfs.h" 25#include "sysfs.h"
25 26
27/* used in crash dumps to help with debugging */
28static char last_sysfs_file[PATH_MAX];
29void sysfs_printk_last_file(void)
30{
31 printk(KERN_EMERG "last sysfs file: %s\n", last_sysfs_file);
32}
33
26/* 34/*
27 * There's one sysfs_buffer for each open file and one 35 * There's one sysfs_buffer for each open file and one
28 * sysfs_open_dirent for each sysfs_dirent with one or more open 36 * sysfs_open_dirent for each sysfs_dirent with one or more open
@@ -328,6 +336,11 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
328 struct sysfs_buffer *buffer; 336 struct sysfs_buffer *buffer;
329 struct sysfs_ops *ops; 337 struct sysfs_ops *ops;
330 int error = -EACCES; 338 int error = -EACCES;
339 char *p;
340
341 p = d_path(&file->f_path, last_sysfs_file, sizeof(last_sysfs_file));
342 if (p)
343 memmove(last_sysfs_file, p, strlen(p) + 1);
331 344
332 /* need attr_sd for attr and ops, its parent for kobj */ 345 /* need attr_sd for attr and ops, its parent for kobj */
333 if (!sysfs_get_active_two(attr_sd)) 346 if (!sysfs_get_active_two(attr_sd))
@@ -440,7 +453,23 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
440 return POLLERR|POLLPRI; 453 return POLLERR|POLLPRI;
441} 454}
442 455
443void sysfs_notify(struct kobject *k, char *dir, char *attr) 456void sysfs_notify_dirent(struct sysfs_dirent *sd)
457{
458 struct sysfs_open_dirent *od;
459
460 spin_lock(&sysfs_open_dirent_lock);
461
462 od = sd->s_attr.open;
463 if (od) {
464 atomic_inc(&od->event);
465 wake_up_interruptible(&od->poll);
466 }
467
468 spin_unlock(&sysfs_open_dirent_lock);
469}
470EXPORT_SYMBOL_GPL(sysfs_notify_dirent);
471
472void sysfs_notify(struct kobject *k, const char *dir, const char *attr)
444{ 473{
445 struct sysfs_dirent *sd = k->sd; 474 struct sysfs_dirent *sd = k->sd;
446 475
@@ -450,19 +479,8 @@ void sysfs_notify(struct kobject *k, char *dir, char *attr)
450 sd = sysfs_find_dirent(sd, dir); 479 sd = sysfs_find_dirent(sd, dir);
451 if (sd && attr) 480 if (sd && attr)
452 sd = sysfs_find_dirent(sd, attr); 481 sd = sysfs_find_dirent(sd, attr);
453 if (sd) { 482 if (sd)
454 struct sysfs_open_dirent *od; 483 sysfs_notify_dirent(sd);
455
456 spin_lock(&sysfs_open_dirent_lock);
457
458 od = sd->s_attr.open;
459 if (od) {
460 atomic_inc(&od->event);
461 wake_up_interruptible(&od->poll);
462 }
463
464 spin_unlock(&sysfs_open_dirent_lock);
465 }
466 484
467 mutex_unlock(&sysfs_mutex); 485 mutex_unlock(&sysfs_mutex);
468} 486}
diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c
index 14f0023984d7..ab343e371d64 100644
--- a/fs/sysfs/mount.c
+++ b/fs/sysfs/mount.c
@@ -16,6 +16,7 @@
16#include <linux/mount.h> 16#include <linux/mount.h>
17#include <linux/pagemap.h> 17#include <linux/pagemap.h>
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/module.h>
19 20
20#include "sysfs.h" 21#include "sysfs.h"
21 22
@@ -115,3 +116,17 @@ out_err:
115 sysfs_dir_cachep = NULL; 116 sysfs_dir_cachep = NULL;
116 goto out; 117 goto out;
117} 118}
119
120#undef sysfs_get
121struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd)
122{
123 return __sysfs_get(sd);
124}
125EXPORT_SYMBOL_GPL(sysfs_get);
126
127#undef sysfs_put
128void sysfs_put(struct sysfs_dirent *sd)
129{
130 __sysfs_put(sd);
131}
132EXPORT_SYMBOL_GPL(sysfs_put);
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
index a5db496f71c7..93c6d6b27c4d 100644
--- a/fs/sysfs/sysfs.h
+++ b/fs/sysfs/sysfs.h
@@ -124,7 +124,7 @@ int sysfs_create_subdir(struct kobject *kobj, const char *name,
124 struct sysfs_dirent **p_sd); 124 struct sysfs_dirent **p_sd);
125void sysfs_remove_subdir(struct sysfs_dirent *sd); 125void sysfs_remove_subdir(struct sysfs_dirent *sd);
126 126
127static inline struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd) 127static inline struct sysfs_dirent *__sysfs_get(struct sysfs_dirent *sd)
128{ 128{
129 if (sd) { 129 if (sd) {
130 WARN_ON(!atomic_read(&sd->s_count)); 130 WARN_ON(!atomic_read(&sd->s_count));
@@ -132,12 +132,14 @@ static inline struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd)
132 } 132 }
133 return sd; 133 return sd;
134} 134}
135#define sysfs_get(sd) __sysfs_get(sd)
135 136
136static inline void sysfs_put(struct sysfs_dirent *sd) 137static inline void __sysfs_put(struct sysfs_dirent *sd)
137{ 138{
138 if (sd && atomic_dec_and_test(&sd->s_count)) 139 if (sd && atomic_dec_and_test(&sd->s_count))
139 release_sysfs_dirent(sd); 140 release_sysfs_dirent(sd);
140} 141}
142#define sysfs_put(sd) __sysfs_put(sd)
141 143
142/* 144/*
143 * inode.c 145 * inode.c