linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next 1/3] fail_function: Switch to memdup_user_nul() helper
@ 2022-08-26  7:33 Yang Yingliang
  2022-08-26  7:33 ` [PATCH -next 2/3] fail_function: refctor code of checking return value of register_kprobe() Yang Yingliang
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Yang Yingliang @ 2022-08-26  7:33 UTC (permalink / raw)
  To: linux-kernel; +Cc: mhiramat, ast, jbacik, akpm

Use memdup_user_nul() helper instead of open-coding to
simplify the code.

Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 kernel/fail_function.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/kernel/fail_function.c b/kernel/fail_function.c
index 60dc825ecc2b..03643e33e4c3 100644
--- a/kernel/fail_function.c
+++ b/kernel/fail_function.c
@@ -247,15 +247,11 @@ static ssize_t fei_write(struct file *file, const char __user *buffer,
 	/* cut off if it is too long */
 	if (count > KSYM_NAME_LEN)
 		count = KSYM_NAME_LEN;
-	buf = kmalloc(count + 1, GFP_KERNEL);
-	if (!buf)
-		return -ENOMEM;
 
-	if (copy_from_user(buf, buffer, count)) {
-		ret = -EFAULT;
-		goto out_free;
-	}
-	buf[count] = '\0';
+	buf = memdup_user_nul(buffer, count);
+	if (IS_ERR(buf))
+		return PTR_ERR(buf);
+
 	sym = strstrip(buf);
 
 	mutex_lock(&fei_lock);
@@ -308,7 +304,6 @@ static ssize_t fei_write(struct file *file, const char __user *buffer,
 	}
 out:
 	mutex_unlock(&fei_lock);
-out_free:
 	kfree(buf);
 	return ret;
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH -next 2/3] fail_function: refctor code of checking return value of register_kprobe()
  2022-08-26  7:33 [PATCH -next 1/3] fail_function: Switch to memdup_user_nul() helper Yang Yingliang
@ 2022-08-26  7:33 ` Yang Yingliang
  2022-09-12  9:37   ` Masami Hiramatsu
  2022-08-26  7:33 ` [PATCH -next 3/3] fail_function: fix wrong use of fei_attr_remove() Yang Yingliang
  2022-09-12  9:37 ` [PATCH -next 1/3] fail_function: Switch to memdup_user_nul() helper Masami Hiramatsu
  2 siblings, 1 reply; 5+ messages in thread
From: Yang Yingliang @ 2022-08-26  7:33 UTC (permalink / raw)
  To: linux-kernel; +Cc: mhiramat, ast, jbacik, akpm

Refactor the error handling of register_kprobe() to improve readability.
No functional change.

Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 kernel/fail_function.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/kernel/fail_function.c b/kernel/fail_function.c
index 03643e33e4c3..893e8f9a9118 100644
--- a/kernel/fail_function.c
+++ b/kernel/fail_function.c
@@ -294,14 +294,13 @@ static ssize_t fei_write(struct file *file, const char __user *buffer,
 	}
 
 	ret = register_kprobe(&attr->kp);
-	if (!ret)
-		fei_debugfs_add_attr(attr);
-	if (ret < 0)
+	if (ret) {
 		fei_attr_remove(attr);
-	else {
-		list_add_tail(&attr->list, &fei_attr_list);
-		ret = count;
+		goto out;
 	}
+	fei_debugfs_add_attr(attr);
+	list_add_tail(&attr->list, &fei_attr_list);
+	ret = count;
 out:
 	mutex_unlock(&fei_lock);
 	kfree(buf);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH -next 3/3] fail_function: fix wrong use of fei_attr_remove()
  2022-08-26  7:33 [PATCH -next 1/3] fail_function: Switch to memdup_user_nul() helper Yang Yingliang
  2022-08-26  7:33 ` [PATCH -next 2/3] fail_function: refctor code of checking return value of register_kprobe() Yang Yingliang
@ 2022-08-26  7:33 ` Yang Yingliang
  2022-09-12  9:37 ` [PATCH -next 1/3] fail_function: Switch to memdup_user_nul() helper Masami Hiramatsu
  2 siblings, 0 replies; 5+ messages in thread
From: Yang Yingliang @ 2022-08-26  7:33 UTC (permalink / raw)
  To: linux-kernel; +Cc: mhiramat, ast, jbacik, akpm

If register_kprobe() fails, the new attr is not added to the list yet,
so it should call fei_attr_free() intstead.

Fixes: 4b1a29a7f542 ("error-injection: Support fault injection framework")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 kernel/fail_function.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/fail_function.c b/kernel/fail_function.c
index 893e8f9a9118..a7ccd2930c5f 100644
--- a/kernel/fail_function.c
+++ b/kernel/fail_function.c
@@ -295,7 +295,7 @@ static ssize_t fei_write(struct file *file, const char __user *buffer,
 
 	ret = register_kprobe(&attr->kp);
 	if (ret) {
-		fei_attr_remove(attr);
+		fei_attr_free(attr);
 		goto out;
 	}
 	fei_debugfs_add_attr(attr);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH -next 2/3] fail_function: refctor code of checking return value of register_kprobe()
  2022-08-26  7:33 ` [PATCH -next 2/3] fail_function: refctor code of checking return value of register_kprobe() Yang Yingliang
@ 2022-09-12  9:37   ` Masami Hiramatsu
  0 siblings, 0 replies; 5+ messages in thread
