From patchwork Thu Jan 21 17:18:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 8083541 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A02A49F1CC for ; Thu, 21 Jan 2016 17:21:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F389D2025A for ; Thu, 21 Jan 2016 17:21:29 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3BDA320251 for ; Thu, 21 Jan 2016 17:21:29 +0000 (UTC) Received: from localhost ([::1]:49044 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMIvI-0000VN-IP for patchwork-qemu-devel@patchwork.kernel.org; Thu, 21 Jan 2016 12:21:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51730) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMItB-0005PW-S1 for qemu-devel@nongnu.org; Thu, 21 Jan 2016 12:19:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aMIt8-0005r5-9Z for qemu-devel@nongnu.org; Thu, 21 Jan 2016 12:19:17 -0500 Received: from e06smtp11.uk.ibm.com ([195.75.94.107]:32773) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMIt8-0005q3-09 for qemu-devel@nongnu.org; Thu, 21 Jan 2016 12:19:14 -0500 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 21 Jan 2016 17:19:11 -0000 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 21 Jan 2016 17:19:10 -0000 X-IBM-Helo: d06dlp01.portsmouth.uk.ibm.com X-IBM-MailFrom: clg@fr.ibm.com X-IBM-RcptTo: qemu-devel@nongnu.org Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 1CFD317D8063 for ; Thu, 21 Jan 2016 17:19:16 +0000 (GMT) Received: from d06av05.portsmouth.uk.ibm.com (d06av05.portsmouth.uk.ibm.com [9.149.37.229]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u0LHJAiC5636444 for ; Thu, 21 Jan 2016 17:19:10 GMT Received: from d06av05.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u0LHJ9wi001085 for ; Thu, 21 Jan 2016 10:19:09 -0700 Received: from hermes.lab.toulouse-stg.fr.ibm.com (hermes.lab.toulouse-stg.fr.ibm.com [9.101.4.42]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u0LHJ714000958; Thu, 21 Jan 2016 10:19:09 -0700 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: Corey Minyard Date: Thu, 21 Jan 2016 18:18:50 +0100 Message-Id: <1453396734-9363-6-git-send-email-clg@fr.ibm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1453396734-9363-1-git-send-email-clg@fr.ibm.com> References: <1453396734-9363-1-git-send-email-clg@fr.ibm.com> MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16012117-0041-0000-0000-0000073F17BD X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.75.94.107 Cc: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Greg Kurz , qemu-devel@nongnu.org, Marcel Apfelbaum , "Michael S. Tsirkin" Subject: [Qemu-devel] [PATCH v2 5/9] ipmi: fix SDR length value 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The IPMI BMC simulator populates the SDR table with a set of initial SDRs. The length of each SDR is taken from the record itself (byte 4) which does not include the size of the header. But, the full length (header + data) is required by the sdr_add_entry() routine. Signed-off-by: Cédric Le Goater --- hw/ipmi/ipmi_bmc_sim.c | 18 +++++++++--------- include/hw/ipmi/ipmi.h | 1 + 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/hw/ipmi/ipmi_bmc_sim.c b/hw/ipmi/ipmi_bmc_sim.c index 31f990199154..803c7e5130c0 100644 --- a/hw/ipmi/ipmi_bmc_sim.c +++ b/hw/ipmi/ipmi_bmc_sim.c @@ -327,11 +327,11 @@ static int sdr_add_entry(IPMIBmcSim *ibs, const uint8_t *entry, struct ipmi_sdr_header *sdrh = (struct ipmi_sdr_header *) &ibs->sdr.sdr[ibs->sdr.next_free]; - if ((len < 5) || (len > 255)) { + if ((len < IPMI_SDR_HEADER_SIZE) || (len > 255)) { return 1; } - if (sdrh_entry->rec_length != len - 5) { + if (ipmi_sdr_length(sdrh_entry) != len) { return 1; } @@ -364,7 +364,7 @@ static int sdr_find_entry(IPMISdr *sdr, uint16_t recid, struct ipmi_sdr_header *sdrh = (struct ipmi_sdr_header *) &sdr->sdr[pos]; uint16_t trec = ipmi_sdr_recid(sdrh); - unsigned int nextpos = pos + sdrh->rec_length; + unsigned int nextpos = pos + ipmi_sdr_length(sdrh); if (trec == recid) { if (nextrec) { @@ -1179,7 +1179,7 @@ static void get_sdr(IPMIBmcSim *ibs, sdrh = (struct ipmi_sdr_header *) &ibs->sdr.sdr[pos]; - if (cmd[6] > sdrh->rec_length) { + if (cmd[6] > ipmi_sdr_length(sdrh)) { rsp[2] = IPMI_CC_PARM_OUT_OF_RANGE; return; } @@ -1188,7 +1188,7 @@ static void get_sdr(IPMIBmcSim *ibs, IPMI_ADD_RSP_DATA((nextrec >> 8) & 0xff); if (cmd[7] == 0xff) { - cmd[7] = sdrh->rec_length - cmd[6]; + cmd[7] = ipmi_sdr_length(sdrh) - cmd[6]; } if ((cmd[7] + *rsp_len) > max_rsp_len) { @@ -1659,22 +1659,22 @@ static void ipmi_sim_init(Object *obj) for (i = 0;;) { struct ipmi_sdr_header *sdrh; int len; - if ((i + 5) > sizeof(init_sdrs)) { + if ((i + IPMI_SDR_HEADER_SIZE) > sizeof(init_sdrs)) { error_report("Problem with recid 0x%4.4x", i); return; } sdrh = (struct ipmi_sdr_header *) &init_sdrs[i]; - len = sdrh->rec_length; + len = ipmi_sdr_length(sdrh); recid = ipmi_sdr_recid(sdrh); if (recid == 0xffff) { break; } - if ((i + len + 5) > sizeof(init_sdrs)) { + if ((i + len) > sizeof(init_sdrs)) { error_report("Problem with recid 0x%4.4x", i); return; } sdr_add_entry(ibs, init_sdrs + i, len, NULL); - i += len + 5; + i += len; } ipmi_init_sensors_from_sdrs(ibs); diff --git a/include/hw/ipmi/ipmi.h b/include/hw/ipmi/ipmi.h index 7e142e241dcb..74a2b5af9613 100644 --- a/include/hw/ipmi/ipmi.h +++ b/include/hw/ipmi/ipmi.h @@ -219,6 +219,7 @@ struct ipmi_sdr_header { #define IPMI_SDR_HEADER_SIZE sizeof(struct ipmi_sdr_header) #define ipmi_sdr_recid(sdr) ((sdr)->rec_id[0] | ((sdr)->rec_id[1] << 8)) +#define ipmi_sdr_length(sdr) ((sdr)->rec_length + IPMI_SDR_HEADER_SIZE) /* * 43.2 SDR Type 02h. Compact Sensor Record