aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/xen/evtchn.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/xen/evtchn.c')
-rw-r--r--drivers/xen/evtchn.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/drivers/xen/evtchn.c b/drivers/xen/evtchn.c
index 38272ad24551..f4edd6df3df2 100644
--- a/drivers/xen/evtchn.c
+++ b/drivers/xen/evtchn.c
@@ -316,7 +316,6 @@ static int evtchn_resize_ring(struct per_user_data *u)
316{ 316{
317 unsigned int new_size; 317 unsigned int new_size;
318 evtchn_port_t *new_ring, *old_ring; 318 evtchn_port_t *new_ring, *old_ring;
319 unsigned int p, c;
320 319
321 /* 320 /*
322 * Ensure the ring is large enough to capture all possible 321 * Ensure the ring is large enough to capture all possible
@@ -346,20 +345,17 @@ static int evtchn_resize_ring(struct per_user_data *u)
346 /* 345 /*
347 * Copy the old ring contents to the new ring. 346 * Copy the old ring contents to the new ring.
348 * 347 *
349 * If the ring contents crosses the end of the current ring, 348 * To take care of wrapping, a full ring, and the new index
350 * it needs to be copied in two chunks. 349 * pointing into the second half, simply copy the old contents
350 * twice.
351 * 351 *
352 * +---------+ +------------------+ 352 * +---------+ +------------------+
353 * |34567 12| -> | 1234567 | 353 * |34567 12| -> |34567 1234567 12|
354 * +-----p-c-+ +------------------+ 354 * +-----p-c-+ +-------c------p---+
355 */ 355 */
356 p = evtchn_ring_offset(u, u->ring_prod); 356 memcpy(new_ring, old_ring, u->ring_size * sizeof(*u->ring));
357 c = evtchn_ring_offset(u, u->ring_cons); 357 memcpy(new_ring + u->ring_size, old_ring,
358 if (p < c) { 358 u->ring_size * sizeof(*u->ring));
359 memcpy(new_ring + c, u->ring + c, (u->ring_size - c) * sizeof(*u->ring));
360 memcpy(new_ring + u->ring_size, u->ring, p * sizeof(*u->ring));
361 } else
362 memcpy(new_ring + c, u->ring + c, (p - c) * sizeof(*u->ring));
363 359
364 u->ring = new_ring; 360 u->ring = new_ring;
365 u->ring_size = new_size; 361 u->ring_size = new_size;