From f76142a8eef546c8e4623fb6930472466ea2458d Mon Sep 17 00:00:00 2001 From: Ming Lei Date: Tue, 2 Apr 2013 10:12:26 +0800 Subject: [PATCH] --- yaml --- r: 363247 b: refs/heads/master c: f7db5e7660b122142410dcf36ba903c73d473250 h: refs/heads/master i: 363245: ec19cb9094b778632d354592ed79a3992ad3d4fc 363243: 4f4e81d1e7a21dc4c01c39b02e48e3e860102dc9 363239: 0e2a2de8f12b472e4e484cc39b2a2ca284938040 363231: 818bae2780a6a3d12a4b434f1637ef807d84f294 v: v3 --- [refs] | 2 +- trunk/fs/sysfs/dir.c | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/[refs] b/[refs] index fe548da7b82a..3b9b734c1544 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 0f8b1a0204a12441cddbbf5be31e6338e0b8da1c +refs/heads/master: f7db5e7660b122142410dcf36ba903c73d473250 diff --git a/trunk/fs/sysfs/dir.c b/trunk/fs/sysfs/dir.c index c6f54abe9852..1bf016b5e88f 100644 --- a/trunk/fs/sysfs/dir.c +++ b/trunk/fs/sysfs/dir.c @@ -999,6 +999,7 @@ static int sysfs_readdir(struct file * filp, void * dirent, filldir_t filldir) enum kobj_ns_type type; const void *ns; ino_t ino; + loff_t off; type = sysfs_ns_type(parent_sd); ns = sysfs_info(dentry->d_sb)->ns[type]; @@ -1021,6 +1022,7 @@ static int sysfs_readdir(struct file * filp, void * dirent, filldir_t filldir) return 0; } mutex_lock(&sysfs_mutex); + off = filp->f_pos; for (pos = sysfs_dir_pos(ns, parent_sd, filp->f_pos, pos); pos; pos = sysfs_dir_next_pos(ns, parent_sd, filp->f_pos, pos)) { @@ -1032,19 +1034,24 @@ static int sysfs_readdir(struct file * filp, void * dirent, filldir_t filldir) len = strlen(name); ino = pos->s_ino; type = dt_type(pos); - filp->f_pos = pos->s_hash; + off = filp->f_pos = pos->s_hash; filp->private_data = sysfs_get(pos); mutex_unlock(&sysfs_mutex); - ret = filldir(dirent, name, len, filp->f_pos, ino, type); + ret = filldir(dirent, name, len, off, ino, type); mutex_lock(&sysfs_mutex); if (ret < 0) break; } mutex_unlock(&sysfs_mutex); - if ((filp->f_pos > 1) && !pos) { /* EOF */ - filp->f_pos = INT_MAX; + + /* don't reference last entry if its refcount is dropped */ + if (!pos) { filp->private_data = NULL; + + /* EOF and not changed as 0 or 1 in read/write path */ + if (off == filp->f_pos && off > 1) + filp->f_pos = INT_MAX; } return 0; }