aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--fs/kernfs/dir.c10
-rw-r--r--include/trace/events/cgroup.h20
2 files changed, 16 insertions, 14 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)
diff --git a/include/trace/events/cgroup.h b/include/trace/events/cgroup.h
index ab68640a18d0..c226f50e88fa 100644
--- a/include/trace/events/cgroup.h
+++ b/include/trace/events/cgroup.h
@@ -61,19 +61,15 @@ DECLARE_EVENT_CLASS(cgroup,
61 __field( int, id ) 61 __field( int, id )
62 __field( int, level ) 62 __field( int, level )
63 __dynamic_array(char, path, 63 __dynamic_array(char, path,
64 cgrp->kn ? cgroup_path(cgrp, NULL, 0) + 1 64 cgroup_path(cgrp, NULL, 0) + 1)
65 : strlen("(null)"))
66 ), 65 ),
67 66
68 TP_fast_assign( 67 TP_fast_assign(
69 __entry->root = cgrp->root->hierarchy_id; 68 __entry->root = cgrp->root->hierarchy_id;
70 __entry->id = cgrp->id; 69 __entry->id = cgrp->id;
71 __entry->level = cgrp->level; 70 __entry->level = cgrp->level;
72 if (cgrp->kn) 71 cgroup_path(cgrp, __get_dynamic_array(path),
73 cgroup_path(cgrp, __get_dynamic_array(path), 72 __get_dynamic_array_len(path));
74 __get_dynamic_array_len(path));
75 else
76 __assign_str(path, "(null)");
77 ), 73 ),
78 74
79 TP_printk("root=%d id=%d level=%d path=%s", 75 TP_printk("root=%d id=%d level=%d path=%s",
@@ -119,8 +115,7 @@ DECLARE_EVENT_CLASS(cgroup_migrate,
119 __field( int, dst_id ) 115 __field( int, dst_id )
120 __field( int, dst_level ) 116 __field( int, dst_level )
121 __dynamic_array(char, dst_path, 117 __dynamic_array(char, dst_path,
122 dst_cgrp->kn ? cgroup_path(dst_cgrp, NULL, 0) + 1 118 cgroup_path(dst_cgrp, NULL, 0) + 1)
123 : strlen("(null)"))
124 __field( int, pid ) 119 __field( int, pid )
125 __string( comm, task->comm ) 120 __string( comm, task->comm )
126 ), 121 ),
@@ -129,11 +124,8 @@ DECLARE_EVENT_CLASS(cgroup_migrate,
129 __entry->dst_root = dst_cgrp->root->hierarchy_id; 124 __entry->dst_root = dst_cgrp->root->hierarchy_id;
130 __entry->dst_id = dst_cgrp->id; 125 __entry->dst_id = dst_cgrp->id;
131 __entry->dst_level = dst_cgrp->level; 126 __entry->dst_level = dst_cgrp->level;
132 if (dst_cgrp->kn) 127 cgroup_path(dst_cgrp, __get_dynamic_array(dst_path),
133 cgroup_path(dst_cgrp, __get_dynamic_array(dst_path), 128 __get_dynamic_array_len(dst_path));
134 __get_dynamic_array_len(dst_path));
135 else
136 __assign_str(dst_path, "(null)");
137 __entry->pid = task->pid; 129 __entry->pid = task->pid;
138 __assign_str(comm, task->comm); 130 __assign_str(comm, task->comm);
139 ), 131 ),