From: Masami Hiramatsu @ 2022-09-12  9:37 UTC (permalink / raw)
  To: Yang Yingliang; +Cc: linux-kernel, mhiramat, ast, jbacik, akpm

On Fri, 26 Aug 2022 15:33:36 +0800
Yang Yingliang <yangyingliang@huawei.com> wrote:

> Refactor the error handling of register_kprobe() to improve readability.
> No functional change.
> 
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>

OK, but in this case, could you fold [2/3] and [3/3], because
[3/3] can not be applied without this change.

Thank you,

> ---
>  kernel/fail_function.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/kernel/fail_function.c b/kernel/fail_function.c
> index 03643e33e4c3..893e8f9a9118 100644
> --- a/kernel/fail_function.c
> +++ b/kernel/fail_function.c
> @@ -294,14 +294,13 @@ static ssize_t fei_write(struct file *file, const char __user *buffer,
>  	}
>  
>  	ret = register_kprobe(&attr->kp);
> -	if (!ret)
> -		fei_debugfs_add_attr(attr);
> -	if (ret < 0)
> +	if (ret) {
>  		fei_attr_remove(attr);
> -	else {
> -		list_add_tail(&attr->list, &fei_attr_list);
> -		ret = count;
> +		goto out;
>  	}
> +	fei_debugfs_add_attr(attr);
> +	list_add_tail(&attr->list, &fei_attr_list);
> +	ret = count;
>  out:
>  	mutex_unlock(&fei_lock);
>  	kfree(buf);
> -- 
> 2.25.1
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH -next 1/3] fail_function: Switch to memdup_user_nul() helper
  2022-08-26  7:33 [PATCH -next 1/3] fail_function: Switch to memdup_user_nul() helper Yang Yingliang
  2022-08-26  7:33 ` [PATCH -next 2/3] fail_function: refctor code of checking return value of register_kprobe() Yang Yingliang
  2022-08-26  7:33 ` [PATCH -next 3/3] fail_function: fix wrong use of fei_attr_remove() Yang Yingliang
@ 2022-09-12  9:37 ` Masami Hiramatsu
  2 siblings, 0 replies; 5+ messages in thread
From: Masami Hiramatsu @ 2022-09-12  9:37 UTC (permalink / raw)
  To: Yang Yingliang; +Cc: linux-kernel, mhiramat, ast, jbacik, akpm

On Fri, 26 Aug 2022 15:33:35 +0800
Yang Yingliang <yangyingliang@huawei.com> wrote:

> Use memdup_user_nul() helper instead of open-coding to
> simplify the code.
> 
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>

Looks good to me.

Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Thank you!

> ---
>  kernel/fail_function.c | 13 ++++---------
>  1 file changed, 4 insertions(+), 9 deletions(-)
> 
> diff --git a/kernel/fail_function.c b/kernel/fail_function.c
> index 60dc825ecc2b..03643e33e4c3 100644
> --- a/kernel/fail_function.c
> +++ b/kernel/fail_function.c
> @@ -247,15 +247,11 @@ static ssize_t fei_write(struct file *file, const char __user *buffer,
>  	/* cut off if it is too long */
>  	if (count > KSYM_NAME_LEN)
>  		count = KSYM_NAME_LEN;
> -	buf = kmalloc(count + 1, GFP_KERNEL);
> -	if (!buf)
> -		return -ENOMEM;
>  
> -	if (copy_from_user(buf, buffer, count)) {
> -		ret = -EFAULT;
> -		goto out_free;
> -	}
> -	buf[count] = '\0';
> +	buf = memdup_user_nul(buffer, count);
> +	if (IS_ERR(buf))
> +		return PTR_ERR(buf);
> +
>  	sym = strstrip(buf);
>  
>  	mutex_lock(&fei_lock);
> @@ -308,7 +304,6 @@ static ssize_t fei_write(struct file *file, const char __user *buffer,
>  	}
>  out:
>  	mutex_unlock(&fei_lock);
> -out_free:
>  	kfree(buf);
>  	return ret;
>  }
> -- 
> 2.25.1
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-09-12  9:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-26  7:33 [PATCH -next 1/3] fail_function: Switch to memdup_user_nul() helper Yang Yingliang
2022-08-26  7:33 ` [PATCH -next 2/3] fail_function: refctor code of checking return value of register_kprobe() Yang Yingliang
2022-09-12  9:37   ` Masami Hiramatsu
2022-08-26  7:33 ` [PATCH -next 3/3] fail_function: fix wrong use of fei_attr_remove() Yang Yingliang
2022-09-12  9:37 ` [PATCH -next 1/3] fail_function: Switch to memdup_user_nul() helper Masami Hiramatsu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).