From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:54707) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QCB1p-0001X8-Ef for qemu-devel@nongnu.org; Tue, 19 Apr 2011 09:31:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QCB1o-0002JG-9M for qemu-devel@nongnu.org; Tue, 19 Apr 2011 09:31:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:25056) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QCB1n-0002IQ-UT for qemu-devel@nongnu.org; Tue, 19 Apr 2011 09:31:40 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p3JDVc24029532 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 19 Apr 2011 09:31:38 -0400 Message-ID: <4DAD8F4F.5090008@redhat.com> Date: Tue, 19 Apr 2011 15:34:07 +0200 From: Kevin Wolf MIME-Version: 1.0 References: <1303216603-11658-1-git-send-email-kwolf@redhat.com> <1303216603-11658-4-git-send-email-kwolf@redhat.com> <20110419132019.GH16567@amit-x200.redhat.com> In-Reply-To: <20110419132019.GH16567@amit-x200.redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 3/5] ide/atapi: Use table instead of switch for commands List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Amit Shah Cc: qemu-devel@nongnu.org Am 19.04.2011 15:20, schrieb Amit Shah: > On (Tue) 19 Apr 2011 [14:36:41], Kevin Wolf wrote: > >> +struct { >> + void (*handler)(IDEState *s, uint8_t *buf); >> + int flags; >> +} atapi_cmd_table[0x100] = { >> + [ 0x00 ] = { cmd_test_unit_ready, 0 }, >> + [ 0x03 ] = { cmd_request_sense, ALLOW_UA }, >> + [ 0x12 ] = { cmd_inquiry, ALLOW_UA }, >> + [ 0x1a ] = { cmd_mode_sense, /* (6) */ 0 }, >> + [ 0x1b ] = { cmd_start_stop_unit, 0 }, >> + [ 0x1e ] = { cmd_prevent_allow_medium_removal, 0 }, >> + [ 0x25 ] = { cmd_read_cdvd_capacity, 0 }, >> + [ 0x28 ] = { cmd_read, /* (10) */ 0 }, >> + [ 0x2b ] = { cmd_seek, 0 }, >> + [ 0x43 ] = { cmd_read_toc_pma_atip, 0 }, >> + [ 0x46 ] = { cmd_get_configuration, ALLOW_UA }, >> + [ 0x4a ] = { cmd_get_event_status_notification, ALLOW_UA }, >> + [ 0x5a ] = { cmd_mode_sense, /* (10) */ 0 }, >> + [ 0xa8 ] = { cmd_read, /* (12) */ 0 }, >> + [ 0xad ] = { cmd_read_dvd_structure, 0 }, >> + [ 0xbb ] = { cmd_set_speed, 0 }, >> + [ 0xbd ] = { cmd_mechanism_status, 0 }, >> + [ 0xbe ] = { cmd_read_cd, 0 }, >> +}; > > I'd prefer to use the GPCMD_TEST_UNIT_READY, etc., defines we already > have in internal.h instead of using the command numbers here. In fact, I was considering to remove the GPCMD_* definitions because most of them are unused now (only cmd_mode_sense/cmd_read still use them to distinguish the variants). What I like about this table is that you have all information about a command directly visible: Its opcode, its name and any flags. Using the constants would hide the opcode again, duplicate the name and probably make the lines longer than 80 characters. Kevin