public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] drm/amd/display: Replace NUM_ELEMENTS -> ARRAY_SIZE
@ 2026-04-03  8:22 Linus Probert
  2026-04-03  8:22 ` [PATCH 1/2] drm/amd/display: Replace inline NUM_ELEMENTS macro with ARRAY_SIZE Linus Probert
  2026-04-03  8:22 ` [PATCH 2/2] drm/amd/display: Remove unused NUM_ELEMENTS macros Linus Probert
  0 siblings, 2 replies; 4+ messages in thread
From: Linus Probert @ 2026-04-03  8:22 UTC (permalink / raw)
  To: Harry Wentland, Leo Li, Rodrigo Siqueira, Alex Deucher,
	Christian König, David Airlie, Simona Vetter
  Cc: amd-gfx, dri-devel, linux-kernel, Linus Probert

There's a coccinelle script which attempts to replace cases where sizeof
array is divided by sizeof an element. Most of these occurences have
been handled but a few remained in this driver in the shape of the
NUM_ELEMENTS macro.

In two cases the NUM_ELEMENTS macro has been removed and its use has
been replaced by ARRAY_SIZE. (1)
In 4 files the NUM_ELEMENTS macro existed but was never used so it has
just been removed. (2)

I couldn't trace why these cases hadn't been picked up by the coccinelle
check. Just NAK this if there's a reason for NUM_ELEMENTS to be kept as
is. Thanks.

Linus Probert (2):
  drm/amd/display: Replace inline NUM_ELEMENTS macro with ARRAY_SIZE
  drm/amd/display: Remove unused NUM_ELEMENTS macros

 drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c     | 5 +++--
 drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c     | 6 +++---
 drivers/gpu/drm/amd/display/dc/dpp/dcn10/dcn10_dpp_cm.c   | 3 ---
 drivers/gpu/drm/amd/display/dc/dpp/dcn401/dcn401_dpp_cm.c | 3 ---
 drivers/gpu/drm/amd/display/dc/mpc/dcn20/dcn20_mpc.c      | 2 --
 drivers/gpu/drm/amd/display/dc/mpc/dcn30/dcn30_mpc.c      | 4 ----
 6 files changed, 6 insertions(+), 17 deletions(-)

-- 
2.53.0


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

* [PATCH 1/2] drm/amd/display: Replace inline NUM_ELEMENTS macro with ARRAY_SIZE
  2026-04-03  8:22 [PATCH 0/2] drm/amd/display: Replace NUM_ELEMENTS -> ARRAY_SIZE Linus Probert
@ 2026-04-03  8:22 ` Linus Probert
  2026-04-03  8:22 ` [PATCH 2/2] drm/amd/display: Remove unused NUM_ELEMENTS macros Linus Probert
  1 sibling, 0 replies; 4+ messages in thread
From: Linus Probert @ 2026-04-03  8:22 UTC (permalink / raw)
  To: Harry Wentland, Leo Li, Rodrigo Siqueira, Alex Deucher,
	Christian König, David Airlie, Simona Vetter
  Cc: amd-gfx, dri-devel, linux-kernel, Linus Probert, Robert P. J. Day

Replaces the use of local NUM_ELEMENTS macro with the ARRAY_SIZE macro
defined in <linux/array_size.h>.

This aligns with existing coccinelle script array_size.cocci which has
been applied to other sources in order to remove inline
sizeof(a)/sizeof(a[0]) patterns from other source files.

Suggested-by: Robert P. J. Day <rpjday@crashcourse.ca>
Signed-off-by: Linus Probert <linus.probert@gmail.com>
---
 drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c | 5 +++--
 drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c | 6 +++---
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c b/drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c
index 052d573408c3..d42d7befef42 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c
@@ -23,6 +23,8 @@
  *
  */
 
+#include <linux/array_size.h>
+
 #include "dm_services.h"
 #include "core_types.h"
 #include "timing_generator.h"
@@ -40,7 +42,6 @@
 #include "dcn10/dcn10_hubbub.h"
 #include "dce/dmub_hw_lock_mgr.h"
 
-#define NUM_ELEMENTS(a) (sizeof(a) / sizeof((a)[0]))
 #define MAX_NUM_MCACHE 8
 
 /* used as index in array of black_color_format */
