aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-04-29 14:31:50 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-04-29 14:31:50 -0400
commit2794b5d408c625e104de813d3de7ac0ec34d46d9 (patch)
treea99e067475ed4e1de27c86a544347be97e7458fb /fs
parent4f567cbc957a7cffd1a428a000d93bd903f42349 (diff)
parent0d1d392f011b284bb4af0411b2d36e5d04e0f058 (diff)
Merge tag 'driver-core-3.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core
Pull driver core update from Greg Kroah-Hartman: "Here's the merge request for the driver core tree for 3.10-rc1 It's pretty small, just a number of driver core and sysfs updates and fixes, all of which have been in linux-next for a while now. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>" Fixed conflict in kernel/rtmutex-tester.c, the locking tree had a better fix for the same sysfs file mode problem. * tag 'driver-core-3.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: PM / Runtime: Idle devices asynchronously after probe|release driver core: handle user namespaces properly with the uid/gid devtmpfs change driver core: devtmpfs: fix compile failure with CONFIG_UIDGID_STRICT_TYPE_CHECKS devtmpfs: add base.h include driver core: add uid and gid to devtmpfs sysfs: check if one entry has been removed before freeing sysfs: fix crash_notes_size build warning sysfs: fix use after free in case of concurrent read/write and readdir rtmutex-tester: fix mode of sysfs files Documentation: Add ABI entry for crash_notes and crash_notes_size sysfs: Add crash_notes_size to export percpu note size driver core: platform_device.h: fix checkpatch errors and warnings driver core: platform.c: fix checkpatch errors and warnings driver core: warn that platform_driver_probe can not use deferred probing sysfs: use atomic_inc_unless_negative in sysfs_get_active base: core: WARN() about bogus permissions on device attributes device: separate all subsys mutexes
Diffstat (limited to 'fs')
-rw-r--r--fs/sysfs/dir.c41
1 files changed, 21 insertions, 20 deletions
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index e14512678c9b..e8e0e71b29d5 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -165,21 +165,8 @@ struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd)
165 if (unlikely(!sd)) 165 if (unlikely(!sd))
166 return NULL; 166 return NULL;
167 167
168 while (1) { 168 if (!atomic_inc_unless_negative(&sd->s_active))
169 int v, t; 169 return NULL;
170
171 v = atomic_read(&sd->s_active);
172 if (unlikely(v < 0))
173 return NULL;
174
175 t = atomic_cmpxchg(&sd->s_active, v, v + 1);
176 if (likely(t == v))
177 break;
178 if (t < 0)
179 return NULL;
180
181 cpu_relax();
182 }
183 170
184 if (likely(!ignore_lockdep(sd))) 171 if (likely(!ignore_lockdep(sd)))
185 rwsem_acquire_read(&sd->dep_map, 0, 1, _RET_IP_); 172 rwsem_acquire_read(&sd->dep_map, 0, 1, _RET_IP_);
@@ -281,6 +268,10 @@ void release_sysfs_dirent(struct sysfs_dirent * sd)
281 */ 268 */
282 parent_sd = sd->s_parent; 269 parent_sd = sd->s_parent;
283 270
271 WARN(!(sd->s_flags & SYSFS_FLAG_REMOVED),
272 "sysfs: free using entry: %s/%s\n",
273 parent_sd ? parent_sd->s_name : "", sd->s_name);
274
284 if (sysfs_type(sd) == SYSFS_KOBJ_LINK) 275 if (sysfs_type(sd) == SYSFS_KOBJ_LINK)
285 sysfs_put(sd->s_symlink.target_sd); 276 sysfs_put(sd->s_symlink.target_sd);
286 if (sysfs_type(sd) & SYSFS_COPY_NAME) 277 if (sysfs_type(sd) & SYSFS_COPY_NAME)
@@ -399,7 +390,7 @@ struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type)
399 390
400 sd->s_name = name; 391 sd->s_name = name;
401 sd->s_mode = mode; 392 sd->s_mode = mode;
402 sd->s_flags = type; 393 sd->s_flags = type | SYSFS_FLAG_REMOVED;
403 394
404 return sd; 395 return sd;
405 396
@@ -479,6 +470,9 @@ int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
479 ps_iattrs->ia_ctime = ps_iattrs->ia_mtime = CURRENT_TIME; 470 ps_iattrs->ia_ctime = ps_iattrs->ia_mtime = CURRENT_TIME;
480 } 471 }
481 472
473 /* Mark the entry added into directory tree */
474 sd->s_flags &= ~SYSFS_FLAG_REMOVED;
475
482 return 0; 476 return 0;
483} 477}
484 478
@@ -1012,6 +1006,7 @@ static int sysfs_readdir(struct file * filp, void * dirent, filldir_t filldir)
1012 enum kobj_ns_type type; 1006 enum kobj_ns_type type;
1013 const void *ns; 1007 const void *ns;
1014 ino_t ino; 1008 ino_t ino;
1009 loff_t off;
1015 1010
1016 type = sysfs_ns_type(parent_sd); 1011 type = sysfs_ns_type(parent_sd);
1017 ns = sysfs_info(dentry->d_sb)->ns[type]; 1012 ns = sysfs_info(dentry->d_sb)->ns[type];
@@ -1034,6 +1029,7 @@ static int sysfs_readdir(struct file * filp, void * dirent, filldir_t filldir)
1034 return 0; 1029 return 0;
1035 } 1030 }
1036 mutex_lock(&sysfs_mutex); 1031 mutex_lock(&sysfs_mutex);
1032 off = filp->f_pos;
1037 for (pos = sysfs_dir_pos(ns, parent_sd, filp->f_pos, pos); 1033 for (pos = sysfs_dir_pos(ns, parent_sd, filp->f_pos, pos);
1038 pos; 1034 pos;
1039 pos = sysfs_dir_next_pos(ns, parent_sd, filp->f_pos, pos)) { 1035 pos = sysfs_dir_next_pos(ns, parent_sd, filp->f_pos, pos)) {
@@ -1045,19 +1041,24 @@ static int sysfs_readdir(struct file * filp, void * dirent, filldir_t filldir)
1045 len = strlen(name); 1041 len = strlen(name);
1046 ino = pos->s_ino; 1042 ino = pos->s_ino;
1047 type = dt_type(pos); 1043 type = dt_type(pos);
1048 filp->f_pos = pos->s_hash; 1044 off = filp->f_pos = pos->s_hash;
1049 filp->private_data = sysfs_get(pos); 1045 filp->private_data = sysfs_get(pos);
1050 1046
1051 mutex_unlock(&sysfs_mutex); 1047 mutex_unlock(&sysfs_mutex);
1052 ret = filldir(dirent, name, len, filp->f_pos, ino, type); 1048 ret = filldir(dirent, name, len, off, ino, type);
1053 mutex_lock(&sysfs_mutex); 1049 mutex_lock(&sysfs_mutex);
1054 if (ret < 0) 1050 if (ret < 0)
1055 break; 1051 break;
1056 } 1052 }
1057 mutex_unlock(&sysfs_mutex); 1053 mutex_unlock(&sysfs_mutex);
1058 if ((filp->f_pos > 1) && !pos) { /* EOF */ 1054
1059 filp->f_pos = INT_MAX; 1055 /* don't reference last entry if its refcount is dropped */
1056 if (!pos) {
1060 filp->private_data = NULL; 1057 filp->private_data = NULL;
1058
1059 /* EOF and not changed as 0 or 1 in read/write path */
1060 if (off == filp->f_pos && off > 1)
1061 filp->f_pos = INT_MAX;
1061 } 1062 }
1062 return 0; 1063 return 0;
1063} 1064}