From patchwork Fri Aug 21 04:57:38 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vijay Kumar X-Patchwork-Id: 31801 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 bilbo.ozlabs.org (Postfix) with ESMTPS id A40EDB7B92 for ; Fri, 21 Aug 2009 15:00:50 +1000 (EST) Received: from localhost ([127.0.0.1]:58386 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MeMEr-0007vx-Pt for incoming@patchwork.ozlabs.org; Fri, 21 Aug 2009 01:00:33 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MeME3-0007vq-IQ for qemu-devel@nongnu.org; Fri, 21 Aug 2009 00:59:43 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MeMDx-0007vb-MP for qemu-devel@nongnu.org; Fri, 21 Aug 2009 00:59:42 -0400 Received: from [199.232.76.173] (port=44119 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MeMDx-0007vY-FZ for qemu-devel@nongnu.org; Fri, 21 Aug 2009 00:59:37 -0400 Received: from li2-213.members.linode.com ([69.56.173.213]:47832 helo=mail.zilogic.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MeMDw-0000SD-KT for qemu-devel@nongnu.org; Fri, 21 Aug 2009 00:59:36 -0400 Received: from [192.168.1.5] (unknown [59.92.18.158]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.zilogic.com (Postfix) with ESMTP id C9A421055F for ; Fri, 21 Aug 2009 00:59:30 -0400 (EDT) Message-ID: <4A8E2942.8020808@bravegnu.org> Date: Fri, 21 Aug 2009 10:27:38 +0530 From: Vijay Kumar User-Agent: Icedove 1.5.0.12 (X11/20070607) MIME-Version: 1.0 To: qemu-devel@nongnu.org X-Enigmail-Version: 0.94.2.0 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 1) Subject: [Qemu-devel] [PATCH] Check block driver read error in pflash_cfi0x 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 If a flash file of size smaller than the flash size is specified in the -pflash option, the block driver returns error. But the pflash_cfi0x ignores the error. This results in a flash content of all zeroes. And the simulation aborts while executing code. This patch adds the checks for errors from bdrv_read and escalates it to the calling code. Signed-off-by: Vijay Kumar B. Index: qemu/hw/pflash_cfi01.c =================================================================== --- qemu.orig/hw/pflash_cfi01.c 2009-08-21 09:12:59.000000000 +0530 +++ qemu/hw/pflash_cfi01.c 2009-08-21 10:19:34.000000000 +0530 @@ -507,6 +507,7 @@ { pflash_t *pfl; target_phys_addr_t total_len; + int ret; total_len = sector_len * nb_blocs; @@ -530,7 +531,12 @@ pfl->bs = bs; if (pfl->bs) { /* read the initial flash content */ - bdrv_read(pfl->bs, 0, pfl->storage, total_len >> 9); + ret = bdrv_read(pfl->bs, 0, pfl->storage, total_len >> 9); + if (ret < 0) { + cpu_unregister_io_memory(pfl->fl_mem); + qemu_free(pfl); + return NULL; + } } #if 0 /* XXX: there should be a bit to set up read-only, * the same way the hardware does (with WP pin). Index: qemu/hw/pflash_cfi02.c =================================================================== --- qemu.orig/hw/pflash_cfi02.c 2009-08-21 09:39:04.000000000 +0530 +++ qemu/hw/pflash_cfi02.c 2009-08-21 10:19:42.000000000 +0530 @@ -547,6 +547,7 @@ { pflash_t *pfl; int32_t chip_len; + int ret; chip_len = sector_len * nb_blocs; /* XXX: to be fixed */ @@ -568,7 +569,12 @@ pfl->bs = bs; if (pfl->bs) { /* read the initial flash content */ - bdrv_read(pfl->bs, 0, pfl->storage, chip_len >> 9); + ret = bdrv_read(pfl->bs, 0, pfl->storage, chip_len >> 9); + if (ret < 0) { + cpu_unregister_io_memory(pfl->fl_mem); + qemu_free(pfl); + return NULL; + } } #if 0 /* XXX: there should be a bit to set up read-only, * the same way the hardware does (with WP pin).