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

Commit b4c98f62 authored by Joel Becker's avatar Joel Becker Committed by Mark Fasheh
Browse files

configfs: Prevent duplicate subsystem names.



For all child objects, creation comes through mkdir(2), so duplicate names
are prevented.

Subsystems, though, are registered by client drivers at init_module()/__init
time.  This patch prevents duplicate subsystem names.

Signed-off-by: default avatarJoel Becker <joel.becker@oracle.com>
Signed-off-by: default avatarMark Fasheh <mark.fasheh@oracle.com>
parent e478bec0
Loading
Loading
Loading
Loading
+30 −2
Original line number Original line Diff line number Diff line
@@ -86,6 +86,32 @@ static struct configfs_dirent *configfs_new_dirent(struct configfs_dirent * pare
	return sd;
	return sd;
}
}


/*
 *
 * Return -EEXIST if there is already a configfs element with the same
 * name for the same parent.
 *
 * called with parent inode's i_mutex held
 */
int configfs_dirent_exists(struct configfs_dirent *parent_sd,
			   const unsigned char *new)
{
	struct configfs_dirent * sd;

	list_for_each_entry(sd, &parent_sd->s_children, s_sibling) {
		if (sd->s_element) {
			const unsigned char *existing = configfs_get_name(sd);
			if (strcmp(existing, new))
				continue;
			else
				return -EEXIST;
		}
	}

	return 0;
}


int configfs_make_dirent(struct configfs_dirent * parent_sd,
int configfs_make_dirent(struct configfs_dirent * parent_sd,
			 struct dentry * dentry, void * element,
			 struct dentry * dentry, void * element,
			 umode_t mode, int type)
			 umode_t mode, int type)
@@ -136,6 +162,8 @@ static int create_dir(struct config_item * k, struct dentry * p,
	int error;
	int error;
	umode_t mode = S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO;
	umode_t mode = S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO;


	error = configfs_dirent_exists(p->d_fsdata, d->d_name.name);
	if (!error)
		error = configfs_make_dirent(p->d_fsdata, d, k, mode,
		error = configfs_make_dirent(p->d_fsdata, d, k, mode,
					     CONFIGFS_DIR);
					     CONFIGFS_DIR);
	if (!error) {
	if (!error) {