Em Tue, 17 Apr 2018 15:11:10 +0200 Hans Verkuil <hansv...@cisco.com> escreveu:
> >> Be aware that the unsigned char * cast is actually a bug: it will clamp the > >> u32 'blocks' value to a u8. > >> > >> Regards, > >> > >> Hans > > > > What about this approach (code untested)? > > I prefer the explicit casts. These are special situations and hiding it in > defines makes it actually harder to follow. There are just one special case there: USERPTR, where we force a cast to unsigned long: drivers/media/v4l2-core/v4l2-compat-ioctl32.c: put_user((unsigned long)compat_ptr(p), &p64->m.userptr)) ... drivers/media/v4l2-core/v4l2-compat-ioctl32.c: put_user((unsigned long)compat_ptr(userptr), drivers/media/v4l2-core/v4l2-compat-ioctl32.c- &p64->m.userptr)) I kept it out of the macros. IMO, maintaining the code with the type_of() is more error-prune, as the cast will be done the way it should. The cases where some other cast like is needed - with is what it was done for USERPTR should be explicit (and, btw, they should be properly documented why doing that). I don't remember anymore why it is casting to unsigned long, but, based on v4l2-compliance tests, it seems that such cast works. Thanks, Mauro