Commit 6cfc0081 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman Committed by Jens Axboe

blk-mq: no need to check return value of debugfs_create functions

When calling debugfs functions, there is no need to ever check the
return value.  The function can work or not, but the code logic should
never do something different based on this.

When all of these checks are cleaned up, lots of the functions used in
the blk-mq-debugfs code can now return void, as no need to check the
return value of them either.

Overall, this ends up cleaning up the code and making it smaller, always
a nice win.

Cc: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 355e8d26
...@@ -821,38 +821,28 @@ static const struct blk_mq_debugfs_attr blk_mq_debugfs_ctx_attrs[] = { ...@@ -821,38 +821,28 @@ static const struct blk_mq_debugfs_attr blk_mq_debugfs_ctx_attrs[] = {
{}, {},
}; };
static bool debugfs_create_files(struct dentry *parent, void *data, static void debugfs_create_files(struct dentry *parent, void *data,
const struct blk_mq_debugfs_attr *attr) const struct blk_mq_debugfs_attr *attr)
{ {
if (IS_ERR_OR_NULL(parent)) if (IS_ERR_OR_NULL(parent))
return false; return;
d_inode(parent)->i_private = data; d_inode(parent)->i_private = data;
for (; attr->name; attr++) { for (; attr->name; attr++)
if (!debugfs_create_file(attr->name, attr->mode, parent, debugfs_create_file(attr->name, attr->mode, parent,
(void *)attr, &blk_mq_debugfs_fops)) (void *)attr, &blk_mq_debugfs_fops);
return false;
}
return true;
} }
int blk_mq_debugfs_register(struct request_queue *q) void blk_mq_debugfs_register(struct request_queue *q)
{ {
struct blk_mq_hw_ctx *hctx; struct blk_mq_hw_ctx *hctx;
int i; int i;
if (!blk_debugfs_root)
return -ENOENT;
q->debugfs_dir = debugfs_create_dir(kobject_name(q->kobj.parent), q->debugfs_dir = debugfs_create_dir(kobject_name(q->kobj.parent),
blk_debugfs_root); blk_debugfs_root);
if (!q->debugfs_dir)
return -ENOMEM;
if (!debugfs_create_files(q->debugfs_dir, q, debugfs_create_files(q->debugfs_dir, q, blk_mq_debugfs_queue_attrs);
blk_mq_debugfs_queue_attrs))
goto err;
/* /*
* blk_mq_init_sched() attempted to do this already, but q->debugfs_dir * blk_mq_init_sched() attempted to do this already, but q->debugfs_dir
...@@ -864,11 +854,10 @@ int blk_mq_debugfs_register(struct request_queue *q) ...@@ -864,11 +854,10 @@ int blk_mq_debugfs_register(struct request_queue *q)
/* Similarly, blk_mq_init_hctx() couldn't do this previously. */ /* Similarly, blk_mq_init_hctx() couldn't do this previously. */
queue_for_each_hw_ctx(q, hctx, i) { queue_for_each_hw_ctx(q, hctx, i) {
if (!hctx->debugfs_dir && blk_mq_debugfs_register_hctx(q, hctx)) if (!hctx->debugfs_dir)
goto err; blk_mq_debugfs_register_hctx(q, hctx);
if (q->elevator && !hctx->sched_debugfs_dir && if (q->elevator && !hctx->sched_debugfs_dir)
blk_mq_debugfs_register_sched_hctx(q, hctx)) blk_mq_debugfs_register_sched_hctx(q, hctx);
goto err;
} }
if (q->rq_qos) { if (q->rq_qos) {
...@@ -879,12 +868,6 @@ int blk_mq_debugfs_register(struct request_queue *q) ...@@ -879,12 +868,6 @@ int blk_mq_debugfs_register(struct request_queue *q)
rqos = rqos->next; rqos = rqos->next;
} }
} }
return 0;
err:
blk_mq_debugfs_unregister(q);
return -ENOMEM;
} }
void blk_mq_debugfs_unregister(struct request_queue *q) void blk_mq_debugfs_unregister(struct request_queue *q)
...@@ -894,52 +877,32 @@ void blk_mq_debugfs_unregister(struct request_queue *q) ...@@ -894,52 +877,32 @@ void blk_mq_debugfs_unregister(struct request_queue *q)
q->debugfs_dir = NULL; q->debugfs_dir = NULL;
} }
static int blk_mq_debugfs_register_ctx(struct blk_mq_hw_ctx *hctx, static void blk_mq_debugfs_register_ctx(struct blk_mq_hw_ctx *hctx,
struct blk_mq_ctx *ctx) struct blk_mq_ctx *ctx)
{ {
struct dentry *ctx_dir; struct dentry *ctx_dir;
char name[20]; char name[20];
snprintf(name, sizeof(name), "cpu%u", ctx->cpu); snprintf(name, sizeof(name), "cpu%u", ctx->cpu);
ctx_dir = debugfs_create_dir(name, hctx->debugfs_dir); ctx_dir = debugfs_create_dir(name, hctx->debugfs_dir);
if (!ctx_dir)
return -ENOMEM;
if (!debugfs_create_files(ctx_dir, ctx, blk_mq_debugfs_ctx_attrs)) debugfs_create_files(ctx_dir, ctx, blk_mq_debugfs_ctx_attrs);
return -ENOMEM;
return 0;
} }
int blk_mq_debugfs_register_hctx(struct request_queue *q, void blk_mq_debugfs_register_hctx(struct request_queue *q,
struct blk_mq_hw_ctx *hctx) struct blk_mq_hw_ctx *hctx)
{ {
struct blk_mq_ctx *ctx; struct blk_mq_ctx *ctx;
char name[20]; char name[20];
int i; int i;
if (!q->debugfs_dir)
return -ENOENT;
snprintf(name, sizeof(name), "hctx%u", hctx->queue_num); snprintf(name, sizeof(name), "hctx%u", hctx->queue_num);
hctx->debugfs_dir = debugfs_create_dir(name, q->debugfs_dir); hctx->debugfs_dir = debugfs_create_dir(name, q->debugfs_dir);
if (!hctx->debugfs_dir)
return -ENOMEM;
if (!debugfs_create_files(hctx->debugfs_dir, hctx,
blk_mq_debugfs_hctx_attrs))
goto err;
hctx_for_each_ctx(hctx, ctx, i) {
if (blk_mq_debugfs_register_ctx(hctx, ctx))
goto err;
}
return 0; debugfs_create_files(hctx->debugfs_dir, hctx, blk_mq_debugfs_hctx_attrs);
err: hctx_for_each_ctx(hctx, ctx, i)
blk_mq_debugfs_unregister_hctx(hctx); blk_mq_debugfs_register_ctx(hctx, ctx);
return -ENOMEM;
} }
void blk_mq_debugfs_unregister_hctx(struct blk_mq_hw_ctx *hctx) void blk_mq_debugfs_unregister_hctx(struct blk_mq_hw_ctx *hctx)
...@@ -949,17 +912,13 @@ void blk_mq_debugfs_unregister_hctx(struct blk_mq_hw_ctx *hctx) ...@@ -949,17 +912,13 @@ void blk_mq_debugfs_unregister_hctx(struct blk_mq_hw_ctx *hctx)
hctx->debugfs_dir = NULL; hctx->debugfs_dir = NULL;
} }
int blk_mq_debugfs_register_hctxs(struct request_queue *q) void blk_mq_debugfs_register_hctxs(struct request_queue *q)
{ {
struct blk_mq_hw_ctx *hctx; struct blk_mq_hw_ctx *hctx;
int i; int i;
queue_for_each_hw_ctx(q, hctx, i) { queue_for_each_hw_ctx(q, hctx, i)
if (blk_mq_debugfs_register_hctx(q, hctx)) blk_mq_debugfs_register_hctx(q, hctx);
return -ENOMEM;
}
return 0;
} }
void blk_mq_debugfs_unregister_hctxs(struct request_queue *q) void blk_mq_debugfs_unregister_hctxs(struct request_queue *q)
...@@ -971,29 +930,16 @@ void blk_mq_debugfs_unregister_hctxs(struct request_queue *q) ...@@ -971,29 +930,16 @@ void blk_mq_debugfs_unregister_hctxs(struct request_queue *q)
blk_mq_debugfs_unregister_hctx(hctx); blk_mq_debugfs_unregister_hctx(hctx);
} }
int blk_mq_debugfs_register_sched(struct request_queue *q) void blk_mq_debugfs_register_sched(struct request_queue *q)
{ {
struct elevator_type *e = q->elevator->type; struct elevator_type *e = q->elevator->type;
if (!q->debugfs_dir)
return -ENOENT;
if (!e->queue_debugfs_attrs) if (!e->queue_debugfs_attrs)
return 0; return;
q->sched_debugfs_dir = debugfs_create_dir("sched", q->debugfs_dir); q->sched_debugfs_dir = debugfs_create_dir("sched", q->debugfs_dir);
if (!q->sched_debugfs_dir)
return -ENOMEM;
if (!debugfs_create_files(q->sched_debugfs_dir, q, debugfs_create_files(q->sched_debugfs_dir, q, e->queue_debugfs_attrs);
e->queue_debugfs_attrs))
goto err;
return 0;
err:
blk_mq_debugfs_unregister_sched(q);
return -ENOMEM;
} }
void blk_mq_debugfs_unregister_sched(struct request_queue *q) void blk_mq_debugfs_unregister_sched(struct request_queue *q)
...@@ -1008,36 +954,22 @@ void blk_mq_debugfs_unregister_rqos(struct rq_qos *rqos) ...@@ -1008,36 +954,22 @@ void blk_mq_debugfs_unregister_rqos(struct rq_qos *rqos)
rqos->debugfs_dir = NULL; rqos->debugfs_dir = NULL;
} }
int blk_mq_debugfs_register_rqos(struct rq_qos *rqos) void blk_mq_debugfs_register_rqos(struct rq_qos *rqos)
{ {
struct request_queue *q = rqos->q; struct request_queue *q = rqos->q;
const char *dir_name = rq_qos_id_to_name(rqos->id); const char *dir_name = rq_qos_id_to_name(rqos->id);
if (!q->debugfs_dir)
return -ENOENT;
if (rqos->debugfs_dir || !rqos->ops->debugfs_attrs) if (rqos->debugfs_dir || !rqos->ops->debugfs_attrs)
return 0; return;
if (!q->rqos_debugfs_dir) { if (!q->rqos_debugfs_dir)
q->rqos_debugfs_dir = debugfs_create_dir("rqos", q->rqos_debugfs_dir = debugfs_create_dir("rqos",
q->debugfs_dir); q->debugfs_dir);
if (!q->rqos_debugfs_dir)
return -ENOMEM;
}
rqos->debugfs_dir = debugfs_create_dir(dir_name, rqos->debugfs_dir = debugfs_create_dir(dir_name,
rqos->q->rqos_debugfs_dir); rqos->q->rqos_debugfs_dir);
if (!rqos->debugfs_dir)
return -ENOMEM;
if (!debugfs_create_files(rqos->debugfs_dir, rqos, debugfs_create_files(rqos->debugfs_dir, rqos, rqos->ops->debugfs_attrs);
rqos->ops->debugfs_attrs))
goto err;
return 0;
err:
blk_mq_debugfs_unregister_rqos(rqos);
return -ENOMEM;
} }
void blk_mq_debugfs_unregister_queue_rqos(struct request_queue *q) void blk_mq_debugfs_unregister_queue_rqos(struct request_queue *q)
...@@ -1046,27 +978,18 @@ void blk_mq_debugfs_unregister_queue_rqos(struct request_queue *q) ...@@ -1046,27 +978,18 @@ void blk_mq_debugfs_unregister_queue_rqos(struct request_queue *q)
q->rqos_debugfs_dir = NULL; q->rqos_debugfs_dir = NULL;
} }
int blk_mq_debugfs_register_sched_hctx(struct request_queue *q, void blk_mq_debugfs_register_sched_hctx(struct request_queue *q,
struct blk_mq_hw_ctx *hctx) struct blk_mq_hw_ctx *hctx)
{ {
struct elevator_type *e = q->elevator->type; struct elevator_type *e = q->elevator->type;
if (!hctx->debugfs_dir)
return -ENOENT;
if (!e->hctx_debugfs_attrs) if (!e->hctx_debugfs_attrs)
return 0; return;
hctx->sched_debugfs_dir = debugfs_create_dir("sched", hctx->sched_debugfs_dir = debugfs_create_dir("sched",
hctx->debugfs_dir); hctx->debugfs_dir);
if (!hctx->sched_debugfs_dir) debugfs_create_files(hctx->sched_debugfs_dir, hctx,
return -ENOMEM; e->hctx_debugfs_attrs);
if (!debugfs_create_files(hctx->sched_debugfs_dir, hctx,
e->hctx_debugfs_attrs))
return -ENOMEM;
return 0;
} }
void blk_mq_debugfs_unregister_sched_hctx(struct blk_mq_hw_ctx *hctx) void blk_mq_debugfs_unregister_sched_hctx(struct blk_mq_hw_ctx *hctx)
......
...@@ -18,74 +18,68 @@ struct blk_mq_debugfs_attr { ...@@ -18,74 +18,68 @@ struct blk_mq_debugfs_attr {
int __blk_mq_debugfs_rq_show(struct seq_file *m, struct request *rq); int __blk_mq_debugfs_rq_show(struct seq_file *m, struct request *rq);
int blk_mq_debugfs_rq_show(struct seq_file *m, void *v); int blk_mq_debugfs_rq_show(struct seq_file *m, void *v);
int blk_mq_debugfs_register(struct request_queue *q); void blk_mq_debugfs_register(struct request_queue *q);
void blk_mq_debugfs_unregister(struct request_queue *q); void blk_mq_debugfs_unregister(struct request_queue *q);
int blk_mq_debugfs_register_hctx(struct request_queue *q, void blk_mq_debugfs_register_hctx(struct request_queue *q,
struct blk_mq_hw_ctx *hctx); struct blk_mq_hw_ctx *hctx);
void blk_mq_debugfs_unregister_hctx(struct blk_mq_hw_ctx *hctx); void blk_mq_debugfs_unregister_hctx(struct blk_mq_hw_ctx *hctx);
int blk_mq_debugfs_register_hctxs(struct request_queue *q); void blk_mq_debugfs_register_hctxs(struct request_queue *q);
void blk_mq_debugfs_unregister_hctxs(struct request_queue *q); void blk_mq_debugfs_unregister_hctxs(struct request_queue *q);
int blk_mq_debugfs_register_sched(struct request_queue *q); void blk_mq_debugfs_register_sched(struct request_queue *q);
void blk_mq_debugfs_unregister_sched(struct request_queue *q); void blk_mq_debugfs_unregister_sched(struct request_queue *q);
int blk_mq_debugfs_register_sched_hctx(struct request_queue *q, void blk_mq_debugfs_register_sched_hctx(struct request_queue *q,
struct blk_mq_hw_ctx *hctx); struct blk_mq_hw_ctx *hctx);
void blk_mq_debugfs_unregister_sched_hctx(struct blk_mq_hw_ctx *hctx); void blk_mq_debugfs_unregister_sched_hctx(struct blk_mq_hw_ctx *hctx);
int blk_mq_debugfs_register_rqos(struct rq_qos *rqos); void blk_mq_debugfs_register_rqos(struct rq_qos *rqos);
void blk_mq_debugfs_unregister_rqos(struct rq_qos *rqos); void blk_mq_debugfs_unregister_rqos(struct rq_qos *rqos);
void blk_mq_debugfs_unregister_queue_rqos(struct request_queue *q); void blk_mq_debugfs_unregister_queue_rqos(struct request_queue *q);
#else #else
static inline int blk_mq_debugfs_register(struct request_queue *q) static inline void blk_mq_debugfs_register(struct request_queue *q)
{ {
return 0;
} }
static inline void blk_mq_debugfs_unregister(struct request_queue *q) static inline void blk_mq_debugfs_unregister(struct request_queue *q)
{ {
} }
static inline int blk_mq_debugfs_register_hctx(struct request_queue *q, static inline void blk_mq_debugfs_register_hctx(struct request_queue *q,
struct blk_mq_hw_ctx *hctx) struct blk_mq_hw_ctx *hctx)
{ {
return 0;
} }
static inline void blk_mq_debugfs_unregister_hctx(struct blk_mq_hw_ctx *hctx) static inline void blk_mq_debugfs_unregister_hctx(struct blk_mq_hw_ctx *hctx)
{ {
} }
static inline int blk_mq_debugfs_register_hctxs(struct request_queue *q) static inline void blk_mq_debugfs_register_hctxs(struct request_queue *q)
{ {
return 0;
} }
static inline void blk_mq_debugfs_unregister_hctxs(struct request_queue *q) static inline void blk_mq_debugfs_unregister_hctxs(struct request_queue *q)
{ {
} }
static inline int blk_mq_debugfs_register_sched(struct request_queue *q) static inline void blk_mq_debugfs_register_sched(struct request_queue *q)
{ {
return 0;
} }
static inline void blk_mq_debugfs_unregister_sched(struct request_queue *q) static inline void blk_mq_debugfs_unregister_sched(struct request_queue *q)
{ {
} }
static inline int blk_mq_debugfs_register_sched_hctx(struct request_queue *q, static inline void blk_mq_debugfs_register_sched_hctx(struct request_queue *q,
struct blk_mq_hw_ctx *hctx) struct blk_mq_hw_ctx *hctx)
{ {
return 0;
} }
static inline void blk_mq_debugfs_unregister_sched_hctx(struct blk_mq_hw_ctx *hctx) static inline void blk_mq_debugfs_unregister_sched_hctx(struct blk_mq_hw_ctx *hctx)
{ {
} }
static inline int blk_mq_debugfs_register_rqos(struct rq_qos *rqos) static inline void blk_mq_debugfs_register_rqos(struct rq_qos *rqos)
{ {
return 0;
} }
static inline void blk_mq_debugfs_unregister_rqos(struct rq_qos *rqos) static inline void blk_mq_debugfs_unregister_rqos(struct rq_qos *rqos)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment