aboutsummaryrefslogtreecommitdiffstats
path: root/fs/kernfs/dir.c
diff options
context:
space:
mode:
authorKonstantin Khlebnikov <khlebnikov@yandex-team.ru>2017-02-08 06:28:55 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-02-10 10:02:26 -0500
commit17627157cda13089d8a6c1c2d35acb07334b899c (patch)
tree9a717bcda9657c2e46943d852631e0a53fe3e45a /fs/kernfs/dir.c
parent64e90a8acb8590c2468c919f803652f081e3a4bf (diff)
kernfs: handle null pointers while printing node name and path
Null kernfs nodes could be found at cgroups during construction. It seems safer to handle these null pointers right in kernfs in the same way as printf prints "(null)" for null pointer string. Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru> Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/kernfs/dir.c')
-rw-r--r--fs/kernfs/dir.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index cf4c636ff4da..439b946c4808 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -41,6 +41,9 @@ static bool kernfs_lockdep(struct kernfs_node *kn)
41 41
42static int kernfs_name_locked(struct kernfs_node *kn, char *buf, size_t buflen) 42static int kernfs_name_locked(struct kernfs_node *kn, char *buf, size_t buflen)
43{ 43{
44 if (!kn)
45 return strlcpy(buf, "(null)", buflen);
46
44 return strlcpy(buf, kn->parent ? kn->name : "/", buflen); 47 return strlcpy(buf, kn->parent ? kn->name : "/", buflen);
45} 48}
46 49
@@ -110,6 +113,8 @@ static struct kernfs_node *kernfs_common_ancestor(struct kernfs_node *a,
110 * kn_to: /n1/n2/n3 [depth=3] 113 * kn_to: /n1/n2/n3 [depth=3]
111 * result: /../.. 114 * result: /../..
112 * 115 *
116 * [3] when @kn_to is NULL result will be "(null)"
117 *
113 * Returns the length of the full path. If the full length is equal to or 118 * Returns the length of the full path. If the full length is equal to or
114 * greater than @buflen, @buf contains the truncated path with the trailing 119 * greater than @buflen, @buf contains the truncated path with the trailing
115 * '\0'. On error, -errno is returned. 120 * '\0'. On error, -errno is returned.
@@ -123,6 +128,9 @@ static int kernfs_path_from_node_locked(struct kernfs_node *kn_to,
123 size_t depth_from, depth_to, len = 0; 128 size_t depth_from, depth_to, len = 0;
124 int i, j; 129 int i, j;
125 130
131 if (!kn_to)
132 return strlcpy(buf, "(null)", buflen);
133
126 if (!kn_from) 134 if (!kn_from)
127 kn_from = kernfs_root(kn_to)->kn; 135 kn_from = kernfs_root(kn_to)->kn;
128 136
@@ -166,6 +174,8 @@ static int kernfs_path_from_node_locked(struct kernfs_node *kn_to,
166 * similar to strlcpy(). It returns the length of @kn's name and if @buf 174 * similar to strlcpy(). It returns the length of @kn's name and if @buf
167 * isn't long enough, it's filled upto @buflen-1 and nul terminated. 175 * isn't long enough, it's filled upto @buflen-1 and nul terminated.
168 * 176 *
177 * Fills buffer with "(null)" if @kn is NULL.
178 *
169 * This function can be called from any context. 179 * This function can be called from any context.
170 */ 180 */
171int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen) 181int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen)