All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/bridge: adv7511: Replace hardcoded number
@ 2020-02-12 13:42 Fabio Estevam
  2020-02-13  9:20 ` Neil Armstrong
  0 siblings, 1 reply; 2+ messages in thread
From: Fabio Estevam @ 2020-02-12 13:42 UTC (permalink / raw)
  To: a.hajda; +Cc: dri-devel, narmstrong

The hardcoded '12' means the number of elements in the
adv7511_csc_ycbcr_to_rgb[] array, so use the ARRAY_SIZE() macro
to let the code less error prone.

Signed-off-by: Fabio Estevam <festevam@gmail.com>
---
 drivers/gpu/drm/bridge/adv7511/adv7511_drv.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
index 9e13e466e72c..568c6d52cdda 100644
--- a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
+++ b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
@@ -132,6 +132,13 @@ static const struct regmap_config adv7511_regmap_config = {
  * Hardware configuration
  */
 
+/* Coefficients for adv7511 color space conversion */
+static const uint16_t adv7511_csc_ycbcr_to_rgb[] = {
+	0x0734, 0x04ad, 0x0000, 0x1c1b,
+	0x1ddc, 0x04ad, 0x1f24, 0x0135,
+	0x0000, 0x04ad, 0x087c, 0x1b77,
+};
+
 static void adv7511_set_colormap(struct adv7511 *adv7511, bool enable,
 				 const uint16_t *coeff,
 				 unsigned int scaling_factor)
@@ -142,7 +149,7 @@ static void adv7511_set_colormap(struct adv7511 *adv7511, bool enable,
 			   ADV7511_CSC_UPDATE_MODE, ADV7511_CSC_UPDATE_MODE);
 
 	if (enable) {
-		for (i = 0; i < 12; ++i) {
+		for (i = 0; i < ARRAY_SIZE(adv7511_csc_ycbcr_to_rgb); ++i) {
 			regmap_update_bits(adv7511->regmap,
 					   ADV7511_REG_CSC_UPPER(i),
 					   0x1f, coeff[i] >> 8);
@@ -193,13 +200,6 @@ static int adv7511_packet_disable(struct adv7511 *adv7511, unsigned int packet)
 	return 0;
 }
 
-/* Coefficients for adv7511 color space conversion */
-static const uint16_t adv7511_csc_ycbcr_to_rgb[] = {
-	0x0734, 0x04ad, 0x0000, 0x1c1b,
-	0x1ddc, 0x04ad, 0x1f24, 0x0135,
-	0x0000, 0x04ad, 0x087c, 0x1b77,
-};
-
 static void adv7511_set_config_csc(struct adv7511 *adv7511,
 				   struct drm_connector *connector,
 				   bool rgb, bool hdmi_mode)
-- 
2.17.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH] drm/bridge: adv7511: Replace hardcoded number
  2020-02-12 13:42 [PATCH] drm/bridge: adv7511: Replace hardcoded number Fabio Estevam
@ 2020-02-13  9:20 ` Neil Armstrong
  0 siblings, 0 replies; 2+ messages in thread
From: Neil Armstrong @ 2020-02-13  9:20 UTC (permalink / raw)
  To: Fabio Estevam, a.hajda; +Cc: dri-devel

On 12/02/2020 14:42, Fabio Estevam wrote:
> The hardcoded '12' means the number of elements in the
> adv7511_csc_ycbcr_to_rgb[] array, so use the ARRAY_SIZE() macro
> to let the code less error prone.
> 
> Signed-off-by: Fabio Estevam <festevam@gmail.com>
> ---
>  drivers/gpu/drm/bridge/adv7511/adv7511_drv.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
> index 9e13e466e72c..568c6d52cdda 100644
> --- a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
> +++ b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
> @@ -132,6 +132,13 @@ static const struct regmap_config adv7511_regmap_config = {
>   * Hardware configuration
>   */
>  
> +/* Coefficients for adv7511 color space conversion */
> +static const uint16_t adv7511_csc_ycbcr_to_rgb[] = {
> +	0x0734, 0x04ad, 0x0000, 0x1c1b,
> +	0x1ddc, 0x04ad, 0x1f24, 0x0135,
> +	0x0000, 0x04ad, 0x087c, 0x1b77,
> +};
> +
>  static void adv7511_set_colormap(struct adv7511 *adv7511, bool enable,
>  				 const uint16_t *coeff,
>  				 unsigned int scaling_factor)
> @@ -142,7 +149,7 @@ static void adv7511_set_colormap(struct adv7511 *adv7511, bool enable,
>  			   ADV7511_CSC_UPDATE_MODE, ADV7511_CSC_UPDATE_MODE);
>  
>  	if (enable) {
> -		for (i = 0; i < 12; ++i) {
> +		for (i = 0; i < ARRAY_SIZE(adv7511_csc_ycbcr_to_rgb); ++i) {
>  			regmap_update_bits(adv7511->regmap,
>  					   ADV7511_REG_CSC_UPPER(i),
>  					   0x1f, coeff[i] >> 8);
> @@ -193,13 +200,6 @@ static int adv7511_packet_disable(struct adv7511 *adv7511, unsigned int packet)
>  	return 0;
>  }
>  
> -/* Coefficients for adv7511 color space conversion */
> -static const uint16_t adv7511_csc_ycbcr_to_rgb[] = {
> -	0x0734, 0x04ad, 0x0000, 0x1c1b,
> -	0x1ddc, 0x04ad, 0x1f24, 0x0135,
> -	0x0000, 0x04ad, 0x087c, 0x1b77,
> -};
> -
>  static void adv7511_set_config_csc(struct adv7511 *adv7511,
>  				   struct drm_connector *connector,
>  				   bool rgb, bool hdmi_mode)
> 

Hmm, you replace an hardcoded number by an ARRAY_SIZE() of a maybe unrelated array,
maybe the size should be passed to adv7511_set_colormap() instead,

Neil
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

end of thread, other threads:[~2020-02-13  9:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-12 13:42 [PATCH] drm/bridge: adv7511: Replace hardcoded number Fabio Estevam
2020-02-13  9:20 ` Neil Armstrong

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.