lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20130731090457.GB7484@redhat.com>
Date:	Wed, 31 Jul 2013 12:04:57 +0300
From:	Gleb Natapov <gleb@...hat.com>
To:	Paolo Bonzini <pbonzini@...hat.com>
Cc:	linux-kernel@...r.kernel.org, cornelia.huck@...ibm.com,
	kvm@...r.kernel.org
Subject: Re: [PATCH] KVM: introduce __kvm_io_bus_sort_cmp

On Tue, Jul 30, 2013 at 05:05:37PM +0200, Paolo Bonzini wrote:
> 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: Paolo Bonzini <pbonzini@...hat.com>
> ---
>  virt/kvm/kvm_main.c | 21 ++++++++++++---------
>  1 file changed, 12 insertions(+), 9 deletions(-)
> 
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index b2a2bb9..e0d127d 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -2812,11 +2812,9 @@ static void kvm_io_bus_destroy(struct kvm_io_bus *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)
IMO calling this one kvm_io_bus_sort_cmp and another one
kvm_io_bus_cmp will be better naming.

>  {
> -	const struct kvm_io_range *r1 = p1;
> -	const struct kvm_io_range *r2 = p2;
> -
>  	if (r1->addr < r2->addr)
>  		return -1;
>  	if (r1->addr + r1->len > r2->addr + r2->len)
> @@ -2824,6 +2822,11 @@ static int kvm_io_bus_sort_cmp(const void *p1, const void *p2)
>  	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,
>  			  gpa_t addr, int len)
>  {
> @@ -2857,7 +2860,7 @@ static int kvm_io_bus_get_first_dev(struct kvm_io_bus *bus,
>  
>  	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--;
>  
>  	return off;
> @@ -2873,7 +2876,7 @@ static int __kvm_io_bus_write(struct kvm_io_bus *bus,
>  		return -EOPNOTSUPP;
>  
>  	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,
>  					range->len, val))
>  			return idx;
> @@ -2917,7 +2920,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. */
>  	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,
>  					val))
>  			return cookie;
> @@ -2939,7 +2942,7 @@ static int __kvm_io_bus_read(struct kvm_io_bus *bus, struct kvm_io_range *range,
>  		return -EOPNOTSUPP;
>  
>  	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,
>  				       range->len, val))
>  			return idx;
> @@ -2983,7 +2986,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. */
>  	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,
>  				       val))
>  			return cookie;
> -- 
> 1.8.1.4

--
			Gleb.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