Skip to contentSkip to conversation

drm/edid: make a couple of read-only arrays static const

PATCH In review Colin Ian King 2 participants 2 messages Nov 3, 2022

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

PATCH 1/1 drm/edid: make a couple of read-only arrays static const

Don't populate two read-only arrays on the stack but instead make them static const . Also makes the object code a little smaller.

---
 drivers/gpu/drm/drm_edid.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_edid.c +2 -2
index 4671dc23abe0..50d488cc840e 100644
@@ -3916,8 +3916,8 @@ static int drm_cvt_modes(struct drm_connector *connector,
 	struct drm_display_mode *newmode;
 	struct drm_device *dev = connector->dev;
 	const struct cvt_timing *cvt;
-	const int rates[] = { 60, 85, 75, 60, 50 };
-	const u8 empty[3] = { 0, 0, 0 };
+	static const int rates[] = { 60, 85, 75, 60, 50 };
+	static const u8 empty[3] = { 0, 0, 0 };
 
 	for (i = 0; i < 4; i++) {
 		int width, height;
Signature · 1 line
2.38.1
#1 lore raw
Quoted 13 lines · Colin Ian King

Don't populate two read-only arrays on the stack but instead make them static const . Also makes the object code a little smaller.

---
 drivers/gpu/drm/drm_edid.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_edid.c +0 -0
index 4671dc23abe0..50d488cc840e 100644

drivers/gpu/drm/drm_edid.c static int drm_cvt_modes(struct drm_connector *connector, · line 3920

Quoted 7 lines
drivers/gpu/drm/drm_edid.c +2 -2
@@ -3916,8 +3916,8 @@ static int drm_cvt_modes(struct drm_connector *connector,
 	struct drm_display_mode *newmode;
 	struct drm_device *dev = connector->dev;
 	const struct cvt_timing *cvt;
-	const int rates[] = { 60, 85, 75, 60, 50 };
-	const u8 empty[3] = { 0, 0, 0 };
+	static const int rates[] = { 60, 85, 75, 60, 50 };
+	static const u8 empty[3] = { 0, 0, 0 };

The change is fine per se, but I think this whole array is silly. Could be removed with:

- if (!memcmp(cvt->code, empty, 3))
+ if (!memchr_inv(cvt->code, 0, sizeof(cvt->code)))

BR,
Jani.

PS. I also note that rates[0] is never used, but that's another story, maybe a bug.

Quoted 3 lines
drivers/gpu/drm/drm_edid.c +0 -0
 	for (i = 0; i < 4; i++) {
 		int width, height;
Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center