diff mbox series

[v3,7/8] drm/omap: add omap_gem_validate_flags()

Message ID 20191007112555.25278-8-jjhiblot@ti.com (mailing list archive)
State New, archived
Headers show
Series drm/omap: OMAP_BO flags | expand

Commit Message

Jean-Jacques Hiblot Oct. 7, 2019, 11:25 a.m. UTC
From: Tomi Valkeinen <tomi.valkeinen@ti.com>

Add a helper function omap_gem_validate_flags() which validates the
omap_bo flags passed from the userspace.

Also drop the dev_err() message, as the userspace can cause that at
will.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
---
 drivers/gpu/drm/omapdrm/omap_gem.c | 40 ++++++++++++++++++++++++++----
 1 file changed, 35 insertions(+), 5 deletions(-)

Comments

Jean-Jacques Hiblot Oct. 8, 2019, 3:58 p.m. UTC | #1
On 07/10/2019 13:25, Jean-Jacques Hiblot wrote:
> From: Tomi Valkeinen <tomi.valkeinen@ti.com>
>
> Add a helper function omap_gem_validate_flags() which validates the
> omap_bo flags passed from the userspace.
>
> Also drop the dev_err() message, as the userspace can cause that at
> will.
>
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
> ---
>   drivers/gpu/drm/omapdrm/omap_gem.c | 40 ++++++++++++++++++++++++++----
>   1 file changed, 35 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/omapdrm/omap_gem.c b/drivers/gpu/drm/omapdrm/omap_gem.c
> index 27e0a2f8508a..e518d93ca6df 100644
> --- a/drivers/gpu/drm/omapdrm/omap_gem.c
> +++ b/drivers/gpu/drm/omapdrm/omap_gem.c
> @@ -1133,6 +1133,38 @@ void omap_gem_free_object(struct drm_gem_object *obj)
>   	kfree(omap_obj);
>   }
>   
> +static bool omap_gem_validate_flags(struct drm_device *dev, u32 flags)
> +{
> +	struct omap_drm_private *priv = dev->dev_private;
> +
> +	switch (flags & OMAP_BO_CACHE_MASK) {
> +	case OMAP_BO_CACHED:
> +	case OMAP_BO_WC:
> +	case OMAP_BO_CACHE_MASK:
> +		break;
> +
> +	default:
> +		return false;
> +	}
> +
> +	if (flags & OMAP_BO_TILED_MASK) {
> +		if (!priv->usergart)
> +			return false;
> +
> +		switch (flags & OMAP_BO_TILED_MASK) {
> +		case OMAP_BO_TILED_8:
> +		case OMAP_BO_TILED_16:
> +		case OMAP_BO_TILED_32:
> +			break;
> +
> +		default:
> +			return false;
> +		}
> +	}
> +
> +	return true;
> +}
> +
>   /* GEM buffer object constructor */
>   struct drm_gem_object *omap_gem_new(struct drm_device *dev,
>   		union omap_gem_size gsize, u32 flags)
> @@ -1144,13 +1176,11 @@ struct drm_gem_object *omap_gem_new(struct drm_device *dev,
>   	size_t size;
>   	int ret;
>   
> +	if (!omap_gem_validate_flags(dev, flags))
> +		return NULL;
> +
>   	/* Validate the flags and compute the memory and cache flags. */
>   	if (flags & OMAP_BO_TILED_MASK) {
> -		if (!priv->usergart) {
> -			dev_err(dev->dev, "Tiled buffers require DMM\n");
> -			return NULL;
> -		}
> -
>   		/*
>   		 * Tiled buffers are always shmem paged backed. When they are
>   		 * scanned out, they are remapped into DMM/TILER.
Reviewed-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/omapdrm/omap_gem.c b/drivers/gpu/drm/omapdrm/omap_gem.c
index 27e0a2f8508a..e518d93ca6df 100644
--- a/drivers/gpu/drm/omapdrm/omap_gem.c
+++ b/drivers/gpu/drm/omapdrm/omap_gem.c
@@ -1133,6 +1133,38 @@  void omap_gem_free_object(struct drm_gem_object *obj)
 	kfree(omap_obj);
 }
 
+static bool omap_gem_validate_flags(struct drm_device *dev, u32 flags)
+{
+	struct omap_drm_private *priv = dev->dev_private;
+
+	switch (flags & OMAP_BO_CACHE_MASK) {
+	case OMAP_BO_CACHED:
+	case OMAP_BO_WC:
+	case OMAP_BO_CACHE_MASK:
+		break;
+
+	default:
+		return false;
+	}
+
+	if (flags & OMAP_BO_TILED_MASK) {
+		if (!priv->usergart)
+			return false;
+
+		switch (flags & OMAP_BO_TILED_MASK) {
+		case OMAP_BO_TILED_8:
+		case OMAP_BO_TILED_16:
+		case OMAP_BO_TILED_32:
+			break;
+
+		default:
+			return false;
+		}
+	}
+
+	return true;
+}
+
 /* GEM buffer object constructor */
 struct drm_gem_object *omap_gem_new(struct drm_device *dev,
 		union omap_gem_size gsize, u32 flags)
@@ -1144,13 +1176,11 @@  struct drm_gem_object *omap_gem_new(struct drm_device *dev,
 	size_t size;
 	int ret;
 
+	if (!omap_gem_validate_flags(dev, flags))
+		return NULL;
+
 	/* Validate the flags and compute the memory and cache flags. */
 	if (flags & OMAP_BO_TILED_MASK) {
-		if (!priv->usergart) {
-			dev_err(dev->dev, "Tiled buffers require DMM\n");
-			return NULL;
-		}
-
 		/*
 		 * Tiled buffers are always shmem paged backed. When they are
 		 * scanned out, they are remapped into DMM/TILER.