From owner-freebsd-current@FreeBSD.ORG Mon Dec 29 10:45:11 2008 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 877B21065670; Mon, 29 Dec 2008 10:45:11 +0000 (UTC) (envelope-from des@des.no) Received: from tim.des.no (tim.des.no [194.63.250.121]) by mx1.freebsd.org (Postfix) with ESMTP id 3C0BC8FC14; Mon, 29 Dec 2008 10:45:11 +0000 (UTC) (envelope-from des@des.no) Received: from ds4.des.no (des.no [84.49.246.2]) by smtp.des.no (Postfix) with ESMTP id 75B536D43F; Mon, 29 Dec 2008 10:45:10 +0000 (UTC) Received: by ds4.des.no (Postfix, from userid 1001) id 52D5E844A1; Mon, 29 Dec 2008 11:45:10 +0100 (CET) From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= To: Hans Petter Selasky References: <20081222214010.GA18389@elvis.mu.org> <200812231736.29198.hselasky@c2i.net> <86d4fb72se.fsf@ds4.des.no> <200812291125.30222.hselasky@c2i.net> Date: Mon, 29 Dec 2008 11:45:10 +0100 In-Reply-To: <200812291125.30222.hselasky@c2i.net> (Hans Petter Selasky's message of "Mon, 29 Dec 2008 11:25:28 +0100") Message-ID: <864p0n6z0p.fsf@ds4.des.no> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Cc: freebsd-current@freebsd.org, current@freebsd.org, Alfred Perlstein Subject: Re: HEADSUP usb2 (usb4bsd) to become default in 2 weeks. X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Dec 2008 10:45:11 -0000 Hans Petter Selasky 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