Commit 3087b335 authored by Md Haris Iqbal's avatar Md Haris Iqbal Committed by Jens Axboe

block/rnbd: Use sysfs_emit instead of s*printf function for sysfs show

sysfs_emit function was added to be aware of the PAGE_SIZE maximum of
the temporary buffer used for outputting sysfs content, so there is no
possible overruns. So replace the uses of any s*printf functions for
the sysfs show functions with sysfs_emit.
Signed-off-by: default avatarMd Haris Iqbal <haris.iqbal@ionos.com>
Signed-off-by: default avatarJack Wang <jinpu.wang@ionos.com>
Link: https://lore.kernel.org/r/20210726115950.470543-3-jinpu.wang@ionos.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 94dace8c
...@@ -227,17 +227,17 @@ static ssize_t state_show(struct kobject *kobj, ...@@ -227,17 +227,17 @@ static ssize_t state_show(struct kobject *kobj,
switch (dev->dev_state) { switch (dev->dev_state) {
case DEV_STATE_INIT: case DEV_STATE_INIT:
return snprintf(page, PAGE_SIZE, "init\n"); return sysfs_emit(page, "init\n");
case DEV_STATE_MAPPED: case DEV_STATE_MAPPED:
/* TODO fix cli tool before changing to proper state */ /* TODO fix cli tool before changing to proper state */
return snprintf(page, PAGE_SIZE, "open\n"); return sysfs_emit(page, "open\n");
case DEV_STATE_MAPPED_DISCONNECTED: case DEV_STATE_MAPPED_DISCONNECTED:
/* TODO fix cli tool before changing to proper state */ /* TODO fix cli tool before changing to proper state */
return snprintf(page, PAGE_SIZE, "closed\n"); return sysfs_emit(page, "closed\n");
case DEV_STATE_UNMAPPED: case DEV_STATE_UNMAPPED:
return snprintf(page, PAGE_SIZE, "unmapped\n"); return sysfs_emit(page, "unmapped\n");
default: default:
return snprintf(page, PAGE_SIZE, "unknown\n"); return sysfs_emit(page, "unknown\n");
} }
} }
...@@ -263,7 +263,7 @@ static ssize_t mapping_path_show(struct kobject *kobj, ...@@ -263,7 +263,7 @@ static ssize_t mapping_path_show(struct kobject *kobj,
dev = container_of(kobj, struct rnbd_clt_dev, kobj); dev = container_of(kobj, struct rnbd_clt_dev, kobj);
return scnprintf(page, PAGE_SIZE, "%s\n", dev->pathname); return sysfs_emit(page, "%s\n", dev->pathname);
} }
static struct kobj_attribute rnbd_clt_mapping_path_attr = static struct kobj_attribute rnbd_clt_mapping_path_attr =
...@@ -276,8 +276,7 @@ static ssize_t access_mode_show(struct kobject *kobj, ...@@ -276,8 +276,7 @@ static ssize_t access_mode_show(struct kobject *kobj,
dev = container_of(kobj, struct rnbd_clt_dev, kobj); dev = container_of(kobj, struct rnbd_clt_dev, kobj);
return snprintf(page, PAGE_SIZE, "%s\n", return sysfs_emit(page, "%s\n", rnbd_access_mode_str(dev->access_mode));
rnbd_access_mode_str(dev->access_mode));
} }
static struct kobj_attribute rnbd_clt_access_mode = static struct kobj_attribute rnbd_clt_access_mode =
...@@ -286,7 +285,7 @@ static struct kobj_attribute rnbd_clt_access_mode = ...@@ -286,7 +285,7 @@ static struct kobj_attribute rnbd_clt_access_mode =
static ssize_t rnbd_clt_unmap_dev_show(struct kobject *kobj, static ssize_t rnbd_clt_unmap_dev_show(struct kobject *kobj,
struct kobj_attribute *attr, char *page) struct kobj_attribute *attr, char *page)
{ {
return scnprintf(page, PAGE_SIZE, "Usage: echo <normal|force> > %s\n", return sysfs_emit(page, "Usage: echo <normal|force> > %s\n",
attr->attr.name); attr->attr.name);
} }
...@@ -357,8 +356,7 @@ static ssize_t rnbd_clt_resize_dev_show(struct kobject *kobj, ...@@ -357,8 +356,7 @@ static ssize_t rnbd_clt_resize_dev_show(struct kobject *kobj,
struct kobj_attribute *attr, struct kobj_attribute *attr,
char *page) char *page)
{ {
return scnprintf(page, PAGE_SIZE, return sysfs_emit(page, "Usage: echo <new size in sectors> > %s\n",
"Usage: echo <new size in sectors> > %s\n",
attr->attr.name); attr->attr.name);
} }
...@@ -390,8 +388,7 @@ static struct kobj_attribute rnbd_clt_resize_dev_attr = ...@@ -390,8 +388,7 @@ static struct kobj_attribute rnbd_clt_resize_dev_attr =
static ssize_t rnbd_clt_remap_dev_show(struct kobject *kobj, static ssize_t rnbd_clt_remap_dev_show(struct kobject *kobj,
struct kobj_attribute *attr, char *page) struct kobj_attribute *attr, char *page)
{ {
return scnprintf(page, PAGE_SIZE, "Usage: echo <1> > %s\n", return sysfs_emit(page, "Usage: echo <1> > %s\n", attr->attr.name);
attr->attr.name);
} }
static ssize_t rnbd_clt_remap_dev_store(struct kobject *kobj, static ssize_t rnbd_clt_remap_dev_store(struct kobject *kobj,
...@@ -436,7 +433,7 @@ static ssize_t session_show(struct kobject *kobj, struct kobj_attribute *attr, ...@@ -436,7 +433,7 @@ static ssize_t session_show(struct kobject *kobj, struct kobj_attribute *attr,
dev = container_of(kobj, struct rnbd_clt_dev, kobj); dev = container_of(kobj, struct rnbd_clt_dev, kobj);
return scnprintf(page, PAGE_SIZE, "%s\n", dev->sess->sessname); return sysfs_emit(page, "%s\n", dev->sess->sessname);
} }
static struct kobj_attribute rnbd_clt_session_attr = static struct kobj_attribute rnbd_clt_session_attr =
...@@ -499,7 +496,7 @@ static ssize_t rnbd_clt_map_device_show(struct kobject *kobj, ...@@ -499,7 +496,7 @@ static ssize_t rnbd_clt_map_device_show(struct kobject *kobj,
struct kobj_attribute *attr, struct kobj_attribute *attr,
char *page) char *page)
{ {
return scnprintf(page, PAGE_SIZE, return sysfs_emit(page,
"Usage: echo \"[dest_port=server port number] sessname=<name of the rtrs session> path=<[srcaddr@]dstaddr> [path=<[srcaddr@]dstaddr>] device_path=<full path on remote side> [access_mode=<ro|rw|migration>] [nr_poll_queues=<number of queues>]\" > %s\n\naddr ::= [ ip:<ipv4> | ip:<ipv6> | gid:<gid> ]\n", "Usage: echo \"[dest_port=server port number] sessname=<name of the rtrs session> path=<[srcaddr@]dstaddr> [path=<[srcaddr@]dstaddr>] device_path=<full path on remote side> [access_mode=<ro|rw|migration>] [nr_poll_queues=<number of queues>]\" > %s\n\naddr ::= [ ip:<ipv4> | ip:<ipv6> | gid:<gid> ]\n",
attr->attr.name); attr->attr.name);
} }
......
...@@ -90,7 +90,7 @@ static ssize_t read_only_show(struct kobject *kobj, struct kobj_attribute *attr, ...@@ -90,7 +90,7 @@ static ssize_t read_only_show(struct kobject *kobj, struct kobj_attribute *attr,
sess_dev = container_of(kobj, struct rnbd_srv_sess_dev, kobj); sess_dev = container_of(kobj, struct rnbd_srv_sess_dev, kobj);
return scnprintf(page, PAGE_SIZE, "%d\n", return sysfs_emit(page, "%d\n",
!(sess_dev->open_flags & FMODE_WRITE)); !(sess_dev->open_flags & FMODE_WRITE));
} }
...@@ -105,7 +105,7 @@ static ssize_t access_mode_show(struct kobject *kobj, ...@@ -105,7 +105,7 @@ static ssize_t access_mode_show(struct kobject *kobj,
sess_dev = container_of(kobj, struct rnbd_srv_sess_dev, kobj); sess_dev = container_of(kobj, struct rnbd_srv_sess_dev, kobj);
return scnprintf(page, PAGE_SIZE, "%s\n", return sysfs_emit(page, "%s\n",
rnbd_access_mode_str(sess_dev->access_mode)); rnbd_access_mode_str(sess_dev->access_mode));
} }
...@@ -119,7 +119,7 @@ static ssize_t mapping_path_show(struct kobject *kobj, ...@@ -119,7 +119,7 @@ static ssize_t mapping_path_show(struct kobject *kobj,
sess_dev = container_of(kobj, struct rnbd_srv_sess_dev, kobj); sess_dev = container_of(kobj, struct rnbd_srv_sess_dev, kobj);
return scnprintf(page, PAGE_SIZE, "%s\n", sess_dev->pathname); return sysfs_emit(page, "%s\n", sess_dev->pathname);
} }
static struct kobj_attribute rnbd_srv_dev_session_mapping_path_attr = static struct kobj_attribute rnbd_srv_dev_session_mapping_path_attr =
...@@ -128,7 +128,7 @@ static struct kobj_attribute rnbd_srv_dev_session_mapping_path_attr = ...@@ -128,7 +128,7 @@ static struct kobj_attribute rnbd_srv_dev_session_mapping_path_attr =
static ssize_t rnbd_srv_dev_session_force_close_show(struct kobject *kobj, static ssize_t rnbd_srv_dev_session_force_close_show(struct kobject *kobj,
struct kobj_attribute *attr, char *page) struct kobj_attribute *attr, char *page)
{ {
return scnprintf(page, PAGE_SIZE, "Usage: echo 1 > %s\n", return sysfs_emit(page, "Usage: echo 1 > %s\n",
attr->attr.name); attr->attr.name);
} }
......
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