Skip to content

Commit a2db684

Browse files
ebiedermgregkh
authored andcommitted
sysfs: Only take active references on attributes.
If we exclude directories and symlinks from the set of sysfs dirents where we need active references we are left with sysfs attributes (binary or not). - Tweak sysfs_deactivate to only do something on attributes - Move lockdep initialization into sysfs_file_add_mode to limit it to just attributes. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Acked-by: WANG Cong <xiyou.wangcong@gmail.com> Cc: Tejun Heo <tj@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent e72ceb8 commit a2db684

3 files changed

Lines changed: 6 additions & 1 deletion

File tree

‎fs/sysfs/dir.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ static void sysfs_deactivate(struct sysfs_dirent *sd)
156156
int v;
157157

158158
BUG_ON(sd->s_sibling || !(sd->s_flags & SYSFS_FLAG_REMOVED));
159+
160+
if (!(sysfs_type(sd) & SYSFS_ACTIVE_REF))
161+
return;
162+
159163
sd->s_sibling = (void *)&wait;
160164

161165
rwsem_acquire(&sd->dep_map, 0, 0, _RET_IP_);
@@ -315,7 +319,6 @@ struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type)
315319

316320
atomic_set(&sd->s_count, 1);
317321
atomic_set(&sd->s_active, 0);
318-
sysfs_dirent_init_lockdep(sd);
319322

320323
sd->s_name = name;
321324
sd->s_mode = mode;

‎fs/sysfs/file.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ int sysfs_add_file_mode(struct sysfs_dirent *dir_sd,
509509
if (!sd)
510510
return -ENOMEM;
511511
sd->s_attr.attr = (void *)attr;
512+
sysfs_dirent_init_lockdep(sd);
512513

513514
sysfs_addrm_start(&acxt, dir_sd);
514515
rc = sysfs_add_one(&acxt, sd);

‎fs/sysfs/sysfs.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ struct sysfs_dirent {
7979
#define SYSFS_KOBJ_BIN_ATTR 0x0004
8080
#define SYSFS_KOBJ_LINK 0x0008
8181
#define SYSFS_COPY_NAME (SYSFS_DIR | SYSFS_KOBJ_LINK)
82+
#define SYSFS_ACTIVE_REF (SYSFS_KOBJ_ATTR | SYSFS_KOBJ_BIN_ATTR)
8283

8384
#define SYSFS_FLAG_MASK ~SYSFS_TYPE_MASK
8485
#define SYSFS_FLAG_REMOVED 0x0200

0 commit comments

Comments
 (0)