Re: [PATCH] drm/gma500: use ARRAY_SIZE

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Oct 15, 2017 at 10:30:46PM -0400, Jérémy Lefaure wrote:
> Using the ARRAY_SIZE macro improves the readability of the code. Also,
> it is useless to re-invent it.
> 
> Found with Coccinelle with the following semantic patch:
> @r depends on (org || report)@
> type T;
> T[] E;
> position p;
> @@
> (
>  (sizeof(E)@p /sizeof(*E))
> |
>  (sizeof(E)@p /sizeof(E[...]))
> |
>  (sizeof(E)@p /sizeof(T))
> )
> 
> Reviewed-by: Thierry Reding <treding@xxxxxxxxxx>
> Signed-off-by: Jérémy Lefaure <jeremy.lefaure@xxxxxxxxxxxx>

Applied to drm-misc-next, thanks.
-Daniel

> ---
> This patch was part of a bigger patch [1] reviewed by Thierry Reding
> before it was split in several patches.
> 
> [1]: https://patchwork.kernel.org/patch/9979843/
> 
>  drivers/gpu/drm/gma500/psb_intel_sdvo.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/gpu/drm/gma500/psb_intel_sdvo.c b/drivers/gpu/drm/gma500/psb_intel_sdvo.c
> index e787d376ba67..84507912be84 100644
> --- a/drivers/gpu/drm/gma500/psb_intel_sdvo.c
> +++ b/drivers/gpu/drm/gma500/psb_intel_sdvo.c
> @@ -37,6 +37,7 @@
>  #include "psb_drv.h"
>  #include "psb_intel_sdvo_regs.h"
>  #include "psb_intel_reg.h"
> +#include <linux/kernel.h>
>  
>  #define SDVO_TMDS_MASK (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)
>  #define SDVO_RGB_MASK  (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1)
> @@ -62,8 +63,6 @@ static const char *tv_format_names[] = {
>  	"SECAM_60"
>  };
>  
> -#define TV_FORMAT_NUM  (sizeof(tv_format_names) / sizeof(*tv_format_names))
> -
>  struct psb_intel_sdvo {
>  	struct gma_encoder base;
>  
> @@ -148,7 +147,7 @@ struct psb_intel_sdvo_connector {
>  	int force_audio;
>  
>  	/* This contains all current supported TV format */
> -	u8 tv_format_supported[TV_FORMAT_NUM];
> +	u8 tv_format_supported[ARRAY_SIZE(tv_format_names)];
>  	int   format_supported_num;
>  	struct drm_property *tv_format;
>  
> @@ -1709,7 +1708,7 @@ psb_intel_sdvo_set_property(struct drm_connector *connector,
>  	}
>  
>  	if (property == psb_intel_sdvo_connector->tv_format) {
> -		if (val >= TV_FORMAT_NUM)
> +		if (val >= ARRAY_SIZE(tv_format_names))
>  			return -EINVAL;
>  
>  		if (psb_intel_sdvo->tv_format_index ==
> @@ -2269,7 +2268,7 @@ static bool psb_intel_sdvo_tv_create_property(struct psb_intel_sdvo *psb_intel_s
>  		return false;
>  
>  	psb_intel_sdvo_connector->format_supported_num = 0;
> -	for (i = 0 ; i < TV_FORMAT_NUM; i++)
> +	for (i = 0 ; i < ARRAY_SIZE(tv_format_names); i++)
>  		if (format_map & (1 << i))
>  			psb_intel_sdvo_connector->tv_format_supported[psb_intel_sdvo_connector->format_supported_num++] = i;
>  
> -- 
> 2.14.2
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@xxxxxxxxxxxxxxxxxxxxx
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux