1 From 3bf1e29359a1e22a2ecdffb50f124db275abf5bd Mon Sep 17 00:00:00 2001
2 From: Prasad J Pandit <pjp@fedoraproject.org>
3 Date: Mon, 24 Apr 2017 17:36:34 +0530
4 Subject: [PATCH 14/15] scsi: avoid an off-by-one error in megasas_mmio_write
6 While reading magic sequence(MFI_SEQ) in megasas_mmio_write,
7 an off-by-one error could occur as 's->adp_reset' index is not
8 reset after reading the last sequence.
10 Reported-by: YY Z <bigbird475958471@gmail.com>
11 Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
12 Message-Id: <20170424120634.12268-1-ppandit@redhat.com>
13 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
15 hw/scsi/megasas.c | 10 +++++-----
16 1 file changed, 5 insertions(+), 5 deletions(-)
18 diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c
19 index 84b8caf901..804122ab05 100644
20 --- a/hw/scsi/megasas.c
21 +++ b/hw/scsi/megasas.c
22 @@ -2138,15 +2138,15 @@ static void megasas_mmio_write(void *opaque, hwaddr addr,
24 trace_megasas_mmio_writel("MFI_SEQ", val);
25 /* Magic sequence to start ADP reset */
26 - if (adp_reset_seq[s->adp_reset] == val) {
28 + if (adp_reset_seq[s->adp_reset++] == val) {
29 + if (s->adp_reset == 6) {
31 + s->diag = MFI_DIAG_WRITE_ENABLE;
37 - if (s->adp_reset == 6) {
38 - s->diag = MFI_DIAG_WRITE_ENABLE;
42 trace_megasas_mmio_writel("MFI_DIAG", val);