From: Ian Jackson Subject: Re: [PATCH v12 02/17] libxl: refactor disk addition to take a helper Date: Thu, 26 Jul 2012 12:06:41 +0100 Message-ID: <20497.9409.111042.309732@mariner.uk.xensource.com> References: <1343215161-27546-1-git-send-email-roger.pau@citrix.com> <1343215161-27546-3-git-send-email-roger.pau@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1343215161-27546-3-git-send-email-roger.pau@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Roger Pau Monne Cc: "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org Roger Pau Monne writes ("[PATCH v12 02/17] libxl: refactor disk addition to take a helper"): > Change libxl__device_disk_add to no longer take a xs transaction and > instead pass a helper for the local attach case that's used to get the > free vdev. ... > +static int device_disk_add(libxl__gc *gc, uint32_t domid, > + libxl_device_disk *disk, > + void *get_vdev(libxl__gc *, void *, > + xs_transaction_t), > + void *get_vdev_user) get_vdev needs to return a char*. The point of the void* is that if another caller of device_disk_add needs to use this feature, the type of get_vdev_user may need to be something different for this user; this is why passthrough pointers like this need to be void*s. But another user of this feature will have to have their get_vdev return a char*, since that's how the value is used. So: +static int device_disk_add(libxl__gc *gc, uint32_t domid, + libxl_device_disk *disk, + char *get_vdev(libxl__gc *, void *, + xs_transaction_t), + void *get_vdev_user) > + (void *) libxl__alloc_vdev, This is not permitted. The (malicious) compiler might choose to misoptimise the program as a result. You must not cast a function from one type to another. The actual type of the function must be the same where it is defined and called. So either libxl__alloc_vdev needs to change its type to match, or you need to make a wrapper function which contains the upcast from void* to const char*. Ian.