Date: Mon, 29 Dec 2008 11:45:10 +0100 From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= <des@des.no> To: Hans Petter Selasky <hselasky@c2i.net> Cc: freebsd-current@freebsd.org, current@freebsd.org, Alfred Perlstein <alfred@freebsd.org> Subject: Re: HEADSUP usb2 (usb4bsd) to become default in 2 weeks. Message-ID: <864p0n6z0p.fsf@ds4.des.no> In-Reply-To: <200812291125.30222.hselasky@c2i.net> (Hans Petter Selasky's message of "Mon, 29 Dec 2008 11:25:28 %2B0100") References: <20081222214010.GA18389@elvis.mu.org> <200812231736.29198.hselasky@c2i.net> <86d4fb72se.fsf@ds4.des.no> <200812291125.30222.hselasky@c2i.net>
next in thread | previous in thread | raw e-mail | index | archive | help
Hans Petter Selasky <hselasky@c2i.net> writes: > The following function is a candidate for de-constifying. You have a data= =20 > pointer there which is read or write, and to be able to transfer constant= =20 > data you need to do a deconst before passing the pointer to this function. > > usb2_do_request_flags(struct usb2_device *udev, struct mtx *mtx, > struct usb2_device_request *req, void *data, uint32_t flags, > uint16_t *actlen, uint32_t timeout) In this particular case, I would create separate wrappers for read and write requests, and have the read version assert that the direction bit is set before deconst'ing. > Deconstifying is not illegal in C using standard pointer arithmetics. > (void *)((const uint8_t *)(ptr) - (const uint8_t *)0) Undefined behaviour. You can only compare or perform arithmetic on pointers to elements in the same array or one element past the end of the array. The correct way to deconst (if you must) is to cast through uintptr_t, or in FreeBSD, use the __DECONST() macro. DES --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?864p0n6z0p.fsf>