From patchwork Tue Jul 30 15:05:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 2835728 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4075B9F7D6 for ; Tue, 30 Jul 2013 15:06:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 742DA20494 for ; Tue, 30 Jul 2013 15:06:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BB05120456 for ; Tue, 30 Jul 2013 15:06:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752558Ab3G3PFw (ORCPT ); Tue, 30 Jul 2013 11:05:52 -0400 Received: from mail-ea0-f172.google.com ([209.85.215.172]:45163 "EHLO mail-ea0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752353Ab3G3PFv (ORCPT ); Tue, 30 Jul 2013 11:05:51 -0400 Received: by mail-ea0-f172.google.com with SMTP id r16so191865ead.31 for ; Tue, 30 Jul 2013 08:05:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer; bh=cQrHnC2obYVk/vnDAzOKZ4YN9tCPyfPcaRy0VVyVnto=; b=KTxgo2sCRwxo9m9MBeUBCg925RudNCCRlpAY3USmRfoONZjEhMwpCYjCDaomX/zfNC qoTVDy4Mh72v3ASMwe2twJX2r2eKgg95nAdRE4b6woocN0+2Ec9hi8hrrpjPzbhykxWN UDSE9HsC9Ti94TLq1AC/YioaGDs+X0MSgbaQuIYnNKGa6agiU4pa6o8kKlrnR4bixOCf 8LGQ+xtUvq5J9TSaw+KXDUZdK4UOB9VB/UhV9vt9x2/bpCtDMmWqr/m+eT29oqA7lRIM 4xtbFq4I17+6qHgQEPNg3oAt7qWEn1orE89A+RuZVW4SU3o0vsvA7/UPH4pVs7qqUUm+ 4HwQ== X-Received: by 10.14.87.133 with SMTP id y5mr64884596eee.50.1375196749170; Tue, 30 Jul 2013 08:05:49 -0700 (PDT) Received: from playground.station (net-2-39-8-162.cust.dsl.vodafone.it. [2.39.8.162]) by mx.google.com with ESMTPSA id n45sm111271334eew.1.2013.07.30.08.05.46 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 30 Jul 2013 08:05:48 -0700 (PDT) From: Paolo Bonzini To: linux-kernel@vger.kernel.org Cc: cornelia.huck@de.ibm.com, gnatapov@redhat.com, kvm@vger.kernel.org Subject: [PATCH] KVM: introduce __kvm_io_bus_sort_cmp Date: Tue, 30 Jul 2013 17:05:37 +0200 Message-Id: <1375196737-2264-1-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.1.4 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Acked-by: Cornelia Huck --- 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) { - 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;