From patchwork Mon Oct 17 14:44:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 120218 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C747BB6F9F for ; Tue, 18 Oct 2011 01:44:42 +1100 (EST) Received: from localhost ([::1]:47238 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RFoQf-0002qv-5H for incoming@patchwork.ozlabs.org; Mon, 17 Oct 2011 10:44:37 -0400 Received: from eggs.gnu.org ([140.186.70.92]:38664) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RFoQT-0002qK-LB for qemu-devel@nongnu.org; Mon, 17 Oct 2011 10:44:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RFoQR-0003bT-7A for qemu-devel@nongnu.org; Mon, 17 Oct 2011 10:44:25 -0400 Received: from mail-iy0-f173.google.com ([209.85.210.173]:34435) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RFoQQ-0003bF-VN for qemu-devel@nongnu.org; Mon, 17 Oct 2011 10:44:23 -0400 Received: by iakl21 with SMTP id l21so7520989iak.4 for ; Mon, 17 Oct 2011 07:44:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:message-id:date:from:user-agent:mime-version:cc:subject :references:in-reply-to:content-type; bh=12Kz+yRuKELwnYtATnOI9sAq0MUN1YKKANjTAwWSkZM=; b=bzxKJYtPHP3YZisg5SttlXHdzEaPEqbUjECUVhGqlqfaUV2u2kBaMYz7kdDXNMaJV5 vh7QCuVkI9+3yTMM3vx6SpJvlFmprMIN6/4wzNhAxMphBN7ihdX6Wy9AaIBK/gVMFYIk 8Dnk3QEFN4OBrBcfE55SpxlVhz2/SUqUxCYu0= Received: by 10.231.0.217 with SMTP id 25mr9160941ibc.4.1318862662181; Mon, 17 Oct 2011 07:44:22 -0700 (PDT) Received: from yakj.usersys.redhat.com (93-34-218-143.ip51.fastwebnet.it. [93.34.218.143]) by mx.google.com with ESMTPS id z10sm36926623ibv.9.2011.10.17.07.44.18 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 17 Oct 2011 07:44:20 -0700 (PDT) Message-ID: <4E9C3F3F.6060909@redhat.com> Date: Mon, 17 Oct 2011 16:44:15 +0200 From: Paolo Bonzini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0) Gecko/20110927 Thunderbird/7.0 MIME-Version: 1.0 References: <1318503845-11473-1-git-send-email-pbonzini@redhat.com> <1318503845-11473-8-git-send-email-pbonzini@redhat.com> <4E9C3B59.5030800@redhat.com> <4E9C3BA1.30005@redhat.com> In-Reply-To: <4E9C3BA1.30005@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.210.173 Cc: Kevin Wolf , qemu-devel@nongnu.org Subject: Re: [Qemu-devel] [PATCH 07/35] scsi-disk: add stubs for more MMC commands X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On 10/17/2011 04:28 PM, Paolo Bonzini wrote: > On 10/17/2011 04:27 PM, Kevin Wolf wrote: >> Braces are missing here and in the other commands. > > Yes, but that's consistent with the rest of scsi-disk. I'll try to add > them and see how bad the conflicts are. Ok, half a dozen patches have to be rebased, but nothing monumental. I'll include the attached patch before this one. Paolo From e351ff2598c822d7fff79f4bbf394b35b8fa1841 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 17 Oct 2011 16:39:27 +0200 Subject: [PATCH] scsi-disk: fix coding style issues (braces) Signed-off-by: Paolo Bonzini --- hw/scsi-disk.c | 71 ++++++++++++++++++++++++++++++++++++------------------- 1 files changed, 46 insertions(+), 25 deletions(-) diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 880cb22..3a08848 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -350,9 +350,9 @@ static void scsi_dma_restart_cb(void *opaque, int running, RunState state) { SCSIDiskState *s = opaque; - if (!running) + if (!running) { return; - + } if (!s->bh) { s->bh = qemu_bh_new(scsi_dma_restart_bh, s); qemu_bh_schedule(s->bh); @@ -403,8 +403,9 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf) "buffer size %zd\n", req->cmd.xfer); pages = buflen++; outbuf[buflen++] = 0x00; // list of supported pages (this page) - if (s->serial) + if (s->serial) { outbuf[buflen++] = 0x80; // unit serial number + } outbuf[buflen++] = 0x83; // device identification if (s->qdev.type == TYPE_DISK) { outbuf[buflen++] = 0xb0; // block limits @@ -423,10 +424,12 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf) } l = strlen(s->serial); - if (l > req->cmd.xfer) + if (l > req->cmd.xfer) { l = req->cmd.xfer; - if (l > 20) + } + if (l > 20) { l = 20; + } DPRINTF("Inquiry EVPD[Serial number] " "buffer size %zd\n", req->cmd.xfer); @@ -441,8 +444,9 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf) int max_len = 255 - 8; int id_len = strlen(bdrv_get_device_name(s->bs)); - if (id_len > max_len) + if (id_len > max_len) { id_len = max_len; + } DPRINTF("Inquiry EVPD[Device identification] " "buffer size %zd\n", req->cmd.xfer); @@ -525,9 +529,9 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf) } buflen = req->cmd.xfer; - if (buflen > SCSI_MAX_INQUIRY_LEN) + if (buflen > SCSI_MAX_INQUIRY_LEN) { buflen = SCSI_MAX_INQUIRY_LEN; - + } memset(outbuf, 0, buflen); outbuf[0] = s->qdev.type & 0x1f; @@ -749,8 +753,9 @@ static int scsi_disk_emulate_mode_sense(SCSIDiskReq *r, uint8_t *outbuf) outbuf[7] = 8; /* Block descriptor length */ } nb_sectors /= s->cluster_size; - if (nb_sectors > 0xffffff) + if (nb_sectors > 0xffffff) { nb_sectors = 0; + } p[0] = 0; /* media density code */ p[1] = (nb_sectors >> 16) & 0xff; p[2] = (nb_sectors >> 8) & 0xff; @@ -791,8 +796,9 @@ static int scsi_disk_emulate_mode_sense(SCSIDiskReq *r, uint8_t *outbuf) outbuf[0] = ((buflen - 2) >> 8) & 0xff; outbuf[1] = (buflen - 2) & 0xff; } - if (buflen > r->req.cmd.xfer) + if (buflen > r->req.cmd.xfer) { buflen = r->req.cmd.xfer; + } return buflen; } @@ -826,8 +832,9 @@ static int scsi_disk_emulate_read_toc(SCSIRequest *req, uint8_t *outbuf) default: return -1; } - if (toclen > req->cmd.xfer) + if (toclen > req->cmd.xfer) { toclen = req->cmd.xfer; + } return toclen; } @@ -879,40 +886,48 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r) outbuf = r->iov.iov_base; switch (req->cmd.buf[0]) { case TEST_UNIT_READY: - if (s->tray_open || !bdrv_is_inserted(s->bs)) + if (s->tray_open || !bdrv_is_inserted(s->bs)) { goto not_ready; + } break; case INQUIRY: buflen = scsi_disk_emulate_inquiry(req, outbuf); - if (buflen < 0) + if (buflen < 0) { goto illegal_request; + } break; case MODE_SENSE: case MODE_SENSE_10: buflen = scsi_disk_emulate_mode_sense(r, outbuf); - if (buflen < 0) + if (buflen < 0) { goto illegal_request; + } break; case READ_TOC: buflen = scsi_disk_emulate_read_toc(req, outbuf); - if (buflen < 0) + if (buflen < 0) { goto illegal_request; + } break; case RESERVE: - if (req->cmd.buf[1] & 1) + if (req->cmd.buf[1] & 1) { goto illegal_request; + } break; case RESERVE_10: - if (req->cmd.buf[1] & 3) + if (req->cmd.buf[1] & 3) { goto illegal_request; + } break; case RELEASE: - if (req->cmd.buf[1] & 1) + if (req->cmd.buf[1] & 1) { goto illegal_request; + } break; case RELEASE_10: - if (req->cmd.buf[1] & 3) + if (req->cmd.buf[1] & 3) { goto illegal_request; + } break; case START_STOP: if (scsi_disk_emulate_start_stop(r) < 0) { @@ -927,16 +942,18 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r) /* The normal LEN field for this command is zero. */ memset(outbuf, 0, 8); bdrv_get_geometry(s->bs, &nb_sectors); - if (!nb_sectors) + if (!nb_sectors) { goto not_ready; + } nb_sectors /= s->cluster_size; /* Returned value is the address of the last sector. */ nb_sectors--; /* Remember the new size for read/write sanity checking. */ s->max_lba = nb_sectors; /* Clip to 2TB, instead of returning capacity modulo 2TB. */ - if (nb_sectors > UINT32_MAX) + if (nb_sectors > UINT32_MAX) { nb_sectors = UINT32_MAX; + } outbuf[0] = (nb_sectors >> 24) & 0xff; outbuf[1] = (nb_sectors >> 16) & 0xff; outbuf[2] = (nb_sectors >> 8) & 0xff; @@ -960,8 +977,9 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r) DPRINTF("SAI READ CAPACITY(16)\n"); memset(outbuf, 0, req->cmd.xfer); bdrv_get_geometry(s->bs, &nb_sectors); - if (!nb_sectors) + if (!nb_sectors) { goto not_ready; + } nb_sectors /= s->cluster_size; /* Returned value is the address of the last sector. */ nb_sectors--; @@ -1078,8 +1096,9 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *buf) case READ_16: len = r->req.cmd.xfer / s->qdev.blocksize; DPRINTF("Read (sector %" PRId64 ", count %d)\n", r->req.cmd.lba, len); - if (r->req.cmd.lba > s->max_lba) + if (r->req.cmd.lba > s->max_lba) { goto illegal_lba; + } r->sector = r->req.cmd.lba * s->cluster_size; r->sector_count = len * s->cluster_size; break; @@ -1094,8 +1113,9 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *buf) DPRINTF("Write %s(sector %" PRId64 ", count %d)\n", (command & 0xe) == 0xe ? "And Verify " : "", r->req.cmd.lba, len); - if (r->req.cmd.lba > s->max_lba) + if (r->req.cmd.lba > s->max_lba) { goto illegal_lba; + } r->sector = r->req.cmd.lba * s->cluster_size; r->sector_count = len * s->cluster_size; break; @@ -1168,8 +1188,9 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *buf) if (r->req.cmd.mode == SCSI_XFER_TO_DEV) { return -len; } else { - if (!r->sector_count) + if (!r->sector_count) { r->sector_count = -1; + } return len; } } -- 1.7.6