From patchwork Thu Nov 11 14:03:26 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 70807 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5A575B7149 for ; Fri, 12 Nov 2010 01:05:14 +1100 (EST) Received: from localhost ([127.0.0.1]:34768 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PGXm3-0003my-08 for incoming@patchwork.ozlabs.org; Thu, 11 Nov 2010 09:05:11 -0500 Received: from [140.186.70.92] (port=55195 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PGXka-0003Je-Rt for qemu-devel@nongnu.org; Thu, 11 Nov 2010 09:03:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PGXkZ-0006U2-NL for qemu-devel@nongnu.org; Thu, 11 Nov 2010 09:03:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41748) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PGXkZ-0006SX-Fw for qemu-devel@nongnu.org; Thu, 11 Nov 2010 09:03:39 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oABE3VR1030347 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 11 Nov 2010 09:03:31 -0500 Received: from doriath (ovpn-113-43.phx2.redhat.com [10.3.113.43]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id oABE3QrH002533 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Thu, 11 Nov 2010 09:03:29 -0500 Date: Thu, 11 Nov 2010 12:03:26 -0200 From: Luiz Capitulino To: qemu-devel@nongnu.org Message-ID: <20101111120326.22020026@doriath> Organization: Red Hat Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Markus Armbruster , gleb@redhat.com Subject: [Qemu-devel] [PATCH v2] ioport: Fix duplicated code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Functions register_ioport_read() and register_ioport_write() are almost identical, the only difference is that they write to different arrays. Introduce register_ioport_rw() to handle this difference and change both functions to use it instead of duplicating code. Signed-off-by: Luiz Capitulino --- v2: Fix error messages and make register_ioport_rw() register both handlers at the same call ioport.c | 37 ++++++++++++++++++------------------- 1 files changed, 18 insertions(+), 19 deletions(-) diff --git a/ioport.c b/ioport.c index ec3dc65..4560973 100644 --- a/ioport.c +++ b/ioport.c @@ -137,41 +137,40 @@ static int ioport_bsize(int size, int *bsize) } /* size is the word size in byte */ -int register_ioport_read(pio_addr_t start, int length, int size, - IOPortReadFunc *func, void *opaque) +static int register_ioport_rw(pio_addr_t start, int length, int size, + IOPortReadFunc *read_func, + IOPortWriteFunc *write_func, void *opaque) { int i, bsize; if (ioport_bsize(size, &bsize)) { - hw_error("register_ioport_read: invalid size"); + hw_error("register_ioport_rw: invalid size"); return -1; } for(i = start; i < start + length; i += size) { - ioport_read_table[bsize][i] = func; + if (read_func) { + ioport_read_table[bsize][i] = read_func; + } + if (write_func) { + ioport_write_table[bsize][i] = write_func; + } if (ioport_opaque[i] != NULL && ioport_opaque[i] != opaque) - hw_error("register_ioport_read: invalid opaque"); + hw_error("register_ioport_rw: invalid opaque"); ioport_opaque[i] = opaque; } return 0; } -/* size is the word size in byte */ +int register_ioport_read(pio_addr_t start, int length, int size, + IOPortReadFunc *func, void *opaque) +{ + return register_ioport_rw(start, length, size, func, NULL, opaque); +} + int register_ioport_write(pio_addr_t start, int length, int size, IOPortWriteFunc *func, void *opaque) { - int i, bsize; - - if (ioport_bsize(size, &bsize)) { - hw_error("register_ioport_write: invalid size"); - return -1; - } - for(i = start; i < start + length; i += size) { - ioport_write_table[bsize][i] = func; - if (ioport_opaque[i] != NULL && ioport_opaque[i] != opaque) - hw_error("register_ioport_write: invalid opaque"); - ioport_opaque[i] = opaque; - } - return 0; + return register_ioport_rw(start, length, size, NULL, func, opaque); } void isa_unassign_ioport(pio_addr_t start, int length)