struct sysfs_dirent *parent_sd = NULL;
struct sysfs_dirent *target_sd = NULL;
struct sysfs_dirent *sd = NULL;
+ struct sysfs_addrm_cxt acxt;
int error;
BUG_ON(!name);
sd = sysfs_new_dirent(name, S_IFLNK|S_IRWXUGO, SYSFS_KOBJ_LINK);
if (!sd)
goto out_put;
+
sd->s_elem.symlink.target_sd = target_sd;
+ target_sd = NULL; /* reference is now owned by the symlink */
- mutex_lock(&sysfs_mutex);
- error = -EEXIST;
- if (sysfs_find_dirent(parent_sd, name))
- goto out_unlock;
- sysfs_attach_dirent(sd, parent_sd, NULL);
- mutex_unlock(&sysfs_mutex);
+ sysfs_addrm_start(&acxt, parent_sd);
+
+ if (!sysfs_find_dirent(parent_sd, name)) {
+ sysfs_add_one(&acxt, sd);
+ sysfs_link_sibling(sd);
+ }
+
+ if (!sysfs_addrm_finish(&acxt)) {
+ error = -EEXIST;
+ goto out_put;
+ }
return 0;
- out_unlock:
- mutex_unlock(&sysfs_mutex);
out_put:
sysfs_put(target_sd);
sysfs_put(sd);