diff mbox series

[v2,09/15] drm/edid: add drm_edid_raw() to access the raw EDID data

Message ID 5363988bcd7f0af9a32e30634348dbb8f22ec5b9.1654674560.git.jani.nikula@intel.com (mailing list archive)
State New, archived
Headers show
Series drm/edid: expand on struct drm_edid usage | expand

Commit Message

Jani Nikula June 8, 2022, 7:50 a.m. UTC
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>
---
 drivers/gpu/drm/drm_edid.c | 26 ++++++++++++++++++++++++++
 include/drm/drm_edid.h     |  1 +
 2 files changed, 27 insertions(+)

Comments

Ville Syrjälä June 10, 2022, 7:29 p.m. UTC | #1
On Wed, Jun 08, 2022 at 10:50:39AM +0300, Jani Nikula wrote:
> 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 952724788963..4e788c5cbf25 100644
> --- a/drivers/gpu/drm/drm_edid.c
> +++ b/drivers/gpu/drm/drm_edid.c
> @@ -2333,6 +2333,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
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 952724788963..4e788c5cbf25 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -2333,6 +2333,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);