From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sasha Levin Subject: [PATCH 2/5] ioeventfd: Add helper functions for reading and writing Date: Wed, 6 Jul 2011 07:37:55 +0300 Message-ID: <1309927078-5983-2-git-send-email-levinsasha928@gmail.com> References: <1309927078-5983-1-git-send-email-levinsasha928@gmail.com> Cc: Sasha Levin To: kvm@vger.kernel.org Return-path: Received: from mail-ww0-f44.google.com ([74.125.82.44]:58854 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751585Ab1GFEiK (ORCPT ); Wed, 6 Jul 2011 00:38:10 -0400 Received: by wwe5 with SMTP id 5so6552449wwe.1 for ; Tue, 05 Jul 2011 21:38:09 -0700 (PDT) In-Reply-To: <1309927078-5983-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: Add get_val() and set_val() to help getting and setting a natural sized variable pointed by a void ptr. Signed-off-by: Sasha Levin --- virt/kvm/eventfd.c | 57 ++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 42 insertions(+), 15 deletions(-) diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c index 5fb09b4..a1a3f66 100644 --- a/virt/kvm/eventfd.c +++ b/virt/kvm/eventfd.c @@ -444,23 +444,10 @@ ioeventfd_release(struct _ioeventfd *p) kfree(p); } -static bool -ioeventfd_in_range(struct _ioeventfd *p, gpa_t addr, int len, const void *val) +static u64 get_val(const void *val, int len) { u64 _val; - if (!((addr >= p->addr) && ((addr + len) <= (p->addr + p->length)))) - /* the entire address-range must be within the ioeventfd */ - return false; - - if (p->wildcard) - /* all else equal, wildcard is always a hit */ - return true; - - /* otherwise, we have to actually compare the data */ - - BUG_ON(!IS_ALIGNED((unsigned long)val, len)); - switch (len) { case 1: _val = *(u8 *)val; @@ -475,8 +462,48 @@ ioeventfd_in_range(struct _ioeventfd *p, gpa_t addr, int len, const void *val) _val = *(u64 *)val; break; default: - return false; + return 0; + } + + return _val; +} + +static void set_val(void *val, int len, u64 new_val) +{ + switch (len) { + case 1: + *(u8 *)val = new_val; + break; + case 2: + *(u16 *)val = new_val; + break; + case 4: + *(u32 *)val = new_val; + break; + case 8: + *(u64 *)val = new_val; + break; } +} + +static bool +ioeventfd_in_range(struct _ioeventfd *p, gpa_t addr, int len, const void *val) +{ + u64 _val; + + if (!((addr >= p->addr) && ((addr + len) <= (p->addr + p->length)))) + /* the entire address-range must be within the ioeventfd */ + return false; + + if (p->wildcard) + /* all else equal, wildcard is always a hit */ + return true; + + /* otherwise, we have to actually compare the data */ + + BUG_ON(!IS_ALIGNED((unsigned long)val, len)); + + _val = get_val(val, len); return _val == p->datamatch ? true : false; } -- 1.7.6