aboutsummaryrefslogtreecommitdiffstats
path: root/fs/sysfs/file.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-11-28 14:54:30 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-11-29 20:55:10 -0500
commitccf73cf336dc55bc52748205dee998d2fd4a8808 (patch)
tree8e3a3b9891e6b9d4804299cd23110c91d8f8016e /fs/sysfs/file.c
parent517e64f57883bd63c5a4ab8b3d0d3ed68c55d0cf (diff)
sysfs, kernfs: introduce kernfs[_find_and]_get() and kernfs_put()
Introduce kernfs interface for finding, getting and putting sysfs_dirents. * sysfs_find_dirent() is renamed to kernfs_find_ns() and lockdep assertion for sysfs_mutex is added. * sysfs_get_dirent_ns() is renamed to kernfs_find_and_get(). * Macro inline dancing around __sysfs_get/put() are removed and kernfs_get/put() are made proper functions implemented in fs/sysfs/dir.c. While the conversions are mostly equivalent, there's one difference - kernfs_get() doesn't return the input param as its return value. This change is intentional. While passing through the input increases writability in some areas, it is unnecessary and has been shown to cause confusion regarding how the last ref is handled. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/sysfs/file.c')
-rw-r--r--fs/sysfs/file.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index e4eca285b390..7f0a79fa2ed8 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -881,19 +881,19 @@ void sysfs_notify(struct kobject *k, const char *dir, const char *attr)
881 struct sysfs_dirent *sd = k->sd, *tmp; 881 struct sysfs_dirent *sd = k->sd, *tmp;
882 882
883 if (sd && dir) 883 if (sd && dir)
884 sd = sysfs_get_dirent(sd, dir); 884 sd = kernfs_find_and_get(sd, dir);
885 else 885 else
886 sysfs_get(sd); 886 kernfs_get(sd);
887 887
888 if (sd && attr) { 888 if (sd && attr) {
889 tmp = sysfs_get_dirent(sd, attr); 889 tmp = kernfs_find_and_get(sd, attr);
890 sysfs_put(sd); 890 kernfs_put(sd);
891 sd = tmp; 891 sd = tmp;
892 } 892 }
893 893
894 if (sd) { 894 if (sd) {
895 kernfs_notify(sd); 895 kernfs_notify(sd);
896 sysfs_put(sd); 896 kernfs_put(sd);
897 } 897 }
898} 898}
899EXPORT_SYMBOL_GPL(sysfs_notify); 899EXPORT_SYMBOL_GPL(sysfs_notify);
@@ -1052,7 +1052,7 @@ struct sysfs_dirent *kernfs_create_file_ns_key(struct sysfs_dirent *parent,
1052 sysfs_addrm_finish(&acxt); 1052 sysfs_addrm_finish(&acxt);
1053 1053
1054 if (rc) { 1054 if (rc) {
1055 sysfs_put(sd); 1055 kernfs_put(sd);
1056 return ERR_PTR(rc); 1056 return ERR_PTR(rc);
1057 } 1057 }
1058 return sd; 1058 return sd;
@@ -1106,16 +1106,18 @@ int sysfs_add_file_to_group(struct kobject *kobj,
1106 struct sysfs_dirent *dir_sd; 1106 struct sysfs_dirent *dir_sd;
1107 int error; 1107 int error;
1108 1108
1109 if (group) 1109 if (group) {
1110 dir_sd = sysfs_get_dirent(kobj->sd, group); 1110 dir_sd = kernfs_find_and_get(kobj->sd, group);
1111 else 1111 } else {
1112 dir_sd = sysfs_get(kobj->sd); 1112 dir_sd = kobj->sd;
1113 kernfs_get(dir_sd);
1114 }
1113 1115
1114 if (!dir_sd) 1116 if (!dir_sd)
1115 return -ENOENT; 1117 return -ENOENT;
1116 1118
1117 error = sysfs_add_file(dir_sd, attr, false); 1119 error = sysfs_add_file(dir_sd, attr, false);
1118 sysfs_put(dir_sd); 1120 kernfs_put(dir_sd);
1119 1121
1120 return error; 1122 return error;
1121} 1123}
@@ -1135,7 +1137,7 @@ int sysfs_chmod_file(struct kobject *kobj, const struct attribute *attr,
1135 struct iattr newattrs; 1137 struct iattr newattrs;
1136 int rc; 1138 int rc;
1137 1139
1138 sd = sysfs_get_dirent(kobj->sd, attr->name); 1140 sd = kernfs_find_and_get(kobj->sd, attr->name);
1139 if (!sd) 1141 if (!sd)
1140 return -ENOENT; 1142 return -ENOENT;
1141 1143
@@ -1144,7 +1146,7 @@ int sysfs_chmod_file(struct kobject *kobj, const struct attribute *attr,
1144 1146
1145 rc = kernfs_setattr(sd, &newattrs); 1147 rc = kernfs_setattr(sd, &newattrs);
1146 1148
1147 sysfs_put(sd); 1149 kernfs_put(sd);
1148 return rc; 1150 return rc;
1149} 1151}
1150EXPORT_SYMBOL_GPL(sysfs_chmod_file); 1152EXPORT_SYMBOL_GPL(sysfs_chmod_file);
@@ -1185,13 +1187,16 @@ void sysfs_remove_file_from_group(struct kobject *kobj,
1185{ 1187{
1186 struct sysfs_dirent *dir_sd; 1188 struct sysfs_dirent *dir_sd;
1187 1189
1188 if (group) 1190 if (group) {
1189 dir_sd = sysfs_get_dirent(kobj->sd, group); 1191 dir_sd = kernfs_find_and_get(kobj->sd, group);
1190 else 1192 } else {
1191 dir_sd = sysfs_get(kobj->sd); 1193 dir_sd = kobj->sd;
1194 kernfs_get(dir_sd);
1195 }
1196
1192 if (dir_sd) { 1197 if (dir_sd) {
1193 kernfs_remove_by_name(dir_sd, attr->name); 1198 kernfs_remove_by_name(dir_sd, attr->name);
1194 sysfs_put(dir_sd); 1199 kernfs_put(dir_sd);
1195 } 1200 }
1196} 1201}
1197EXPORT_SYMBOL_GPL(sysfs_remove_file_from_group); 1202EXPORT_SYMBOL_GPL(sysfs_remove_file_from_group);