@@ -230,7 +231,7 @@ const uint16_t *find_color_matrix(enum dc_color_space color_space,
 	int i;
 	enum dc_color_space_type type;
 	const uint16_t *val = NULL;
-	int arr_size = NUM_ELEMENTS(output_csc_matrix);
+	int arr_size = ARRAY_SIZE(output_csc_matrix);
 
 	type = get_color_space_type(color_space);
 	for (i = 0; i < arr_size; i++)
diff --git a/drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c b/drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c
index 5722be965422..9d043cc35eb5 100644
--- a/drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c
+++ b/drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c
@@ -23,6 +23,8 @@
  *
  */
 
+#include <linux/array_size.h>
+
 #include "dm_services.h"
 
 
@@ -57,8 +59,6 @@
 #define CALC_PLL_CLK_SRC_ERR_TOLERANCE 1
 #define MAX_PLL_CALC_ERROR 0xFFFFFFFF
 
-#define NUM_ELEMENTS(a) (sizeof(a) / sizeof((a)[0]))
-
 static const struct spread_spectrum_data *get_ss_data_entry(
 		struct dce110_clk_src *clk_src,
 		enum signal_type signal,
@@ -1267,7 +1267,7 @@ const struct pixel_rate_range_table_entry *look_up_in_video_optimized_rate_tlb(
 {
 	int i;
 
-	for (i = 0; i < NUM_ELEMENTS(video_optimized_pixel_rates); i++) {
+	for (i = 0; i < ARRAY_SIZE(video_optimized_pixel_rates); i++) {
 		const struct pixel_rate_range_table_entry *e = &video_optimized_pixel_rates[i];
 
 		if (e->range_min_khz <= pixel_rate_khz && pixel_rate_khz <= e->range_max_khz) {
-- 
2.53.0


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

* [PATCH 2/2] drm/amd/display: Remove unused NUM_ELEMENTS macros
  2026-04-03  8:22 [PATCH 0/2] drm/amd/display: Replace NUM_ELEMENTS -> ARRAY_SIZE Linus Probert
  2026-04-03  8:22 ` [PATCH 1/2] drm/amd/display: Replace inline NUM_ELEMENTS macro with ARRAY_SIZE Linus Probert
@ 2026-04-03  8:22 ` Linus Probert
  2026-04-03 13:58   ` Alex Deucher
  1 sibling, 1 reply; 4+ messages in thread
From: Linus Probert @ 2026-04-03  8:22 UTC (permalink / raw)
  To: Harry Wentland, Leo Li, Rodrigo Siqueira, Alex Deucher,
	Christian König, David Airlie, Simona Vetter
  Cc: amd-gfx, dri-devel, linux-kernel, Linus Probert, Robert P. J. Day

Removes unused NUM_ELEMENTS macros. Discovered while removing cases
where ARRAY_SIZE from the header <linus/array_size.h> can be used.
This also aligns with the array_size.cocci coccinelle check.

Suggested-by: Robert P. J. Day <rpjday@crashcourse.ca>
Signed-off-by: Linus Probert <linus.probert@gmail.com>
---
 drivers/gpu/drm/amd/display/dc/dpp/dcn10/dcn10_dpp_cm.c   | 3 ---
 drivers/gpu/drm/amd/display/dc/dpp/dcn401/dcn401_dpp_cm.c | 3 ---
 drivers/gpu/drm/amd/display/dc/mpc/dcn20/dcn20_mpc.c      | 2 --
 drivers/gpu/drm/amd/display/dc/mpc/dcn30/dcn30_mpc.c      | 4 ----
 4 files changed, 12 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dpp/dcn10/dcn10_dpp_cm.c b/drivers/gpu/drm/amd/display/dc/dpp/dcn10/dcn10_dpp_cm.c
index f8f6019d8304..2bdd063cc1e1 100644
--- a/drivers/gpu/drm/amd/display/dc/dpp/dcn10/dcn10_dpp_cm.c
+++ b/drivers/gpu/drm/amd/display/dc/dpp/dcn10/dcn10_dpp_cm.c
@@ -49,9 +49,6 @@
 #define FN(reg_name, field_name) \
 	dpp->tf_shift->field_name, dpp->tf_mask->field_name
 
-#define NUM_ELEMENTS(a) (sizeof(a) / sizeof((a)[0]))
-
-
 enum dcn10_coef_filter_type_sel {
 	SCL_COEF_LUMA_VERT_FILTER = 0,
 	SCL_COEF_LUMA_HORZ_FILTER = 1,
diff --git a/drivers/gpu/drm/amd/display/dc/dpp/dcn401/dcn401_dpp_cm.c b/drivers/gpu/drm/amd/display/dc/dpp/dcn401/dcn401_dpp_cm.c
index 62bf7cea21d8..7b7a0c660d47 100644
--- a/drivers/gpu/drm/amd/display/dc/dpp/dcn401/dcn401_dpp_cm.c
+++ b/drivers/gpu/drm/amd/display/dc/dpp/dcn401/dcn401_dpp_cm.c
@@ -49,9 +49,6 @@
 #define FN(reg_name, field_name) \
 	dpp->tf_shift->field_name, dpp->tf_mask->field_name
 
-#define NUM_ELEMENTS(a) (sizeof(a) / sizeof((a)[0]))
-
-
 enum dcn401_coef_filter_type_sel {
 	SCL_COEF_LUMA_VERT_FILTER = 0,
 	SCL_COEF_LUMA_HORZ_FILTER = 1,
diff --git a/drivers/gpu/drm/amd/display/dc/mpc/dcn20/dcn20_mpc.c b/drivers/gpu/drm/amd/display/dc/mpc/dcn20/dcn20_mpc.c
index ea73473b970a..fa600593f4c1 100644
--- a/drivers/gpu/drm/amd/display/dc/mpc/dcn20/dcn20_mpc.c
+++ b/drivers/gpu/drm/amd/display/dc/mpc/dcn20/dcn20_mpc.c
@@ -43,8 +43,6 @@
 #define FN(reg_name, field_name) \
 	mpc20->mpc_shift->field_name, mpc20->mpc_mask->field_name
 
-#define NUM_ELEMENTS(a) (sizeof(a) / sizeof((a)[0]))
-
 void mpc2_update_blending(
 	struct mpc *mpc,
 	struct mpcc_blnd_cfg *blnd_cfg,
diff --git a/drivers/gpu/drm/amd/display/dc/mpc/dcn30/dcn30_mpc.c b/drivers/gpu/drm/amd/display/dc/mpc/dcn30/dcn30_mpc.c
index 6bfd2c1294e5..ec2181d9f20b 100644
--- a/drivers/gpu/drm/amd/display/dc/mpc/dcn30/dcn30_mpc.c
+++ b/drivers/gpu/drm/amd/display/dc/mpc/dcn30/dcn30_mpc.c
@@ -40,10 +40,6 @@
 #define FN(reg_name, field_name) \
 	mpc30->mpc_shift->field_name, mpc30->mpc_mask->field_name
 
-
-#define NUM_ELEMENTS(a) (sizeof(a) / sizeof((a)[0]))
-
-
 void mpc3_mpc_init(struct mpc *mpc)
 {
 	struct dcn30_mpc *mpc30 = TO_DCN30_MPC(mpc);
-- 
2.53.0


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

* Re: [PATCH 2/2] drm/amd/display: Remove unused NUM_ELEMENTS macros
  2026-04-03  8:22 ` [PATCH 2/2] drm/amd/display: Remove unused NUM_ELEMENTS macros Linus Probert
@ 2026-04-03 13:58   ` Alex Deucher
  0 siblings, 0 replies; 4+ messages in thread
From: Alex Deucher @ 2026-04-03 13:58 UTC (permalink / raw)
  To: Linus Probert
  Cc: Harry Wentland, Leo Li, Rodrigo Siqueira, Alex Deucher,
	Christian König, David Airlie, Simona Vetter, amd-gfx,
	dri-devel, linux-kernel, Robert P. J. Day

Applied the series.  Thanks!

On Fri, Apr 3, 2026 at 5:29 AM Linus Probert <linus.probert@gmail.com> wrote:
>
> Removes unused NUM_ELEMENTS macros. Discovered while removing cases
> where ARRAY_SIZE from the header <linus/array_size.h> can be used.
> This also aligns with the array_size.cocci coccinelle check.
>
> Suggested-by: Robert P. J. Day <rpjday@crashcourse.ca>
> Signed-off-by: Linus Probert <linus.probert@gmail.com>
> ---
>  drivers/gpu/drm/amd/display/dc/dpp/dcn10/dcn10_dpp_cm.c   | 3 ---
>  drivers/gpu/drm/amd/display/dc/dpp/dcn401/dcn401_dpp_cm.c | 3 ---
>  drivers/gpu/drm/amd/display/dc/mpc/dcn20/dcn20_mpc.c      | 2 --
>  drivers/gpu/drm/amd/display/dc/mpc/dcn30/dcn30_mpc.c      | 4 ----
>  4 files changed, 12 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/display/dc/dpp/dcn10/dcn10_dpp_cm.c b/drivers/gpu/drm/amd/display/dc/dpp/dcn10/dcn10_dpp_cm.c
> index f8f6019d8304..2bdd063cc1e1 100644
> --- a/drivers/gpu/drm/amd/display/dc/dpp/dcn10/dcn10_dpp_cm.c
> +++ b/drivers/gpu/drm/amd/display/dc/dpp/dcn10/dcn10_dpp_cm.c
> @@ -49,9 +49,6 @@
>  #define FN(reg_name, field_name) \
>         dpp->tf_shift->field_name, dpp->tf_mask->field_name
>
> -#define NUM_ELEMENTS(a) (sizeof(a) / sizeof((a)[0]))
> -
> -
>  enum dcn10_coef_filter_type_sel {
>         SCL_COEF_LUMA_VERT_FILTER = 0,
>         SCL_COEF_LUMA_HORZ_FILTER = 1,
> diff --git a/drivers/gpu/drm/amd/display/dc/dpp/dcn401/dcn401_dpp_cm.c b/drivers/gpu/drm/amd/display/dc/dpp/dcn401/dcn401_dpp_cm.c
> index 62bf7cea21d8..7b7a0c660d47 100644
> --- a/drivers/gpu/drm/amd/display/dc/dpp/dcn401/dcn401_dpp_cm.c
> +++ b/drivers/gpu/drm/amd/display/dc/dpp/dcn401/dcn401_dpp_cm.c
> @@ -49,9 +49,6 @@
>  #define FN(reg_name, field_name) \
>         dpp->tf_shift->field_name, dpp->tf_mask->field_name
>
> -#define NUM_ELEMENTS(a) (sizeof(a) / sizeof((a)[0]))
> -
> -
>  enum dcn401_coef_filter_type_sel {
>         SCL_COEF_LUMA_VERT_FILTER = 0,
>         SCL_COEF_LUMA_HORZ_FILTER = 1,
> diff --git a/drivers/gpu/drm/amd/display/dc/mpc/dcn20/dcn20_mpc.c b/drivers/gpu/drm/amd/display/dc/mpc/dcn20/dcn20_mpc.c
> index ea73473b970a..fa600593f4c1 100644
> --- a/drivers/gpu/drm/amd/display/dc/mpc/dcn20/dcn20_mpc.c
> +++ b/drivers/gpu/drm/amd/display/dc/mpc/dcn20/dcn20_mpc.c
> @@ -43,8 +43,6 @@
>  #define FN(reg_name, field_name) \
>         mpc20->mpc_shift->field_name, mpc20->mpc_mask->field_name
>
> -#define NUM_ELEMENTS(a) (sizeof(a) / sizeof((a)[0]))
> -
>  void mpc2_update_blending(
>         struct mpc *mpc,
>         struct mpcc_blnd_cfg *blnd_cfg,
> diff --git a/drivers/gpu/drm/amd/display/dc/mpc/dcn30/dcn30_mpc.c b/drivers/gpu/drm/amd/display/dc/mpc/dcn30/dcn30_mpc.c
> index 6bfd2c1294e5..ec2181d9f20b 100644
> --- a/drivers/gpu/drm/amd/display/dc/mpc/dcn30/dcn30_mpc.c
> +++ b/drivers/gpu/drm/amd/display/dc/mpc/dcn30/dcn30_mpc.c
> @@ -40,10 +40,6 @@
>  #define FN(reg_name, field_name) \
>         mpc30->mpc_shift->field_name, mpc30->mpc_mask->field_name
>
> -
> -#define NUM_ELEMENTS(a) (sizeof(a) / sizeof((a)[0]))
> -
> -
>  void mpc3_mpc_init(struct mpc *mpc)
>  {
>         struct dcn30_mpc *mpc30 = TO_DCN30_MPC(mpc);
> --
> 2.53.0
>

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

end of thread, other threads:[~2026-04-03 13:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-03  8:22 [PATCH 0/2] drm/amd/display: Replace NUM_ELEMENTS -> ARRAY_SIZE Linus Probert
2026-04-03  8:22 ` [PATCH 1/2] drm/amd/display: Replace inline NUM_ELEMENTS macro with ARRAY_SIZE Linus Probert
2026-04-03  8:22 ` [PATCH 2/2] drm/amd/display: Remove unused NUM_ELEMENTS macros Linus Probert
2026-04-03 13:58   ` Alex Deucher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox