All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amd/powerplay: remove unnecessary call to memset
@ 2017-09-11 12:37 Himanshu Jha
  2017-09-11 21:27   ` Alex Deucher
  0 siblings, 1 reply; 3+ messages in thread
From: Himanshu Jha @ 2017-09-11 12:37 UTC (permalink / raw)
  To: airlied
  Cc: christian.koenig, alexander.deucher, Rex.Zhu, amd-gfx, dri-devel,
	linux-kernel, Himanshu Jha

call to memset to assign 0 value immediately after allocating
memory with kzalloc is unnecesaary as kzalloc allocates the memory
filled with 0 value.

Semantic patch used to resolve this issue:

@@
expression e,e2; constant c;
statement S;
@@

  e = kzalloc(e2, c);
  if(e == NULL) S
- memset(e, 0, e2);

Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
---
 .../drm/amd/powerplay/hwmgr/process_pptables_v1_0.c  | 20 --------------------
 1 file changed, 20 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/process_pptables_v1_0.c b/drivers/gpu/drm/amd/powerplay/hwmgr/process_pptables_v1_0.c
index 84f01fd3..d1af148 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/process_pptables_v1_0.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/process_pptables_v1_0.c
@@ -173,8 +173,6 @@ static int get_vddc_lookup_table(
 	if (NULL == table)
 		return -ENOMEM;
 
-	memset(table, 0x00, table_size);
-
 	table->count = vddc_lookup_pp_tables->ucNumEntries;
 
 	for (i = 0; i < vddc_lookup_pp_tables->ucNumEntries; i++) {
@@ -335,8 +333,6 @@ static int get_valid_clk(
 	if (NULL == table)
 		return -ENOMEM;
 
-	memset(table, 0x00, table_size);
-
 	table->count = (uint32_t)clk_volt_pp_table->count;
 
 	for (i = 0; i < table->count; i++) {
@@ -390,8 +386,6 @@ static int get_mclk_voltage_dependency_table(
 	if (NULL == mclk_table)
 		return -ENOMEM;
 
-	memset(mclk_table, 0x00, table_size);
-
 	mclk_table->count = (uint32_t)mclk_dep_table->ucNumEntries;
 
 	for (i = 0; i < mclk_dep_table->ucNumEntries; i++) {
@@ -439,8 +433,6 @@ static int get_sclk_voltage_dependency_table(
 		if (NULL == sclk_table)
 			return -ENOMEM;
 
-		memset(sclk_table, 0x00, table_size);
-
 		sclk_table->count = (uint32_t)tonga_table->ucNumEntries;
 
 		for (i = 0; i < tonga_table->ucNumEntries; i++) {
@@ -473,8 +465,6 @@ static int get_sclk_voltage_dependency_table(
 		if (NULL == sclk_table)
 			return -ENOMEM;
 
-		memset(sclk_table, 0x00, table_size);
-
 		sclk_table->count = (uint32_t)polaris_table->ucNumEntries;
 
 		for (i = 0; i < polaris_table->ucNumEntries; i++) {
@@ -525,8 +515,6 @@ static int get_pcie_table(
 		if (pcie_table == NULL)
 			return -ENOMEM;
 
-		memset(pcie_table, 0x00, table_size);
-
 		/*
 		* Make sure the number of pcie entries are less than or equal to sclk dpm levels.
 		* Since first PCIE entry is for ULV, #pcie has to be <= SclkLevel + 1.
@@ -567,8 +555,6 @@ static int get_pcie_table(
 		if (pcie_table == NULL)
 			return -ENOMEM;
 
-		memset(pcie_table, 0x00, table_size);
-
 		/*
 		* Make sure the number of pcie entries are less than or equal to sclk dpm levels.
 		* Since first PCIE entry is for ULV, #pcie has to be <= SclkLevel + 1.
@@ -615,8 +601,6 @@ static int get_cac_tdp_table(
 	if (NULL == tdp_table)
 		return -ENOMEM;
 
-	memset(tdp_table, 0x00, table_size);
-
 	hwmgr->dyn_state.cac_dtp_table = kzalloc(table_size, GFP_KERNEL);
 
 	if (NULL == hwmgr->dyn_state.cac_dtp_table) {
@@ -624,8 +608,6 @@ static int get_cac_tdp_table(
 		return -ENOMEM;
 	}
 
-	memset(hwmgr->dyn_state.cac_dtp_table, 0x00, table_size);
-
 	if (table->ucRevId < 3) {
 		const ATOM_Tonga_PowerTune_Table *tonga_table =
 			(ATOM_Tonga_PowerTune_Table *)table;
@@ -725,8 +707,6 @@ static int get_mm_clock_voltage_table(
 	if (NULL == mm_table)
 		return -ENOMEM;
 
-	memset(mm_table, 0x00, table_size);
-
 	mm_table->count = mm_dependency_table->ucNumEntries;
 
 	for (i = 0; i < mm_dependency_table->ucNumEntries; i++) {
-- 
2.7.4

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

* Re: [PATCH] drm/amd/powerplay: remove unnecessary call to memset
  2017-09-11 12:37 [PATCH] drm/amd/powerplay: remove unnecessary call to memset Himanshu Jha
@ 2017-09-11 21:27   ` Alex Deucher
  0 siblings, 0 replies; 3+ messages in thread
