diff mbox series

[v2,07/10] blktrace: move debugfs file creation to its own function

Message ID 20200419194529.4872-8-mcgrof@kernel.org
State New, archived
Headers show
Series block: fix blktrace debugfs use after free | expand

Commit Message

Luis Chamberlain April 19, 2020, 7:45 p.m. UTC
Move creating the blktrace debugfs files into its own function.
We'll expand on this later.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 kernel/trace/blktrace.c | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

Comments

Bart Van Assche April 19, 2020, 10:55 p.m. UTC | #1
On 4/19/20 12:45 PM, Luis Chamberlain wrote:
> +static int blk_trace_create_debugfs_files(struct blk_user_trace_setup *buts,
> +					  struct dentry *dir,
> +					  struct blk_trace *bt)
> +{
> +	int ret = -EIO;
> +
> +	bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
> +					       &blk_dropped_fops);
> +
> +	bt->msg_file = debugfs_create_file("msg", 0222, dir, bt, &blk_msg_fops);
> +
> +	bt->rchan = relay_open("trace", dir, buts->buf_size,
> +				buts->buf_nr, &blk_relay_callbacks, bt);
> +	if (!bt->rchan)
> +		return ret;
> +
> +	return 0;
> +}

How about adding IS_ERR() checks for the debugfs_create_file() return 
values?

Thanks,

Bart.
Greg Kroah-Hartman April 20, 2020, 11:37 a.m. UTC | #2
On Sun, Apr 19, 2020 at 03:55:15PM -0700, Bart Van Assche wrote:
> On 4/19/20 12:45 PM, Luis Chamberlain wrote:
> > +static int blk_trace_create_debugfs_files(struct blk_user_trace_setup *buts,
> > +					  struct dentry *dir,
> > +					  struct blk_trace *bt)
> > +{
> > +	int ret = -EIO;
> > +
> > +	bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
> > +					       &blk_dropped_fops);
> > +
> > +	bt->msg_file = debugfs_create_file("msg", 0222, dir, bt, &blk_msg_fops);
> > +
> > +	bt->rchan = relay_open("trace", dir, buts->buf_size,
> > +				buts->buf_nr, &blk_relay_callbacks, bt);
> > +	if (!bt->rchan)
> > +		return ret;
> > +
> > +	return 0;
> > +}
> 
> How about adding IS_ERR() checks for the debugfs_create_file() return
> values?

No, please no, I have been removing all of that nonsense from the kernel
for the past 3-4 releases.  You should never care about the return value
from that call, just save it off and move on.

as it is, this is correct.

greg k-h
diff mbox series

Patch

diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 909db597b551..9cc0153849c3 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -548,6 +548,25 @@  static struct dentry *blk_trace_debugfs_dir(struct blk_user_trace_setup *buts,
 	return bt->dir;
 }
 
+static int blk_trace_create_debugfs_files(struct blk_user_trace_setup *buts,
+					  struct dentry *dir,
+					  struct blk_trace *bt)
+{
+	int ret = -EIO;
+
+	bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
+					       &blk_dropped_fops);
+
+	bt->msg_file = debugfs_create_file("msg", 0222, dir, bt, &blk_msg_fops);
+
+	bt->rchan = relay_open("trace", dir, buts->buf_size,
+				buts->buf_nr, &blk_relay_callbacks, bt);
+	if (!bt->rchan)
+		return ret;
+
+	return 0;
+}
+
 /*
  * Setup everything required to start tracing
  */
@@ -597,15 +616,8 @@  static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
 	atomic_set(&bt->dropped, 0);
 	INIT_LIST_HEAD(&bt->running_list);
 
-	ret = -EIO;
-	bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
-					       &blk_dropped_fops);
-
-	bt->msg_file = debugfs_create_file("msg", 0222, dir, bt, &blk_msg_fops);
-
-	bt->rchan = relay_open("trace", dir, buts->buf_size,
-				buts->buf_nr, &blk_relay_callbacks, bt);
-	if (!bt->rchan)
+	ret = blk_trace_create_debugfs_files(buts, dir, bt);
+	if (ret)
 		goto err;
 
 	bt->act_mask = buts->act_mask;