Skip to contentSkip to conversation

kernel: trace: blktrace: remove redundent memcpy() in compat_blk_trace_setup()

PATCH In review Chen Gang 3 participants 6 messages Nov 3, 2013 – Nov 4, 2013

Subsystems (2)
lore
Share & tools
lore

Chen Gang

author
#0 lore raw

PATCH 1/1 kernel: trace: blktrace: remove redundent memcpy() in compat_blk_trace_setup()

do_blk_trace_setup() will fully initialize 'buts.name', so can remove the related memcpy(). And also use BLKTRACE_BDEV_SIZE and ARRAY_SIZE instead of hard code number '32'.

---
 include/linux/blktrace_api.h |    2 +-
 kernel/trace/blktrace.c      |    3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)
include/linux/blktrace_api.h +1 -1
index a12f6ed..afc1343 100644
@@ -89,7 +89,7 @@ static inline int blk_trace_init_sysfs(struct device *dev)
 #ifdef CONFIG_COMPAT
 
 struct compat_blk_user_trace_setup {
-	char name[32];
+	char name[BLKTRACE_BDEV_SIZE];
 	u16 act_mask;
 	u32 buf_size;
 	u32 buf_nr;
kernel/trace/blktrace.c +1 -2
index 7f727b3..f785aef 100644
@@ -579,13 +579,12 @@ static int compat_blk_trace_setup(struct request_queue *q, char *name,
 		.end_lba = cbuts.end_lba,
 		.pid = cbuts.pid,
 	};
-	memcpy(&buts.name, &cbuts.name, 32);
 
 	ret = do_blk_trace_setup(q, name, dev, bdev, &buts);
 	if (ret)
 		return ret;
 
-	if (copy_to_user(arg, &buts.name, 32)) {
+	if (copy_to_user(arg, &buts.name, ARRAY_SIZE(buts.name))) {
 		blk_trace_remove(q);
 		return -EFAULT;
 	}
Signature · 1 line
1.7.7.6
maintainer
#1 lore raw

A quick review of this patch looks fine to me.

Although, using ARRAY_SIZE() for a character string seems to me a bit over paranoid. But I'm fine with it, as it makes sure that the string is an array and not a pointer.

Jens,

Can you give me an Acked-by?

-- Steve

Quoted 43 lines · On Sun, 03 Nov 2013 22:23:39 +0800 Chen Gang <[email protected]> wrote:

do_blk_trace_setup() will fully initialize 'buts.name', so can remove the related memcpy(). And also use BLKTRACE_BDEV_SIZE and ARRAY_SIZE instead of hard code number '32'.

---
 include/linux/blktrace_api.h |    2 +-
 kernel/trace/blktrace.c      |    3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)
include/linux/blktrace_api.h +1 -1
index a12f6ed..afc1343 100644
@@ -89,7 +89,7 @@ static inline int blk_trace_init_sysfs(struct device *dev)
 #ifdef CONFIG_COMPAT
 
 struct compat_blk_user_trace_setup {
-	char name[32];
+	char name[BLKTRACE_BDEV_SIZE];
 	u16 act_mask;
 	u32 buf_size;
 	u32 buf_nr;
kernel/trace/blktrace.c +1 -2
index 7f727b3..f785aef 100644
@@ -579,13 +579,12 @@ static int compat_blk_trace_setup(struct request_queue *q, char *name,
 		.end_lba = cbuts.end_lba,
 		.pid = cbuts.pid,
 	};
-	memcpy(&buts.name, &cbuts.name, 32);
 
 	ret = do_blk_trace_setup(q, name, dev, bdev, &buts);
 	if (ret)
 		return ret;
 
-	if (copy_to_user(arg, &buts.name, 32)) {
+	if (copy_to_user(arg, &buts.name, ARRAY_SIZE(buts.name))) {
 		blk_trace_remove(q);
 		return -EFAULT;
 	}
maintainer
#2 lore raw
Quoted 9 lines · Steven Rostedt

A quick review of this patch looks fine to me.

Although, using ARRAY_SIZE() for a character string seems to me a bit over paranoid. But I'm fine with it, as it makes sure that the string is an array and not a pointer.

Jens,

Can you give me an Acked-by?

Thanks, but I'll just queue it up with the other block bits for 3.13.

Signature · 1 line
Jens Axboe
maintainer
#3 lore raw
Quoted 2 lines · On Sun, 3 Nov 2013 11:16:39 -0700 Jens Axboe <[email protected]> wrote:

Thanks, but I'll just queue it up with the other block bits for 3.13.

OK,

-- Steve

author
#4 lore raw
Quoted 8 lines · Steven Rostedt
Quoted 2 lines · On Sun, 3 Nov 2013 11:16:39 -0700 Jens Axboe <[email protected]> wrote:

Thanks, but I'll just queue it up with the other block bits for 3.13.

OK,

Thank all of you. :-)

Signature · 1 line
Chen Gang
author
#5 lore raw
In reply to Steven Rostedt
Quoted 6 lines · Steven Rostedt

A quick review of this patch looks fine to me.

Although, using ARRAY_SIZE() for a character string seems to me a bit over paranoid. But I'm fine with it, as it makes sure that the string is an array and not a pointer.

Yeah.

Quoted 4 lines

Jens,

Can you give me an Acked-by?

I am glad to.

Thanks.

Signature · 1 line
Chen Gang