From: Alex Deucher @ 2017-09-11 21:27 UTC (permalink / raw)
  To: Himanshu Jha
  Cc: Dave Airlie, LKML, Maling list - DRI developers, amd-gfx list,
	Deucher, Alexander, Rex Zhu, Christian Koenig

On Mon, Sep 11, 2017 at 8:37 AM, Himanshu Jha
<himanshujha199640@gmail.com> wrote:
> call to memset to assign 0 value immediately after allocating
> memory with kzalloc is unnecesaary as kzalloc allocates the memory
> filled with 0 value.
>
> Semantic patch used to resolve this issue:
>
> @@
> expression e,e2; constant c;
> statement S;
> @@
>
>   e = kzalloc(e2, c);
>   if(e == NULL) S
> - memset(e, 0, e2);
>
> Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>

Applied.

Thanks!

Alex

> ---
>  .../drm/amd/powerplay/hwmgr/process_pptables_v1_0.c  | 20 --------------------
>  1 file changed, 20 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/process_pptables_v1_0.c b/drivers/gpu/drm/amd/powerplay/hwmgr/process_pptables_v1_0.c
> index 84f01fd3..d1af148 100644
> --- a/drivers/gpu/drm/amd/powerplay/hwmgr/process_pptables_v1_0.c
> +++ b/drivers/gpu/drm/amd/powerplay/hwmgr/process_pptables_v1_0.c
> @@ -173,8 +173,6 @@ static int get_vddc_lookup_table(
>         if (NULL == table)
>                 return -ENOMEM;
>
> -       memset(table, 0x00, table_size);
> -
>         table->count = vddc_lookup_pp_tables->ucNumEntries;
>
>         for (i = 0; i < vddc_lookup_pp_tables->ucNumEntries; i++) {
> @@ -335,8 +333,6 @@ static int get_valid_clk(
>         if (NULL == table)
>                 return -ENOMEM;
>
> -       memset(table, 0x00, table_size);
> -
>         table->count = (uint32_t)clk_volt_pp_table->count;
>
>         for (i = 0; i < table->count; i++) {
> @@ -390,8 +386,6 @@ static int get_mclk_voltage_dependency_table(
>         if (NULL == mclk_table)
>                 return -ENOMEM;
>
> -       memset(mclk_table, 0x00, table_size);
> -
>         mclk_table->count = (uint32_t)mclk_dep_table->ucNumEntries;
>
>         for (i = 0; i < mclk_dep_table->ucNumEntries; i++) {
> @@ -439,8 +433,6 @@ static int get_sclk_voltage_dependency_table(
>                 if (NULL == sclk_table)
>                         return -ENOMEM;
>
> -               memset(sclk_table, 0x00, table_size);
> -
>                 sclk_table->count = (uint32_t)tonga_table->ucNumEntries;
>
>                 for (i = 0; i < tonga_table->ucNumEntries; i++) {
> @@ -473,8 +465,6 @@ static int get_sclk_voltage_dependency_table(
>                 if (NULL == sclk_table)
>                         return -ENOMEM;
>
> -               memset(sclk_table, 0x00, table_size);
> -
>                 sclk_table->count = (uint32_t)polaris_table->ucNumEntries;
>
>                 for (i = 0; i < polaris_table->ucNumEntries; i++) {
> @@ -525,8 +515,6 @@ static int get_pcie_table(
>                 if (pcie_table == NULL)
>                         return -ENOMEM;
>
> -               memset(pcie_table, 0x00, table_size);
> -
>                 /*
>                 * Make sure the number of pcie entries are less than or equal to sclk dpm levels.
>                 * Since first PCIE entry is for ULV, #pcie has to be <= SclkLevel + 1.
> @@ -567,8 +555,6 @@ static int get_pcie_table(
>                 if (pcie_table == NULL)
>                         return -ENOMEM;
>
> -               memset(pcie_table, 0x00, table_size);
> -
>                 /*
>                 * Make sure the number of pcie entries are less than or equal to sclk dpm levels.
>                 * Since first PCIE entry is for ULV, #pcie has to be <= SclkLevel + 1.
> @@ -615,8 +601,6 @@ static int get_cac_tdp_table(
>         if (NULL == tdp_table)
>                 return -ENOMEM;
>
> -       memset(tdp_table, 0x00, table_size);
> -
>         hwmgr->dyn_state.cac_dtp_table = kzalloc(table_size, GFP_KERNEL);
>
>         if (NULL == hwmgr->dyn_state.cac_dtp_table) {
> @@ -624,8 +608,6 @@ static int get_cac_tdp_table(
>                 return -ENOMEM;
>         }
>
> -       memset(hwmgr->dyn_state.cac_dtp_table, 0x00, table_size);
> -
>         if (table->ucRevId < 3) {
>                 const ATOM_Tonga_PowerTune_Table *tonga_table =
>                         (ATOM_Tonga_PowerTune_Table *)table;
> @@ -725,8 +707,6 @@ static int get_mm_clock_voltage_table(
>         if (NULL == mm_table)
>                 return -ENOMEM;
>
> -       memset(mm_table, 0x00, table_size);
> -
>         mm_table->count = mm_dependency_table->ucNumEntries;
>
>         for (i = 0; i < mm_dependency_table->ucNumEntries; i++) {
> --
> 2.7.4
>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

* Re: [PATCH] drm/amd/powerplay: remove unnecessary call to memset
@ 2017-09-11 21:27   ` Alex Deucher
  0 siblings, 0 replies; 3+ messages in thread
From: Alex Deucher @ 2017-09-11 21:27 UTC (permalink / raw)
  To: Himanshu Jha
  Cc: LKML, amd-gfx list, Maling list - DRI developers, Deucher,
	Alexander, Rex Zhu, Christian Koenig

On Mon, Sep 11, 2017 at 8:37 AM, Himanshu Jha
<himanshujha199640@gmail.com> wrote:
> call to memset to assign 0 value immediately after allocating
> memory with kzalloc is unnecesaary as kzalloc allocates the memory
> filled with 0 value.
>
> Semantic patch used to resolve this issue:
>
> @@
> expression e,e2; constant c;
> statement S;
> @@
>
>   e = kzalloc(e2, c);
>   if(e == NULL) S
> - memset(e, 0, e2);
>
> Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>

Applied.

Thanks!

Alex

> ---
>  .../drm/amd/powerplay/hwmgr/process_pptables_v1_0.c  | 20 --------------------
>  1 file changed, 20 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/process_pptables_v1_0.c b/drivers/gpu/drm/amd/powerplay/hwmgr/process_pptables_v1_0.c
> index 84f01fd3..d1af148 100644
> --- a/drivers/gpu/drm/amd/powerplay/hwmgr/process_pptables_v1_0.c
> +++ b/drivers/gpu/drm/amd/powerplay/hwmgr/process_pptables_v1_0.c
> @@ -173,8 +173,6 @@ static int get_vddc_lookup_table(
>         if (NULL == table)
>                 return -ENOMEM;
>
> -       memset(table, 0x00, table_size);
> -
>         table->count = vddc_lookup_pp_tables->ucNumEntries;
>
>         for (i = 0; i < vddc_lookup_pp_tables->ucNumEntries; i++) {
> @@ -335,8 +333,6 @@ static int get_valid_clk(
>         if (NULL == table)
>                 return -ENOMEM;
>
> -       memset(table, 0x00, table_size);
> -
>         table->count = (uint32_t)clk_volt_pp_table->count;
>
>         for (i = 0; i < table->count; i++) {
> @@ -390,8 +386,6 @@ static int get_mclk_voltage_dependency_table(
>         if (NULL == mclk_table)
>                 return -ENOMEM;
>
> -       memset(mclk_table, 0x00, table_size);
> -
>         mclk_table->count = (uint32_t)mclk_dep_table->ucNumEntries;
>
>         for (i = 0; i < mclk_dep_table->ucNumEntries; i++) {
> @@ -439,8 +433,6 @@ static int get_sclk_voltage_dependency_table(
>                 if (NULL == sclk_table)
>                         return -ENOMEM;
>
> -               memset(sclk_table, 0x00, table_size);
> -
>                 sclk_table->count = (uint32_t)tonga_table->ucNumEntries;
>
>                 for (i = 0; i < tonga_table->ucNumEntries; i++) {
> @@ -473,8 +465,6 @@ static int get_sclk_voltage_dependency_table(
>                 if (NULL == sclk_table)
>                         return -ENOMEM;
>
> -               memset(sclk_table, 0x00, table_size);
> -
>                 sclk_table->count = (uint32_t)polaris_table->ucNumEntries;
>
>                 for (i = 0; i < polaris_table->ucNumEntries; i++) {
> @@ -525,8 +515,6 @@ static int get_pcie_table(
>                 if (pcie_table == NULL)
>                         return -ENOMEM;
>
> -               memset(pcie_table, 0x00, table_size);
> -
>                 /*
>                 * Make sure the number of pcie entries are less than or equal to sclk dpm levels.
>                 * Since first PCIE entry is for ULV, #pcie has to be <= SclkLevel + 1.
> @@ -567,8 +555,6 @@ static int get_pcie_table(
>                 if (pcie_table == NULL)
>                         return -ENOMEM;
>
> -               memset(pcie_table, 0x00, table_size);
> -
>                 /*
>                 * Make sure the number of pcie entries are less than or equal to sclk dpm levels.
>                 * Since first PCIE entry is for ULV, #pcie has to be <= SclkLevel + 1.
> @@ -615,8 +601,6 @@ static int get_cac_tdp_table(
>         if (NULL == tdp_table)
>                 return -ENOMEM;
>
> -       memset(tdp_table, 0x00, table_size);
> -
>         hwmgr->dyn_state.cac_dtp_table = kzalloc(table_size, GFP_KERNEL);
>
>         if (NULL == hwmgr->dyn_state.cac_dtp_table) {
> @@ -624,8 +608,6 @@ static int get_cac_tdp_table(
>                 return -ENOMEM;
>         }
>
> -       memset(hwmgr->dyn_state.cac_dtp_table, 0x00, table_size);
> -
>         if (table->ucRevId < 3) {
>                 const ATOM_Tonga_PowerTune_Table *tonga_table =
>                         (ATOM_Tonga_PowerTune_Table *)table;
> @@ -725,8 +707,6 @@ static int get_mm_clock_voltage_table(
>         if (NULL == mm_table)
>                 return -ENOMEM;
>
> -       memset(mm_table, 0x00, table_size);
> -
>         mm_table->count = mm_dependency_table->ucNumEntries;
>
>         for (i = 0; i < mm_dependency_table->ucNumEntries; i++) {
> --
> 2.7.4
>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

end of thread, other threads:[~2017-09-11 21:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-11 12:37 [PATCH] drm/amd/powerplay: remove unnecessary call to memset Himanshu Jha
2017-09-11 21:27 ` Alex Deucher
2017-09-11 21:27   ` Alex Deucher

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.