diff mbox series

[-next] drm/amd/display: use swap() in sort()

Message ID 20240724073749.14338-1-jiapeng.chong@linux.alibaba.com (mailing list archive)
State New, archived
Headers show
Series [-next] drm/amd/display: use swap() in sort() | expand

Commit Message

Jiapeng Chong July 24, 2024, 7:37 a.m. UTC
Use existing swap() function rather than duplicating its implementation.

./drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c:17:29-30: WARNING opportunity for swap().

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=9573
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
---
 .../display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c    | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

Comments

Alex Deucher July 24, 2024, 4:55 p.m. UTC | #1
Applied.  Thanks!

Alex

On Wed, Jul 24, 2024 at 3:38 AM Jiapeng Chong
<jiapeng.chong@linux.alibaba.com> wrote:
>
> Use existing swap() function rather than duplicating its implementation.
>
> ./drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c:17:29-30: WARNING opportunity for swap().
>
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=9573
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> ---
>  .../display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c    | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c b/drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c
> index 717536d7bb30..8e68a8094658 100644
> --- a/drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c
> +++ b/drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c
> @@ -7,16 +7,12 @@
>
>  static void sort(double *list_a, int list_a_size)
>  {
> -       double temp;
>         // For all elements b[i] in list_b[]
>         for (int i = 0; i < list_a_size - 1; i++) {
>                 // Find the first element of list_a that's larger than b[i]
>                 for (int j = i; j < list_a_size - 1; j++) {
> -                       if (list_a[j] > list_a[j + 1]) {
> -                               temp = list_a[j];
> -                               list_a[j] = list_a[j + 1];
> -                               list_a[j + 1] = temp;
> -                       }
> +                       if (list_a[j] > list_a[j + 1])
> +                               swap(list_a[j], list_a[j + 1]);
>                 }
>         }
>  }
> --
> 2.32.0.3.g01195cf9f
>
Christian König July 25, 2024, 6:55 a.m. UTC | #2
Am 24.07.24 um 09:37 schrieb Jiapeng Chong:
> Use existing swap() function rather than duplicating its implementation.
>
> ./drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c:17:29-30: WARNING opportunity for swap().
>
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=9573
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> ---
>   .../display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c    | 8 ++------
>   1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c b/drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c
> index 717536d7bb30..8e68a8094658 100644
> --- a/drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c
> +++ b/drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c
> @@ -7,16 +7,12 @@
>   
>   static void sort(double *list_a, int list_a_size)
>   {
> -	double temp;
>   	// For all elements b[i] in list_b[]
>   	for (int i = 0; i < list_a_size - 1; i++) {
>   		// Find the first element of list_a that's larger than b[i]

While at it please also replace all // comments by using /* */.

Apart from that looks good to me.

Regards,
Christian.

>   		for (int j = i; j < list_a_size - 1; j++) {
> -			if (list_a[j] > list_a[j + 1]) {
> -				temp = list_a[j];
> -				list_a[j] = list_a[j + 1];
> -				list_a[j + 1] = temp;
> -			}
> +			if (list_a[j] > list_a[j + 1])
> +				swap(list_a[j], list_a[j + 1]);
>   		}
>   	}
>   }
diff mbox series

Patch

diff --git a/drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c b/drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c
index 717536d7bb30..8e68a8094658 100644
--- a/drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c
+++ b/drivers/gpu/drm/amd/display/dc/dml2/dml21/src/dml2_pmo/dml2_pmo_dcn3.c
@@ -7,16 +7,12 @@ 
 
 static void sort(double *list_a, int list_a_size)
 {
-	double temp;
 	// For all elements b[i] in list_b[]
 	for (int i = 0; i < list_a_size - 1; i++) {
 		// Find the first element of list_a that's larger than b[i]
 		for (int j = i; j < list_a_size - 1; j++) {
-			if (list_a[j] > list_a[j + 1]) {
-				temp = list_a[j];
-				list_a[j] = list_a[j + 1];
-				list_a[j + 1] = temp;
-			}
+			if (list_a[j] > list_a[j + 1])
+				swap(list_a[j], list_a[j + 1]);
 		}
 	}
 }