diff options
Diffstat (limited to 'fs/sysfs/file.c')
-rw-r--r-- | fs/sysfs/file.c | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index a68cbef3a674..e4eca285b390 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c | |||
@@ -58,7 +58,7 @@ static struct sysfs_open_file *sysfs_of(struct file *file) | |||
58 | */ | 58 | */ |
59 | static const struct kernfs_ops *kernfs_ops(struct sysfs_dirent *sd) | 59 | static const struct kernfs_ops *kernfs_ops(struct sysfs_dirent *sd) |
60 | { | 60 | { |
61 | if (!sysfs_ignore_lockdep(sd)) | 61 | if (sd->s_flags & SYSFS_FLAG_LOCKDEP) |
62 | lockdep_assert_held(sd); | 62 | lockdep_assert_held(sd); |
63 | return sd->s_attr.ops; | 63 | return sd->s_attr.ops; |
64 | } | 64 | } |
@@ -71,7 +71,7 @@ static const struct sysfs_ops *sysfs_file_ops(struct sysfs_dirent *sd) | |||
71 | { | 71 | { |
72 | struct kobject *kobj = sd->s_parent->priv; | 72 | struct kobject *kobj = sd->s_parent->priv; |
73 | 73 | ||
74 | if (!sysfs_ignore_lockdep(sd)) | 74 | if (sd->s_flags & SYSFS_FLAG_LOCKDEP) |
75 | lockdep_assert_held(sd); | 75 | lockdep_assert_held(sd); |
76 | return kobj->ktype ? kobj->ktype->sysfs_ops : NULL; | 76 | return kobj->ktype ? kobj->ktype->sysfs_ops : NULL; |
77 | } | 77 | } |
@@ -942,6 +942,7 @@ int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd, | |||
942 | const struct attribute *attr, bool is_bin, | 942 | const struct attribute *attr, bool is_bin, |
943 | umode_t mode, const void *ns) | 943 | umode_t mode, const void *ns) |
944 | { | 944 | { |
945 | struct lock_class_key *key = NULL; | ||
945 | const struct kernfs_ops *ops; | 946 | const struct kernfs_ops *ops; |
946 | struct sysfs_dirent *sd; | 947 | struct sysfs_dirent *sd; |
947 | loff_t size; | 948 | loff_t size; |
@@ -981,8 +982,12 @@ int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd, | |||
981 | size = battr->size; | 982 | size = battr->size; |
982 | } | 983 | } |
983 | 984 | ||
984 | sd = kernfs_create_file_ns(dir_sd, attr->name, mode, size, | 985 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
985 | ops, (void *)attr, ns); | 986 | if (!attr->ignore_lockdep) |
987 | key = attr->key ?: (struct lock_class_key *)&attr->skey; | ||
988 | #endif | ||
989 | sd = kernfs_create_file_ns_key(dir_sd, attr->name, mode, size, | ||
990 | ops, (void *)attr, ns, key); | ||
986 | if (IS_ERR(sd)) { | 991 | if (IS_ERR(sd)) { |
987 | if (PTR_ERR(sd) == -EEXIST) | 992 | if (PTR_ERR(sd) == -EEXIST) |
988 | sysfs_warn_dup(dir_sd, attr->name); | 993 | sysfs_warn_dup(dir_sd, attr->name); |
@@ -992,7 +997,7 @@ int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd, | |||
992 | } | 997 | } |
993 | 998 | ||
994 | /** | 999 | /** |
995 | * kernfs_create_file_ns - create a file | 1000 | * kernfs_create_file_ns_key - create a file |
996 | * @parent: directory to create the file in | 1001 | * @parent: directory to create the file in |
997 | * @name: name of the file | 1002 | * @name: name of the file |
998 | * @mode: mode of the file | 1003 | * @mode: mode of the file |
@@ -1000,14 +1005,16 @@ int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd, | |||
1000 | * @ops: kernfs operations for the file | 1005 | * @ops: kernfs operations for the file |
1001 | * @priv: private data for the file | 1006 | * @priv: private data for the file |
1002 | * @ns: optional namespace tag of the file | 1007 | * @ns: optional namespace tag of the file |
1008 | * @key: lockdep key for the file's active_ref, %NULL to disable lockdep | ||
1003 | * | 1009 | * |
1004 | * Returns the created node on success, ERR_PTR() value on error. | 1010 | * Returns the created node on success, ERR_PTR() value on error. |
1005 | */ | 1011 | */ |
1006 | struct sysfs_dirent *kernfs_create_file_ns(struct sysfs_dirent *parent, | 1012 | struct sysfs_dirent *kernfs_create_file_ns_key(struct sysfs_dirent *parent, |
1007 | const char *name, | 1013 | const char *name, |
1008 | umode_t mode, loff_t size, | 1014 | umode_t mode, loff_t size, |
1009 | const struct kernfs_ops *ops, | 1015 | const struct kernfs_ops *ops, |
1010 | void *priv, const void *ns) | 1016 | void *priv, const void *ns, |
1017 | struct lock_class_key *key) | ||
1011 | { | 1018 | { |
1012 | struct sysfs_addrm_cxt acxt; | 1019 | struct sysfs_addrm_cxt acxt; |
1013 | struct sysfs_dirent *sd; | 1020 | struct sysfs_dirent *sd; |
@@ -1022,7 +1029,13 @@ struct sysfs_dirent *kernfs_create_file_ns(struct sysfs_dirent *parent, | |||
1022 | sd->s_attr.size = size; | 1029 | sd->s_attr.size = size; |
1023 | sd->s_ns = ns; | 1030 | sd->s_ns = ns; |
1024 | sd->priv = priv; | 1031 | sd->priv = priv; |
1025 | sysfs_dirent_init_lockdep(sd); | 1032 | |
1033 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | ||
1034 | if (key) { | ||
1035 | lockdep_init_map(&sd->dep_map, "s_active", key, 0); | ||
1036 | sd->s_flags |= SYSFS_FLAG_LOCKDEP; | ||
1037 | } | ||
1038 | #endif | ||
1026 | 1039 | ||
1027 | /* | 1040 | /* |
1028 | * sd->s_attr.ops is accesible only while holding active ref. We | 1041 | * sd->s_attr.ops is accesible only while holding active ref. We |