public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Chris Metcalf <cmetcalf@ezchip.com>
Cc: linux-kernel@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>,
	linux-arch@vger.kernel.org
Subject: Re: [PATCH 2/2] tile: enable sparse checks for get/put_user
Date: Wed, 14 Jan 2015 00:29:35 +0200	[thread overview]
Message-ID: <20150113222935.GB23641@redhat.com> (raw)
In-Reply-To: <201501131951.t0DJpIKt027023@lab-37.internal.tilera.com>

On Tue, Jan 13, 2015 at 02:41:20PM -0500, Chris Metcalf wrote:
> Add an extra intermediate variable to __get_user and __put_user
> to give sparse an opportunity to detect mismatches.
> 
> Signed-off-by: Chris Metcalf <cmetcalf@ezchip.com>

Reviewed-by: Michael S. Tsirkin <mst@redhat.com>

> ---
>  arch/tile/include/asm/uaccess.h | 19 +++++++++++--------
>  1 file changed, 11 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
> index b81b24a8489b..f41cb53cf645 100644
> --- a/arch/tile/include/asm/uaccess.h
> +++ b/arch/tile/include/asm/uaccess.h
> @@ -210,14 +210,16 @@ extern int __get_user_bad(void)
>  #define __get_user(x, ptr)						\
>  	({								\
>  		int __ret;						\
> +		typeof(x) _x;						\
>  		__chk_user_ptr(ptr);					\
>  		switch (sizeof(*(ptr))) {				\
> -		case 1: __get_user_1(x, ptr, __ret); break;		\
> -		case 2: __get_user_2(x, ptr, __ret); break;		\
> -		case 4: __get_user_4(x, ptr, __ret); break;		\
> -		case 8: __get_user_8(x, ptr, __ret); break;		\
> +		case 1: __get_user_1(_x, ptr, __ret); break;		\
> +		case 2: __get_user_2(_x, ptr, __ret); break;		\
> +		case 4: __get_user_4(_x, ptr, __ret); break;		\
> +		case 8: __get_user_8(_x, ptr, __ret); break;		\
>  		default: __ret = __get_user_bad(); break;		\
>  		}							\
> +		(x) = (typeof(*(ptr))) _x;				\
>  		__ret;							\
>  	})
>  
> @@ -289,12 +291,13 @@ extern int __put_user_bad(void)
>  #define __put_user(x, ptr)						\
>  ({									\
>  	int __ret;							\
> +	typeof(*(ptr)) _x = (x);					\
>  	__chk_user_ptr(ptr);						\
>  	switch (sizeof(*(ptr))) {					\
> -	case 1: __put_user_1(x, ptr, __ret); break;			\
> -	case 2: __put_user_2(x, ptr, __ret); break;			\
> -	case 4: __put_user_4(x, ptr, __ret); break;			\
> -	case 8: __put_user_8(x, ptr, __ret); break;			\
> +	case 1: __put_user_1(_x, ptr, __ret); break;			\
> +	case 2: __put_user_2(_x, ptr, __ret); break;			\
> +	case 4: __put_user_4(_x, ptr, __ret); break;			\
> +	case 8: __put_user_8(_x, ptr, __ret); break;			\
>  	default: __ret = __put_user_bad(); break;			\
>  	}								\
>  	__ret;								\
> -- 
> 2.1.2

  reply	other threads:[~2015-01-13 22:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-13 19:39 [PATCH 1/2] tile: fix put_user sparse errors Chris Metcalf
2015-01-13 19:41 ` [PATCH 2/2] tile: enable sparse checks for get/put_user Chris Metcalf
2015-01-13 22:29   ` Michael S. Tsirkin [this message]
2015-01-13 22:29 ` [PATCH 1/2] tile: fix put_user sparse errors Michael S. Tsirkin

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=20150113222935.GB23641@redhat.com \
    --to=mst@redhat.com \
    --cc=arnd@arndb.de \
    --cc=cmetcalf@ezchip.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox