All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mika Kuoppala <mika.kuoppala@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>, intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH igt] lib: Assert that the internal gem_create	interface matches the ioctl
Date: Tue, 03 Oct 2017 17:19:24 +0300	[thread overview]
Message-ID: <87y3os2u1f.fsf@gaia.fi.intel.com> (raw)
In-Reply-To: <20171003140518.29004-1-chris@chris-wilson.co.uk>

Chris Wilson <chris@chris-wilson.co.uk> writes:

> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> ---
>  lib/igt_core.h       | 14 ++++++++++++++
>  lib/ioctl_wrappers.c |  4 ++++
>  2 files changed, 18 insertions(+)
>
> diff --git a/lib/igt_core.h b/lib/igt_core.h
> index f8543d65..f5f65984 100644
> --- a/lib/igt_core.h
> +++ b/lib/igt_core.h
> @@ -932,4 +932,18 @@ int igt_system_quiet(const char *command);
>  		free(buf); \
>  	} while (0)
>  
> +/**
> + * igt_typecheck:
> + * @type: The intended type we expect the variable to be
> + * @x: The variable we wish to check
> + *
> + * Performs a *compile-time* check that a variable is of a particular type.
> + */
> +#define igt_typecheck(type, x) ({ \
> +	type __dummy; \
> +        typeof(x) __dummy2; \
> +        (void)(&__dummy == &__dummy2); \
> +        1; \
> +})
> +
>  #endif /* IGT_CORE_H */
> diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
> index 87511fc6..0b523fac 100644
> --- a/lib/ioctl_wrappers.c
> +++ b/lib/ioctl_wrappers.c
> @@ -558,6 +558,10 @@ int __gem_create(int fd, uint64_t size, uint32_t *handle)
>  	};
>  	int err = 0;
>  
> +	/* Ensure that our internal interface matches the kernel's */
> +	igt_typecheck(typeof(create.size), size);
> +	igt_typecheck(typeof(create.handle), *handle);

Seems to do what it is missing from the tin :)

Fill the commit message and sprinkle more on the ioctl_wrappers.c?
-Mika

> +
>  	if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create) == 0)
>  		*handle = create.handle;
>  	else
> -- 
> 2.14.2
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2017-10-03 14:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-03 14:05 [PATCH igt] lib: Assert that the internal gem_create interface matches the ioctl Chris Wilson
2017-10-03 14:19 ` Mika Kuoppala [this message]
2017-10-03 14:29   ` Chris Wilson
2017-10-03 14:25 ` Chris Wilson
2017-10-03 20:33 ` ✓ Fi.CI.BAT: success for " Patchwork
2017-10-03 22:27 ` ✓ Fi.CI.IGT: " 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=87y3os2u1f.fsf@gaia.fi.intel.com \
    --to=mika.kuoppala@linux.intel.com \
    --cc=chris@chris-wilson.co.uk \
    --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.