public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Ville Syrjala <ville.syrjala@linux.intel.com>
Cc: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 6/6] drm: Reject bad property flag combinations
Date: Tue, 6 Mar 2018 19:22:51 +0100	[thread overview]
Message-ID: <20180306182251.GX22212@phenom.ffwll.local> (raw)
In-Reply-To: <20180306164849.2862-6-ville.syrjala@linux.intel.com>

On Tue, Mar 06, 2018 at 06:48:49PM +0200, Ville Syrjala wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> 
> Pimp drm_property_type_valid() to check for more fails with the
> property flags. Also make the check before adding the property,
> and bail out if things look bad.
> 
> Since we're now chekcing for more than the type let's also
> change the function name to drm_property_flags_valid().
> 
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
>  drivers/gpu/drm/drm_property.c | 29 +++++++++++++++++++++++------
>  1 file changed, 23 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_property.c b/drivers/gpu/drm/drm_property.c
> index 027a50e55e96..6ac6ee41a6a3 100644
> --- a/drivers/gpu/drm/drm_property.c
> +++ b/drivers/gpu/drm/drm_property.c
> @@ -50,11 +50,27 @@
>   * IOCTL and in the get/set property IOCTL.
>   */
>  
> -static bool drm_property_type_valid(struct drm_property *property)
> +static bool drm_property_flags_valid(u32 flags)
>  {
> -	if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
> -		return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
> -	return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
> +	u32 legacy_type = flags & DRM_MODE_PROP_LEGACY_TYPE;
> +	u32 ext_type = flags & DRM_MODE_PROP_EXTENDED_TYPE;
> +
> +	/* Reject undefined/deprecated flags */
> +	if (flags & ~(DRM_MODE_PROP_LEGACY_TYPE |
> +		      DRM_MODE_PROP_EXTENDED_TYPE |
> +		      DRM_MODE_PROP_IMMUTABLE |
> +		      DRM_MODE_PROP_ATOMIC))
> +		return false;
> +
> +	/* We want either a legacy type or an extended type, but not both */
> +	if (!legacy_type == !ext_type)
> +		return false;
> +
> +	/* Only one legacy type at a time please */
> +	if (legacy_type && !is_power_of_2(legacy_type))
> +		return false;
> +
> +	return true;
>  }

I think this catches everything. Well except not-yet-assigned
EXTENDED_TYPE defines, but really we can overdo this :-)

Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
>  
>  /**
> @@ -79,6 +95,9 @@ struct drm_property *drm_property_create(struct drm_device *dev,
>  	struct drm_property *property = NULL;
>  	int ret;
>  
> +	if (WARN_ON(!drm_property_flags_valid(flags)))
> +		return NULL;
> +
>  	if (WARN_ON(strlen(name) >= DRM_PROP_NAME_LEN))
>  		return NULL;
>  
> @@ -108,8 +127,6 @@ struct drm_property *drm_property_create(struct drm_device *dev,
>  
>  	list_add_tail(&property->head, &dev->mode_config.property_list);
>  
> -	WARN_ON(!drm_property_type_valid(property));
> -
>  	return property;
>  fail:
>  	kfree(property->values);
> -- 
> 2.16.1
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2018-03-06 18:22 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-06 16:48 [PATCH 1/6] drm: Reject replacing property enum values Ville Syrjala
2018-03-06 16:48 ` [PATCH 2/6] drm: WARN when trying add enum values to non-enum/bitmask properties Ville Syrjala
2018-03-06 18:16   ` Daniel Vetter
2018-03-06 16:48 ` [PATCH 3/6] drm: WARN when trying to add enum value > 63 to a bitmask property Ville Syrjala
2018-03-06 18:16   ` Daniel Vetter
2018-03-06 16:48 ` [PATCH 4/6] drm/uapi: Deprecate DRM_MODE_PROP_PENDING Ville Syrjala
2018-03-06 18:17   ` Daniel Vetter
2018-03-06 16:48 ` [PATCH 5/6] drm: Make property flags u32 Ville Syrjala
2018-03-06 18:19   ` [Intel-gfx] " Daniel Vetter
2018-03-06 16:48 ` [PATCH 6/6] drm: Reject bad property flag combinations Ville Syrjala
2018-03-06 18:22   ` Daniel Vetter [this message]
2018-03-07 18:50     ` Ville Syrjälä
2018-03-06 17:29 ` ✓ Fi.CI.BAT: success for series starting with [1/6] drm: Reject replacing property enum values Patchwork
2018-03-06 18:16 ` [PATCH 1/6] " Daniel Vetter
2018-03-06 21:49 ` ✗ Fi.CI.IGT: warning for series starting with [1/6] " Patchwork
2018-03-07 16:18   ` Ville Syrjälä

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=20180306182251.GX22212@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=ville.syrjala@linux.intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox