Skip to contentSkip to conversation

drm/bridge: adv7511: Replace hardcoded number

PATCH In review Fabio Estevam 2 participants 2 messages Feb 12, 2020 – Feb 13, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/bridge: adv7511: Replace hardcoded number

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.

---
 drivers/gpu/drm/bridge/adv7511/adv7511_drv.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/gpu/drm/bridge/adv7511/adv7511_drv.c +8 -8
index 9e13e466e72c..568c6d52cdda 100644
@@ -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)
Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 41 lines · Fabio Estevam

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.

---
 drivers/gpu/drm/bridge/adv7511/adv7511_drv.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/gpu/drm/bridge/adv7511/adv7511_drv.c +8 -1
index 9e13e466e72c..568c6d52cdda 100644
@@ -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;
 }
 

drivers/gpu/drm/bridge/adv7511/adv7511_drv.c static int adv7511_packet_disable(struct adv7511 *adv7511, unsigned int packet) · line 205

Quoted 10 lines
drivers/gpu/drm/bridge/adv7511/adv7511_drv.c +0 -7
-/* 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
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel