Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a2db6842 authored by Eric W. Biederman's avatar Eric W. Biederman Committed by Greg Kroah-Hartman
Browse files

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: default avatarEric W. Biederman <ebiederm@xmission.com>
Acked-by: default avatarWANG Cong <xiyou.wangcong@gmail.com>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent e72ceb8c
Loading
Loading
Loading
Loading
+4 −1
Original line number Original line Diff line number Diff line
@@ -156,6 +156,10 @@ static void sysfs_deactivate(struct sysfs_dirent *sd)
	int v;
	int v;


	BUG_ON(sd->s_sibling || !(sd->s_flags & SYSFS_FLAG_REMOVED));
	BUG_ON(sd->s_sibling || !(sd->s_flags & SYSFS_FLAG_REMOVED));

	if (!(sysfs_type(sd) & SYSFS_ACTIVE_REF))
		return;

	sd->s_sibling = (void *)&wait;
	sd->s_sibling = (void *)&wait;


	rwsem_acquire(&sd->dep_map, 0, 0, _RET_IP_);
	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)


	atomic_set(&sd->s_count, 1);
	atomic_set(&sd->s_count, 1);
	atomic_set(&sd->s_active, 0);
	atomic_set(&sd->s_active, 0);
	sysfs_dirent_init_lockdep(sd);


	sd->s_name = name;
	sd->s_name = name;
	sd->s_mode = mode;
	sd->s_mode = mode;
+1 −0
Original line number Original line Diff line number Diff line
@@ -509,6 +509,7 @@ int sysfs_add_file_mode(struct sysfs_dirent *dir_sd,
	if (!sd)
	if (!sd)
		return -ENOMEM;
		return -ENOMEM;
	sd->s_attr.attr = (void *)attr;
	sd->s_attr.attr = (void *)attr;
	sysfs_dirent_init_lockdep(sd);


	sysfs_addrm_start(&acxt, dir_sd);
	sysfs_addrm_start(&acxt, dir_sd);
	rc = sysfs_add_one(&acxt, sd);
	rc = sysfs_add_one(&acxt, sd);
+1 −0
Original line number Original line Diff line number Diff line
@@ -79,6 +79,7 @@ struct sysfs_dirent {
#define SYSFS_KOBJ_BIN_ATTR		0x0004
#define SYSFS_KOBJ_BIN_ATTR		0x0004
#define SYSFS_KOBJ_LINK			0x0008
#define SYSFS_KOBJ_LINK			0x0008
#define SYSFS_COPY_NAME			(SYSFS_DIR | SYSFS_KOBJ_LINK)
#define SYSFS_COPY_NAME			(SYSFS_DIR | SYSFS_KOBJ_LINK)
#define SYSFS_ACTIVE_REF		(SYSFS_KOBJ_ATTR | SYSFS_KOBJ_BIN_ATTR)


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