From patchwork Mon Jan 21 14:08:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 14183 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 583B523E02 for ; Mon, 21 Jan 2013 14:08:44 +0000 (UTC) Received: from mail-vb0-f46.google.com (mail-vb0-f46.google.com [209.85.212.46]) by fiordland.canonical.com (Postfix) with ESMTP id 02586A18A35 for ; Mon, 21 Jan 2013 14:08:43 +0000 (UTC) Received: by mail-vb0-f46.google.com with SMTP id b13so5626041vby.19 for ; Mon, 21 Jan 2013 06:08:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=uHy3k9/3CYbWPiXCAEFqaziMMiGllLr02AewvxYz23c=; b=grWa0wITGVViy197L2fJIGmFSuvEQvOO3Tv/OPB0rVbGvE6mCxDkBDd/SVUNnU5Bg8 K0YTbAS/w/LfaoUnEsW46UkoQ3/kM5AkPBPYRaz6PpkKry6W/cZDvRVtL3uLSB9qVDNr a6dO5iE36waP/AzZ88PAubSM8fLHMluuYwwhkpqYqXjgE0ahzy8orOJkLZpw4AJmkc8n rzS6bxhNu10o/2PIEormHWVMrbF90jnMubTNhWvJg/CaMX8fpTqcXwNXp31CgqDXD86W bc3ehbVc/QAeJ1gX7JlY94FxyYK/PMa+21gnSUpPXEmP3LZf1+au3gu2usmdvAPBi5iO O3Mg== X-Received: by 10.52.176.6 with SMTP id ce6mr17109282vdc.57.1358777323505; Mon, 21 Jan 2013 06:08:43 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.145.101 with SMTP id st5csp202949veb; Mon, 21 Jan 2013 06:08:42 -0800 (PST) X-Received: by 10.194.90.116 with SMTP id bv20mr26529979wjb.33.1358777321925; Mon, 21 Jan 2013 06:08:41 -0800 (PST) Received: from mnementh.archaic.org.uk (1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id p6si3934066wic.28.2013.01.21.06.08.40 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 21 Jan 2013 06:08:41 -0800 (PST) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; Authentication-Results: mx.google.com; spf=neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1TxI3C-0001yk-Qn; Mon, 21 Jan 2013 14:08:38 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Anthony Liguori Subject: [PATCH 2/2] hw/pflash_cfi01: Treat read in unknown command state as read Date: Mon, 21 Jan 2013 14:08:38 +0000 Message-Id: <1358777318-7579-3-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1358777318-7579-1-git-send-email-peter.maydell@linaro.org> References: <1358777318-7579-1-git-send-email-peter.maydell@linaro.org> X-Gm-Message-State: ALoCoQn1iNft5MOTI4Zu8j6fv+f7ATBz8Ri+So0+TRaLZ2FOnCB4tPTyguwRFiw1kBtCHKN0jtLs The code for handling the default "unknown command state" case in pflash_read in pflash_cfi01.c comments "reset state & treat it as a read". However the code doesn't actually do this. Moving the default case to the top of the switch so it can fall through into the read case brings this file into line with pflash_cfi02 and makes the code behave as the comments suggest. The pflash_cfi01 code has always had this bug -- it was presumably introduced when the original author copied the cfi02 code and rearranged the order of the switch statement without noticing that the default case relied on the fall-through. Signed-off-by: Peter Maydell Reviewed-by: Peter Crosthwaite Tested-by: Peter Crosthwaite --- hw/pflash_cfi01.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/hw/pflash_cfi01.c b/hw/pflash_cfi01.c index 310c716..b30cac6 100644 --- a/hw/pflash_cfi01.c +++ b/hw/pflash_cfi01.c @@ -122,6 +122,12 @@ static uint32_t pflash_read (pflash_t *pfl, hwaddr offset, __func__, offset, pfl->cmd, width); #endif switch (pfl->cmd) { + default: + /* This should never happen : reset state & treat it as a read */ + DPRINTF("%s: unknown command state: %x\n", __func__, pfl->cmd); + pfl->wcycle = 0; + pfl->cmd = 0; + /* fall through to read code */ case 0x00: /* Flash area read */ p = pfl->storage; @@ -197,11 +203,6 @@ static uint32_t pflash_read (pflash_t *pfl, hwaddr offset, else ret = pfl->cfi_table[boff]; break; - default: - /* This should never happen : reset state & treat it as a read */ - DPRINTF("%s: unknown command state: %x\n", __func__, pfl->cmd); - pfl->wcycle = 0; - pfl->cmd = 0; } return ret; }