diff mbox series

[-next] drm/msm/adreno: Switch to memdup_user_nul() helper

Message ID 20220826084524.2217022-1-yangyingliang@huawei.com
State New
Headers show
Series [-next] drm/msm/adreno: Switch to memdup_user_nul() helper | expand

Commit Message

Yang Yingliang Aug. 26, 2022, 8:45 a.m. UTC
Use memdup_user_nul() helper instead of open-coding to
simplify the code.

Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/gpu/drm/msm/adreno/adreno_gpu.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

Comments

Dmitry Baryshkov Aug. 26, 2022, 10:12 a.m. UTC | #1
On 26/08/2022 11:45, Yang Yingliang wrote:
> Use memdup_user_nul() helper instead of open-coding to
> simplify the code.
> 
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>

Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>

> ---
>   drivers/gpu/drm/msm/adreno/adreno_gpu.c | 14 +++-----------
>   1 file changed, 3 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/gpu/drm/msm/adreno/adreno_gpu.c b/drivers/gpu/drm/msm/adreno/adreno_gpu.c
> index 382fb7f9e497..50b33e14237b 100644
> --- a/drivers/gpu/drm/msm/adreno/adreno_gpu.c
> +++ b/drivers/gpu/drm/msm/adreno/adreno_gpu.c
> @@ -339,17 +339,9 @@ int adreno_set_param(struct msm_gpu *gpu, struct msm_file_private *ctx,
>   	case MSM_PARAM_CMDLINE: {
>   		char *str, **paramp;
>   
> -		str = kmalloc(len + 1, GFP_KERNEL);
> -		if (!str)
> -			return -ENOMEM;
> -
> -		if (copy_from_user(str, u64_to_user_ptr(value), len)) {
> -			kfree(str);
> -			return -EFAULT;
> -		}
> -
> -		/* Ensure string is null terminated: */
> -		str[len] = '\0';
> +		str = memdup_user_nul(u64_to_user_ptr(value), len);
> +		if (IS_ERR(str))
> +			return PTR_ERR(str);
>   
>   		if (param == MSM_PARAM_COMM) {
>   			paramp = &ctx->comm;
diff mbox series

Patch

diff --git a/drivers/gpu/drm/msm/adreno/adreno_gpu.c b/drivers/gpu/drm/msm/adreno/adreno_gpu.c
index 382fb7f9e497..50b33e14237b 100644
--- a/drivers/gpu/drm/msm/adreno/adreno_gpu.c
+++ b/drivers/gpu/drm/msm/adreno/adreno_gpu.c
@@ -339,17 +339,9 @@  int adreno_set_param(struct msm_gpu *gpu, struct msm_file_private *ctx,
 	case MSM_PARAM_CMDLINE: {
 		char *str, **paramp;
 
-		str = kmalloc(len + 1, GFP_KERNEL);
-		if (!str)
-			return -ENOMEM;
-
-		if (copy_from_user(str, u64_to_user_ptr(value), len)) {
-			kfree(str);
-			return -EFAULT;
-		}
-
-		/* Ensure string is null terminated: */
-		str[len] = '\0';
+		str = memdup_user_nul(u64_to_user_ptr(value), len);
+		if (IS_ERR(str))
+			return PTR_ERR(str);
 
 		if (param == MSM_PARAM_COMM) {
 			paramp = &ctx->comm;