[PATCH] staging: comedi: remove __user annotation inside of struct's

Ian Abbott abbotti at mev.co.uk
Thu May 10 11:05:26 UTC 2012


On 2012-05-09 15:19, Dan Carpenter wrote:
> On Wed, May 09, 2012 at 12:01:25PM +0100, Ian Abbott wrote:
>> Are there any handy macros for casting pointers to __user pointers,
>> something like
>>
>> #define _user(p) ((typeof(*(p)) __user *)(p))
>>
>> but preferably without the repeated expansion of 'p' in case of
>> side-effects?
>
> typeof() doesn't have side effects.
>
> #include<stdio.h>
>
> int main(void)
> {
> 	int x = 0;
> 	typeof(x++) y;
>
> 	printf("%d\n", x);
>
> 	return 0;
> }
>
> regards,
> dan carpenter

Yes, you're correct of course.  I was unnecessarily worried about the 
double-expansion of the macro parameter but it's safe in this case.

BTW, the intention of this macro is so you can write things like:

   copy_from_user(data, _user(insn.data), insn.n * sizeof(insn.data[0]));

instead of:

   copy_from_user(data, (unsigned int __user *)insn.data, insn.n * 
sizeof(insn.data[0]));

where the member insn.data is a 'unsigned int *' but is used for both 
__user pointers and kernel pointers.

-- 
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti at mev.co.uk>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-



More information about the devel mailing list