diff mbox series

drm/amd/powerplay: fix memdup.cocci warnings

Message ID alpine.DEB.2.21.1903020746130.2572@hadrien (mailing list archive)
State New, archived
Headers show
Series drm/amd/powerplay: fix memdup.cocci warnings | expand

Commit Message

Julia Lawall March 2, 2019, 6:50 a.m. UTC
From: kbuild test robot <fengguang.wu@intel.com>

Simplify the code a bit by using kmemdup instead of kzalloc and memcpy.

Generated by: scripts/coccinelle/api/memdup.cocci

Fixes: 76760fe3c00d ("drm/amd/powerplay: add function to store overdrive information for smu11")
CC: Likun Gao <Likun.Gao@amd.com>
Signed-off-by: kbuild test robot <fengguang.wu@intel.com>
Signed-off-by: Julia Lawall <julia.lawall@lip6.fr>
---

tree:   git://people.freedesktop.org/~agd5f/linux.git drm-next-5.2-wip
head:   25752e1fc83e9f983b11d680fc7bfc129b4eaae6
commit: 76760fe3c00d04f25cc1a6115294310d4effeb77 [161/226] drm/amd/powerplay: add function to store overdrive information for smu11
:::::: branch date: 6 hours ago
:::::: commit date: 6 hours ago

 vega20_ppt.c |   24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)

Comments

Gao, Likun March 4, 2019, 6:50 a.m. UTC | #1
Reviewed-by: Likun Gao <Likun.Gao@amd.com>

-----Original Message-----
From: Julia Lawall <julia.lawall@lip6.fr> 
Sent: Saturday, March 02, 2019 2:51 PM
To: Gao, Likun <Likun.Gao@amd.com>
Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Wang, Kevin(Yang) <Kevin1.Wang@amd.com>; Quan, Evan <Evan.Quan@amd.com>; Koenig, Christian <Christian.Koenig@amd.com>; David Airlie <airlied@linux.ie>; Daniel Vetter <daniel@ffwll.ch>; Huang, Ray <Ray.Huang@amd.com>; amd-gfx@lists.freedesktop.org; kbuild test robot <lkp@intel.com>; dri-devel@lists.freedesktop.org; kbuild-all@01.org
Subject: [PATCH] drm/amd/powerplay: fix memdup.cocci warnings

From: kbuild test robot <fengguang.wu@intel.com>

Simplify the code a bit by using kmemdup instead of kzalloc and memcpy.

Generated by: scripts/coccinelle/api/memdup.cocci

Fixes: 76760fe3c00d ("drm/amd/powerplay: add function to store overdrive information for smu11")
CC: Likun Gao <Likun.Gao@amd.com>
Signed-off-by: kbuild test robot <fengguang.wu@intel.com>
Signed-off-by: Julia Lawall <julia.lawall@lip6.fr>
---

tree:   git://people.freedesktop.org/~agd5f/linux.git drm-next-5.2-wip
head:   25752e1fc83e9f983b11d680fc7bfc129b4eaae6
commit: 76760fe3c00d04f25cc1a6115294310d4effeb77 [161/226] drm/amd/powerplay: add function to store overdrive information for smu11
:::::: branch date: 6 hours ago
:::::: commit date: 6 hours ago

 vega20_ppt.c |   24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)

--- a/drivers/gpu/drm/amd/amdgpu/../powerplay/vega20_ppt.c
+++ b/drivers/gpu/drm/amd/amdgpu/../powerplay/vega20_ppt.c
@@ -173,14 +173,12 @@ static int vega20_setup_od8_information(
 		if (table_context->od_feature_capabilities)
 			return -EINVAL;

-		table_context->od_feature_capabilities = kzalloc(od_feature_array_size, GFP_KERNEL);
+		table_context->od_feature_capabilities = kmemdup(&powerplay_table->OverDrive8Table.ODFeatureCapabilities,
+								 od_feature_array_size,
+								 GFP_KERNEL);
 		if (!table_context->od_feature_capabilities)
 			return -ENOMEM;

-		memcpy(table_context->od_feature_capabilities,
-		       &powerplay_table->OverDrive8Table.ODFeatureCapabilities,
-		       od_feature_array_size);
-
 		/* Setup correct ODSettingCount, and store ODSettingArray from
 		 * powerplay table to od_settings_max and od_setting_min */
 		od_setting_count =
@@ -194,7 +192,9 @@ static int vega20_setup_od8_information(
 		if (table_context->od_settings_max)
 			return -EINVAL;

-		table_context->od_settings_max = kzalloc(od_setting_array_size, GFP_KERNEL);
+		table_context->od_settings_max = kmemdup(&powerplay_table->OverDrive8Table.ODSettingsMax,
+							 od_setting_array_size,
+							 GFP_KERNEL);

 		if (!table_context->od_settings_max) {
 			kfree(table_context->od_feature_capabilities);
@@ -202,14 +202,12 @@ static int vega20_setup_od8_information(
 			return -ENOMEM;
 		}

-		memcpy(table_context->od_settings_max,
-		       &powerplay_table->OverDrive8Table.ODSettingsMax,
-		       od_setting_array_size);
-
 		if (table_context->od_settings_min)
 			return -EINVAL;

-		table_context->od_settings_min = kzalloc(od_setting_array_size, GFP_KERNEL);
+		table_context->od_settings_min = kmemdup(&powerplay_table->OverDrive8Table.ODSettingsMin,
+							 od_setting_array_size,
+							 GFP_KERNEL);

 		if (!table_context->od_settings_min) {
 			kfree(table_context->od_feature_capabilities);
@@ -218,10 +216,6 @@ static int vega20_setup_od8_information(
 			table_context->od_settings_max = NULL;
 			return -ENOMEM;
 		}
-
-		memcpy(table_context->od_settings_min,
-		       &powerplay_table->OverDrive8Table.ODSettingsMin,
-		       od_setting_array_size);
 	}

 	return 0;
Huang Rui March 4, 2019, 8:49 a.m. UTC | #2
>  -----Original Message-----
> From: Julia Lawall [mailto:julia.lawall@lip6.fr]
> Sent: Saturday, March 02, 2019 2:51 PM
> To: Gao, Likun <Likun.Gao@amd.com>
> Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Wang, Kevin(Yang)
> <Kevin1.Wang@amd.com>; Quan, Evan <Evan.Quan@amd.com>; Koenig,
> Christian <Christian.Koenig@amd.com>; David Airlie <airlied@linux.ie>;
> Daniel Vetter <daniel@ffwll.ch>; Huang, Ray <Ray.Huang@amd.com>; amd-
> gfx@lists.freedesktop.org; kbuild test robot <lkp@intel.com>; dri-
> devel@lists.freedesktop.org; kbuild-all@01.org
> Subject: [PATCH] drm/amd/powerplay: fix memdup.cocci warnings
> 
> From: kbuild test robot <fengguang.wu@intel.com>
> 
> Simplify the code a bit by using kmemdup instead of kzalloc and memcpy.
> 
> Generated by: scripts/coccinelle/api/memdup.cocci
> 
> Fixes: 76760fe3c00d ("drm/amd/powerplay: add function to store overdrive
> information for smu11")
> CC: Likun Gao <Likun.Gao@amd.com>
> Signed-off-by: kbuild test robot <fengguang.wu@intel.com>
> Signed-off-by: Julia Lawall <julia.lawall@lip6.fr>

Acked-by: Huang Rui <ray.huang@amd.com>

> ---
> 
> tree:   git://people.freedesktop.org/~agd5f/linux.git drm-next-5.2-wip
> head:   25752e1fc83e9f983b11d680fc7bfc129b4eaae6
> commit: 76760fe3c00d04f25cc1a6115294310d4effeb77 [161/226]
> drm/amd/powerplay: add function to store overdrive information for smu11
> :::::: branch date: 6 hours ago
> :::::: commit date: 6 hours ago
> 
>  vega20_ppt.c |   24 +++++++++---------------
>  1 file changed, 9 insertions(+), 15 deletions(-)
> 
> --- a/drivers/gpu/drm/amd/amdgpu/../powerplay/vega20_ppt.c
> +++ b/drivers/gpu/drm/amd/amdgpu/../powerplay/vega20_ppt.c
> @@ -173,14 +173,12 @@ static int vega20_setup_od8_information(
>  		if (table_context->od_feature_capabilities)
>  			return -EINVAL;
> 
> -		table_context->od_feature_capabilities =
> kzalloc(od_feature_array_size, GFP_KERNEL);
> +		table_context->od_feature_capabilities =
> kmemdup(&powerplay_table->OverDrive8Table.ODFeatureCapabilities,
> +
> od_feature_array_size,
> +
> GFP_KERNEL);
>  		if (!table_context->od_feature_capabilities)
>  			return -ENOMEM;
> 
> -		memcpy(table_context->od_feature_capabilities,
> -		       &powerplay_table-
> >OverDrive8Table.ODFeatureCapabilities,
> -		       od_feature_array_size);
> -
>  		/* Setup correct ODSettingCount, and store ODSettingArray
> from
>  		 * powerplay table to od_settings_max and od_setting_min
> */
>  		od_setting_count =
> @@ -194,7 +192,9 @@ static int vega20_setup_od8_information(
>  		if (table_context->od_settings_max)
>  			return -EINVAL;
> 
> -		table_context->od_settings_max =
> kzalloc(od_setting_array_size, GFP_KERNEL);
> +		table_context->od_settings_max =
> kmemdup(&powerplay_table->OverDrive8Table.ODSettingsMax,
> +
> od_setting_array_size,
> +							 GFP_KERNEL);
> 
>  		if (!table_context->od_settings_max) {
>  			kfree(table_context->od_feature_capabilities);
> @@ -202,14 +202,12 @@ static int vega20_setup_od8_information(
>  			return -ENOMEM;
>  		}
> 
> -		memcpy(table_context->od_settings_max,
> -		       &powerplay_table->OverDrive8Table.ODSettingsMax,
> -		       od_setting_array_size);
> -
>  		if (table_context->od_settings_min)
>  			return -EINVAL;
> 
> -		table_context->od_settings_min =
> kzalloc(od_setting_array_size, GFP_KERNEL);
> +		table_context->od_settings_min =
> kmemdup(&powerplay_table->OverDrive8Table.ODSettingsMin,
> +
> od_setting_array_size,
> +							 GFP_KERNEL);
> 
>  		if (!table_context->od_settings_min) {
>  			kfree(table_context->od_feature_capabilities);
> @@ -218,10 +216,6 @@ static int vega20_setup_od8_information(
>  			table_context->od_settings_max = NULL;
>  			return -ENOMEM;
>  		}
> -
> -		memcpy(table_context->od_settings_min,
> -		       &powerplay_table->OverDrive8Table.ODSettingsMin,
> -		       od_setting_array_size);
>  	}
> 
>  	return 0;
diff mbox series

Patch

--- a/drivers/gpu/drm/amd/amdgpu/../powerplay/vega20_ppt.c
+++ b/drivers/gpu/drm/amd/amdgpu/../powerplay/vega20_ppt.c
@@ -173,14 +173,12 @@  static int vega20_setup_od8_information(
 		if (table_context->od_feature_capabilities)
 			return -EINVAL;

-		table_context->od_feature_capabilities = kzalloc(od_feature_array_size, GFP_KERNEL);
+		table_context->od_feature_capabilities = kmemdup(&powerplay_table->OverDrive8Table.ODFeatureCapabilities,
+								 od_feature_array_size,
+								 GFP_KERNEL);
 		if (!table_context->od_feature_capabilities)
 			return -ENOMEM;

-		memcpy(table_context->od_feature_capabilities,
-		       &powerplay_table->OverDrive8Table.ODFeatureCapabilities,
-		       od_feature_array_size);
-
 		/* Setup correct ODSettingCount, and store ODSettingArray from
 		 * powerplay table to od_settings_max and od_setting_min */
 		od_setting_count =
@@ -194,7 +192,9 @@  static int vega20_setup_od8_information(
 		if (table_context->od_settings_max)
 			return -EINVAL;

-		table_context->od_settings_max = kzalloc(od_setting_array_size, GFP_KERNEL);
+		table_context->od_settings_max = kmemdup(&powerplay_table->OverDrive8Table.ODSettingsMax,
+							 od_setting_array_size,
+							 GFP_KERNEL);

 		if (!table_context->od_settings_max) {
 			kfree(table_context->od_feature_capabilities);
@@ -202,14 +202,12 @@  static int vega20_setup_od8_information(
 			return -ENOMEM;
 		}

-		memcpy(table_context->od_settings_max,
-		       &powerplay_table->OverDrive8Table.ODSettingsMax,
-		       od_setting_array_size);
-
 		if (table_context->od_settings_min)
 			return -EINVAL;

-		table_context->od_settings_min = kzalloc(od_setting_array_size, GFP_KERNEL);
+		table_context->od_settings_min = kmemdup(&powerplay_table->OverDrive8Table.ODSettingsMin,
+							 od_setting_array_size,
+							 GFP_KERNEL);

 		if (!table_context->od_settings_min) {
 			kfree(table_context->od_feature_capabilities);
@@ -218,10 +216,6 @@  static int vega20_setup_od8_information(
 			table_context->od_settings_max = NULL;
 			return -ENOMEM;
 		}
-
-		memcpy(table_context->od_settings_min,
-		       &powerplay_table->OverDrive8Table.ODSettingsMin,
-		       od_setting_array_size);
 	}

 	return 0;