All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@intel.com>
To: dri-devel@lists.freedesktop.org
Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org
Subject: [PATCH v3 07/13] drm/edid: add drm_edid_raw() to access the raw EDID data
Date: Wed, 22 Jun 2022 13:59:21 +0300	[thread overview]
Message-ID: <910bff54e79a93a339b209162aad83806a3d66f7.1655895388.git.jani.nikula@intel.com> (raw)
In-Reply-To: <cover.1655895388.git.jani.nikula@intel.com>

Unfortunately, there are still plenty of interfaces around that require
a struct edid pointer, and it's impossible to change them all at
once. Add an accessor to the raw EDID data to help the transition.

While there are no such cases now, be defensive against raw EDID
extension count indicating bigger EDID than is actually allocated.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/drm_edid.c | 26 ++++++++++++++++++++++++++
 include/drm/drm_edid.h     |  1 +
 2 files changed, 27 insertions(+)

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 41b3de52b8f1..1c761e12820e 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -2359,6 +2359,32 @@ struct edid *drm_do_get_edid(struct drm_connector *connector,
 }
 EXPORT_SYMBOL_GPL(drm_do_get_edid);
 
+/**
+ * drm_edid_raw - Get a pointer to the raw EDID data.
+ * @drm_edid: drm_edid container
+ *
+ * Get a pointer to the raw EDID data.
+ *
+ * This is for transition only. Avoid using this like the plague.
+ *
+ * Return: Pointer to raw EDID data.
+ */
+const struct edid *drm_edid_raw(const struct drm_edid *drm_edid)
+{
+	if (!drm_edid || !drm_edid->size)
+		return NULL;
+
+	/*
+	 * Do not return pointers where relying on EDID extension count would
+	 * lead to buffer overflow.
+	 */
+	if (WARN_ON(edid_size(drm_edid->edid) > drm_edid->size))
+		return NULL;
+
+	return drm_edid->edid;
+}
+EXPORT_SYMBOL(drm_edid_raw);
+
 /* Allocate struct drm_edid container *without* duplicating the edid data */
 static const struct drm_edid *_drm_edid_alloc(const void *edid, size_t size)
 {
diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h
index aeb2fa95bc04..2181977ae683 100644
--- a/include/drm/drm_edid.h
+++ b/include/drm/drm_edid.h
@@ -597,6 +597,7 @@ drm_display_mode_from_cea_vic(struct drm_device *dev,
 const struct drm_edid *drm_edid_alloc(const void *edid, size_t size);
 const struct drm_edid *drm_edid_dup(const struct drm_edid *drm_edid);
 void drm_edid_free(const struct drm_edid *drm_edid);
+const struct edid *drm_edid_raw(const struct drm_edid *drm_edid);
 const struct drm_edid *drm_edid_read(struct drm_connector *connector);
 const struct drm_edid *drm_edid_read_ddc(struct drm_connector *connector,
 					 struct i2c_adapter *adapter);
-- 
2.30.2


WARNING: multiple messages have this Message-ID (diff)
From: Jani Nikula <jani.nikula@intel.com>
To: dri-devel@lists.freedesktop.org
Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org
Subject: [Intel-gfx] [PATCH v3 07/13] drm/edid: add drm_edid_raw() to access the raw EDID data
Date: Wed, 22 Jun 2022 13:59:21 +0300	[thread overview]
Message-ID: <910bff54e79a93a339b209162aad83806a3d66f7.1655895388.git.jani.nikula@intel.com> (raw)
In-Reply-To: <cover.1655895388.git.jani.nikula@intel.com>

Unfortunately, there are still plenty of interfaces around that require
a struct edid pointer, and it's impossible to change them all at
once. Add an accessor to the raw EDID data to help the transition.

While there are no such cases now, be defensive against raw EDID
extension count indicating bigger EDID than is actually allocated.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/drm_edid.c | 26 ++++++++++++++++++++++++++
 include/drm/drm_edid.h     |  1 +
 2 files changed, 27 insertions(+)

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 41b3de52b8f1..1c761e12820e 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -2359,6 +2359,32 @@ struct edid *drm_do_get_edid(struct drm_connector *connector,
 }
 EXPORT_SYMBOL_GPL(drm_do_get_edid);
 
+/**
+ * drm_edid_raw - Get a pointer to the raw EDID data.
+ * @drm_edid: drm_edid container
+ *
+ * Get a pointer to the raw EDID data.
+ *
+ * This is for transition only. Avoid using this like the plague.
+ *
+ * Return: Pointer to raw EDID data.
+ */
+const struct edid *drm_edid_raw(const struct drm_edid *drm_edid)
+{
+	if (!drm_edid || !drm_edid->size)
+		return NULL;
+
+	/*
+	 * Do not return pointers where relying on EDID extension count would
+	 * lead to buffer overflow.
+	 */
+	if (WARN_ON(edid_size(drm_edid->edid) > drm_edid->size))
+		return NULL;
+
+	return drm_edid->edid;
+}
+EXPORT_SYMBOL(drm_edid_raw);
+
 /* Allocate struct drm_edid container *without* duplicating the edid data */
 static const struct drm_edid *_drm_edid_alloc(const void *edid, size_t size)
 {
diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h
index aeb2fa95bc04..2181977ae683 100644
--- a/include/drm/drm_edid.h
+++ b/include/drm/drm_edid.h
@@ -597,6 +597,7 @@ drm_display_mode_from_cea_vic(struct drm_device *dev,
 const struct drm_edid *drm_edid_alloc(const void *edid, size_t size);
 const struct drm_edid *drm_edid_dup(const struct drm_edid *drm_edid);
 void drm_edid_free(const struct drm_edid *drm_edid);
+const struct edid *drm_edid_raw(const struct drm_edid *drm_edid);
 const struct drm_edid *drm_edid_read(struct drm_connector *connector);
 const struct drm_edid *drm_edid_read_ddc(struct drm_connector *connector,
 					 struct i2c_adapter *adapter);
-- 
2.30.2


  parent reply	other threads:[~2022-06-22 11:00 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-22 10:59 [PATCH v3 00/13] drm/edid: expand on struct drm_edid usage Jani Nikula
2022-06-22 10:59 ` [Intel-gfx] " Jani Nikula
2022-06-22 10:59 ` [PATCH v3 01/13] drm/edid: move drm_connector_update_edid_property() to drm_edid.c Jani Nikula
2022-06-22 10:59   ` [Intel-gfx] " Jani Nikula
2022-06-22 14:37   ` Ville Syrjälä
2022-06-22 14:37     ` [Intel-gfx] " Ville Syrjälä
2022-06-22 10:59 ` [PATCH v3 02/13] drm/edid: convert drm_connector_update_edid_property() to struct drm_edid Jani Nikula
2022-06-22 10:59   ` [Intel-gfx] " Jani Nikula
2022-06-22 14:38   ` Ville Syrjälä
2022-06-22 14:38     ` [Intel-gfx] " Ville Syrjälä
2022-06-22 10:59 ` [PATCH v3 03/13] drm/edid: clean up connector update error handling and debug logging Jani Nikula
2022-06-22 10:59   ` [Intel-gfx] " Jani Nikula
2022-06-22 14:40   ` Ville Syrjälä
2022-06-22 14:40     ` [Intel-gfx] " Ville Syrjälä
2022-06-22 10:59 ` [PATCH v3 04/13] drm/edid: abstract debugfs override EDID set/reset Jani Nikula
2022-06-22 10:59   ` [Intel-gfx] " Jani Nikula
2022-06-22 14:41   ` Ville Syrjälä
2022-06-22 14:41     ` [Intel-gfx] " Ville Syrjälä
2022-06-22 10:59 ` [PATCH v3 05/13] drm/edid: add drm_edid_connector_update() Jani Nikula
2022-06-22 10:59   ` [Intel-gfx] " Jani Nikula
2022-06-22 15:17   ` Ville Syrjälä
2022-06-22 15:17     ` [Intel-gfx] " Ville Syrjälä
2022-06-22 10:59 ` [PATCH v3 06/13] drm/probe-helper: add drm_connector_helper_get_modes() Jani Nikula
2022-06-22 10:59   ` [Intel-gfx] " Jani Nikula
2022-06-22 10:59 ` Jani Nikula [this message]
2022-06-22 10:59   ` [Intel-gfx] [PATCH v3 07/13] drm/edid: add drm_edid_raw() to access the raw EDID data Jani Nikula
2022-06-22 10:59 ` [PATCH v3 08/13] drm/i915/edid: convert DP, HDMI and LVDS to drm_edid Jani Nikula
2022-06-22 10:59   ` [Intel-gfx] " Jani Nikula
2022-06-22 15:05   ` Ville Syrjälä
2022-06-22 15:05     ` [Intel-gfx] " Ville Syrjälä
2022-06-23  7:29     ` Jani Nikula
2022-06-23  7:29       ` [Intel-gfx] " Jani Nikula
2022-06-23  7:27   ` [PATCH] " Jani Nikula
2022-06-23  7:27     ` [Intel-gfx] " Jani Nikula
2022-06-23  9:20     ` Ville Syrjälä
2022-06-23  9:20       ` [Intel-gfx] " Ville Syrjälä
2022-06-22 10:59 ` [PATCH v3 09/13] drm/i915/bios: convert intel_bios_init_panel() " Jani Nikula
2022-06-22 10:59   ` [Intel-gfx] " Jani Nikula
2022-06-22 10:59 ` [PATCH v3 10/13] drm/edid: do invalid block filtering in-place Jani Nikula
2022-06-22 10:59   ` [Intel-gfx] " Jani Nikula
2022-06-22 10:59 ` [PATCH v3 11/13] drm/edid: add HF-EEODB support to EDID read and allocation Jani Nikula
2022-06-22 10:59   ` [Intel-gfx] " Jani Nikula
2022-06-22 10:59 ` [PATCH v3 12/13] drm/edid: take HF-EEODB extension count into account Jani Nikula
2022-06-22 10:59   ` [Intel-gfx] " Jani Nikula
2022-06-22 10:59 ` [PATCH v3 13/13] drm/todo: add entry for converting the subsystem to struct drm_edid Jani Nikula
2022-06-22 10:59   ` [Intel-gfx] " Jani Nikula
2022-06-22 21:38 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm/edid: expand on struct drm_edid usage (rev4) Patchwork
2022-06-22 21:38 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2022-06-22 21:59 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2022-06-23  7:56 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm/edid: expand on struct drm_edid usage (rev5) Patchwork
2022-06-23  8:18 ` [Intel-gfx] ✗ Fi.CI.BAT: failure " Patchwork
2022-06-23  8:59 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm/edid: expand on struct drm_edid usage (rev6) Patchwork
2022-06-23  9:26 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2022-06-27 10:41 ` [Intel-gfx] ✗ Fi.CI.IGT: failure for drm/edid: expand on struct drm_edid usage (rev4) Patchwork
2022-06-27 13:15 ` [Intel-gfx] ✗ Fi.CI.IGT: failure for drm/edid: expand on struct drm_edid usage (rev6) Patchwork
2022-06-28 20:49 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm/edid: expand on struct drm_edid usage (rev7) Patchwork
2022-06-28 20:49 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2022-06-28 21:09 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2022-06-29 13:28 ` [Intel-gfx] ✗ Fi.CI.IGT: failure " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=910bff54e79a93a339b209162aad83806a3d66f7.1655895388.git.jani.nikula@intel.com \
    --to=jani.nikula@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.