From: hare@suse.de (Hannes Reinecke)
To: "Nicholas A.Bellinger" <nab@linux-iscsi.org>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 2/2] megasas: Error checking for cpu_physical_memory_map()
Date: Fri, 14 May 2010 09:24:30 +0200 [thread overview]
Message-ID: <20100514072430.C80932A37B@ochil.suse.de> (raw)
cpu_physical_memory_map() can fail, so we really should
check for errors here.
Plus a fix for a small casting error.
Signed-off-by: Hannes Reinecke <hare@suse.de>
---
hw/megasas.c | 23 +++++++++++++++++++----
1 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/hw/megasas.c b/hw/megasas.c
index 69c5037..e0725de 100644
--- a/hw/megasas.c
+++ b/hw/megasas.c
@@ -264,6 +264,7 @@ megasas_enqueue_frame(MPTState *s, target_phys_addr_t frame)
{
struct megasas_cmd_t *cmd = NULL;
uint8_t frame_size = sizeof(cmd->frame);
+ target_phys_addr_t frame_size_p = frame_size;
cmd = megasas_next_frame(s, frame);
/* All frames busy */
@@ -271,8 +272,16 @@ megasas_enqueue_frame(MPTState *s, target_phys_addr_t frame)
return NULL;
if (!cmd->pa) {
cmd->pa = frame;
- cmd->frame = cpu_physical_memory_map(frame,
- (target_phys_addr_t *)&frame_size, 0);
+ cmd->frame = cpu_physical_memory_map(frame, &frame_size_p, 0);
+ if (frame_size_p != frame_size) {
+ DPRINTF("failed to map frame %lu\n", (unsigned long)frame);
+ if (cmd->frame) {
+ cpu_physical_memory_unmap(cmd->frame, frame_size_p, 0, 0);
+ cmd->frame = NULL;
+ cmd->pa = 0;
+ }
+ return NULL;
+ }
}
cmd->frame->header.context = le32_to_cpu(cmd->frame->header.context);
@@ -357,8 +366,13 @@ static int megasas_init_firmware(MPTState *s, struct megasas_cmd_t *cmd)
DPRINTF("MFI init firmware: xfer len %d pa %lx\n", (int)iq_pl,
(unsigned long)iq_pa);
#endif
- initq_size = sizeof(initq);
- initq = cpu_physical_memory_map(iq_pa, &initq_size, 0);
+ initq_size = sizeof(*initq);
+ initq = cpu_physical_memory_map(iq_pa, &initq_size, 0);
+ if (initq_size != sizeof(*initq)) {
+ DPRINTF("MFI init firmware: failed to map queue mem\n");
+ s->fw_state = MFI_FWSTATE_FAULT;
+ goto out;
+ }
s->reply_queue_len = le32_to_cpu(initq->rq_entries);
pa_lo = le32_to_cpu(initq->rq_addr_lo);
pa_hi = le32_to_cpu(initq->rq_addr_hi);
@@ -376,6 +390,7 @@ static int megasas_init_firmware(MPTState *s, struct megasas_cmd_t *cmd)
#endif
s->reply_queue_index = ldl_phys(s->producer_pa);
s->fw_state = MFI_FWSTATE_OPERATIONAL;
+out:
cpu_physical_memory_unmap(initq, initq_size, 0, 0);
return 0;
}
--
1.6.0.2
reply other threads:[~2010-05-14 7:24 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100514072430.C80932A37B@ochil.suse.de \
--to=hare@suse.de \
--cc=nab@linux-iscsi.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).