Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a343c9b7 authored by Paolo Bonzini's avatar Paolo Bonzini
Browse files

KVM: introduce __kvm_io_bus_sort_cmp



kvm_io_bus_sort_cmp is used also directly, not just as a callback for
sort and bsearch.  In these cases, it is handy to have a type-safe
variant.  This patch introduces such a variant, __kvm_io_bus_sort_cmp,
and uses it throughout kvm_main.c.

Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 9576c4cd
Loading
Loading
Loading
Loading
+12 −9
Original line number Original line Diff line number Diff line
@@ -2815,11 +2815,9 @@ static void kvm_io_bus_destroy(struct kvm_io_bus *bus)
	kfree(bus);
	kfree(bus);
}
}


static int kvm_io_bus_sort_cmp(const void *p1, const void *p2)
static inline int __kvm_io_bus_sort_cmp(const struct kvm_io_range *r1,
                                        const struct kvm_io_range *r2)
{
{
	const struct kvm_io_range *r1 = p1;
	const struct kvm_io_range *r2 = p2;

	if (r1->addr < r2->addr)
	if (r1->addr < r2->addr)
		return -1;
		return -1;
	if (r1->addr + r1->len > r2->addr + r2->len)
	if (r1->addr + r1->len > r2->addr + r2->len)
@@ -2827,6 +2825,11 @@ static int kvm_io_bus_sort_cmp(const void *p1, const void *p2)
	return 0;
	return 0;
}
}


static int kvm_io_bus_sort_cmp(const void *p1, const void *p2)
{
	return __kvm_io_bus_sort_cmp(p1, p2);
}

static int kvm_io_bus_insert_dev(struct kvm_io_bus *bus, struct kvm_io_device *dev,
static int kvm_io_bus_insert_dev(struct kvm_io_bus *bus, struct kvm_io_device *dev,
			  gpa_t addr, int len)
			  gpa_t addr, int len)
{
{
@@ -2860,7 +2863,7 @@ static int kvm_io_bus_get_first_dev(struct kvm_io_bus *bus,


	off = range - bus->range;
	off = range - bus->range;


	while (off > 0 && kvm_io_bus_sort_cmp(&key, &bus->range[off-1]) == 0)
	while (off > 0 && __kvm_io_bus_sort_cmp(&key, &bus->range[off-1]) == 0)
		off--;
		off--;


	return off;
	return off;
@@ -2876,7 +2879,7 @@ static int __kvm_io_bus_write(struct kvm_io_bus *bus,
		return -EOPNOTSUPP;
		return -EOPNOTSUPP;


	while (idx < bus->dev_count &&
	while (idx < bus->dev_count &&
		kvm_io_bus_sort_cmp(range, &bus->range[idx]) == 0) {
		__kvm_io_bus_sort_cmp(range, &bus->range[idx]) == 0) {
		if (!kvm_iodevice_write(bus->range[idx].dev, range->addr,
		if (!kvm_iodevice_write(bus->range[idx].dev, range->addr,
					range->len, val))
					range->len, val))
			return idx;
			return idx;
@@ -2920,7 +2923,7 @@ int kvm_io_bus_write_cookie(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,


	/* First try the device referenced by cookie. */
	/* First try the device referenced by cookie. */
	if ((cookie >= 0) && (cookie < bus->dev_count) &&
	if ((cookie >= 0) && (cookie < bus->dev_count) &&
	    (kvm_io_bus_sort_cmp(&range, &bus->range[cookie]) == 0))
	    (__kvm_io_bus_sort_cmp(&range, &bus->range[cookie]) == 0))
		if (!kvm_iodevice_write(bus->range[cookie].dev, addr, len,
		if (!kvm_iodevice_write(bus->range[cookie].dev, addr, len,
					val))
					val))
			return cookie;
			return cookie;
@@ -2942,7 +2945,7 @@ static int __kvm_io_bus_read(struct kvm_io_bus *bus, struct kvm_io_range *range,
		return -EOPNOTSUPP;
		return -EOPNOTSUPP;


	while (idx < bus->dev_count &&
	while (idx < bus->dev_count &&
		kvm_io_bus_sort_cmp(range, &bus->range[idx]) == 0) {
		__kvm_io_bus_sort_cmp(range, &bus->range[idx]) == 0) {
		if (!kvm_iodevice_read(bus->range[idx].dev, range->addr,
		if (!kvm_iodevice_read(bus->range[idx].dev, range->addr,
				       range->len, val))
				       range->len, val))
			return idx;
			return idx;
@@ -2986,7 +2989,7 @@ int kvm_io_bus_read_cookie(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,


	/* First try the device referenced by cookie. */
	/* First try the device referenced by cookie. */
	if ((cookie >= 0) && (cookie < bus->dev_count) &&
	if ((cookie >= 0) && (cookie < bus->dev_count) &&
	    (kvm_io_bus_sort_cmp(&range, &bus->range[cookie]) == 0))
	    (__kvm_io_bus_sort_cmp(&range, &bus->range[cookie]) == 0))
		if (!kvm_iodevice_read(bus->range[cookie].dev, addr, len,
		if (!kvm_iodevice_read(bus->range[cookie].dev, addr, len,
				       val))
				       val))
			return cookie;
			return cookie;