Skip to content

Commit

Permalink
sysfs: separate out dup filename warning into a separate function
Browse files Browse the repository at this point in the history
Separate out sysfs_warn_dup() out of sysfs_add_one().  This will help
separating out the core sysfs functionalities into kernfs so that it
can be used by non-sysfs users too.

This doesn't make any functional changes.

Signed-off-by: Tejun Heo <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
htejun authored and gregkh committed Oct 29, 2013
1 parent 7eed6ec commit d1c1459
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
30 changes: 19 additions & 11 deletions fs/sysfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,23 @@ static char *sysfs_pathname(struct sysfs_dirent *sd, char *path)
return path;
}

void sysfs_warn_dup(struct sysfs_dirent *parent, const char *name)
{
char *path;

path = kzalloc(PATH_MAX, GFP_KERNEL);
if (path) {
sysfs_pathname(parent, path);
strlcat(path, "/", PATH_MAX);
strlcat(path, name, PATH_MAX);
}

WARN(1, KERN_WARNING "sysfs: cannot create duplicate filename '%s'\n",
path ? path : name);

kfree(path);
}

/**
* sysfs_add_one - add sysfs_dirent to parent
* @acxt: addrm context to use
Expand Down Expand Up @@ -497,18 +514,9 @@ int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
int ret;

ret = __sysfs_add_one(acxt, sd, parent_sd);
if (ret == -EEXIST) {
char *path = kzalloc(PATH_MAX, GFP_KERNEL);
WARN(1, KERN_WARNING
"sysfs: cannot create duplicate filename '%s'\n",
(path == NULL) ? sd->s_name
: (sysfs_pathname(parent_sd, path),
strlcat(path, "/", PATH_MAX),
strlcat(path, sd->s_name, PATH_MAX),
path));
kfree(path);
}

if (ret == -EEXIST)
sysfs_warn_dup(parent_sd, sd->s_name);
return ret;
}

Expand Down
1 change: 1 addition & 0 deletions fs/sysfs/sysfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ extern const struct inode_operations sysfs_dir_inode_operations;
struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd);
void sysfs_put_active(struct sysfs_dirent *sd);
void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt);
void sysfs_warn_dup(struct sysfs_dirent *parent, const char *name);
int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
struct sysfs_dirent *parent_sd);
int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
Expand Down

0 comments on commit d1c1459

Please sign in to comment.