Received: from eggs.gnu.org ([2001:4830:134:3::10]:36499) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMZOJ-0006Jp-12 for qemu-devel@nongnu.org; Fri, 22 Jan 2016 05:56:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aMZOF-0005hE-Px for qemu-devel@nongnu.org; Fri, 22 Jan 2016 05:56:30 -0500 Received: from e06smtp07.uk.ibm.com ([195.75.94.103]:36709) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMZOF-0005gF-HS for qemu-devel@nongnu.org; Fri, 22 Jan 2016 05:56:27 -0500 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 22 Jan 2016 10:56:26 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id AC34017D8059 for ; Fri, 22 Jan 2016 10:56:30 +0000 (GMT) Received: from d06av07.portsmouth.uk.ibm.com (d06av07.portsmouth.uk.ibm.com [9.149.37.248]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u0MAuOxV917980 for ; Fri, 22 Jan 2016 10:56:24 GMT Received: from d06av07.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av07.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u0MAuN1e020706 for ; Fri, 22 Jan 2016 05:56:24 -0500 Date: Fri, 22 Jan 2016 11:56:20 +0100 From: Greg Kurz Message-ID: <20160122115620.5ff7f257@bahia.huguette.org> In-Reply-To: <1453396734-9363-6-git-send-email-clg@fr.ibm.com> References: <1453396734-9363-1-git-send-email-clg@fr.ibm.com> <1453396734-9363-6-git-send-email-clg@fr.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2 5/9] ipmi: fix SDR length value List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?B?Q8OpZHJpYw==?= Le Goater Cc: Corey Minyard , qemu-devel@nongnu.org, Marcel Apfelbaum , "Michael S. Tsirkin" On Thu, 21 Jan 2016 18:18:50 +0100 C=C3=A9dric Le Goater wrote: > 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. >=20 > Signed-off-by: C=C3=A9dric Le Goater The patch is good but IMHO it should come before patch 4 because this is bu= gfix that could be applied right away, while patch 4 is code cleanup that may ne= ed some more discussion. > --- > hw/ipmi/ipmi_bmc_sim.c | 18 +++++++++--------- > include/hw/ipmi/ipmi.h | 1 + > 2 files changed, 10 insertions(+), 9 deletions(-) >=20 > 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 uin= t8_t *entry, > struct ipmi_sdr_header *sdrh =3D > (struct ipmi_sdr_header *) &ibs->sdr.sdr[ibs->sdr.next_free]; >=20 > - if ((len < 5) || (len > 255)) { > + if ((len < IPMI_SDR_HEADER_SIZE) || (len > 255)) { > return 1; > } >=20 > - if (sdrh_entry->rec_length !=3D len - 5) { > + if (ipmi_sdr_length(sdrh_entry) !=3D len) { > return 1; > } >=20 > @@ -364,7 +364,7 @@ static int sdr_find_entry(IPMISdr *sdr, uint16_t reci= d, > struct ipmi_sdr_header *sdrh =3D > (struct ipmi_sdr_header *) &sdr->sdr[pos]; > uint16_t trec =3D ipmi_sdr_recid(sdrh); > - unsigned int nextpos =3D pos + sdrh->rec_length; > + unsigned int nextpos =3D pos + ipmi_sdr_length(sdrh); >=20 > if (trec =3D=3D recid) { > if (nextrec) { > @@ -1179,7 +1179,7 @@ static void get_sdr(IPMIBmcSim *ibs, >=20 > sdrh =3D (struct ipmi_sdr_header *) &ibs->sdr.sdr[pos]; >=20 > - if (cmd[6] > sdrh->rec_length) { > + if (cmd[6] > ipmi_sdr_length(sdrh)) { > rsp[2] =3D IPMI_CC_PARM_OUT_OF_RANGE; > return; > } > @@ -1188,7 +1188,7 @@ static void get_sdr(IPMIBmcSim *ibs, > IPMI_ADD_RSP_DATA((nextrec >> 8) & 0xff); >=20 > if (cmd[7] =3D=3D 0xff) { > - cmd[7] =3D sdrh->rec_length - cmd[6]; > + cmd[7] =3D ipmi_sdr_length(sdrh) - cmd[6]; > } >=20 > if ((cmd[7] + *rsp_len) > max_rsp_len) { > @@ -1659,22 +1659,22 @@ static void ipmi_sim_init(Object *obj) > for (i =3D 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 =3D (struct ipmi_sdr_header *) &init_sdrs[i]; > - len =3D sdrh->rec_length; > + len =3D ipmi_sdr_length(sdrh); > recid =3D ipmi_sdr_recid(sdrh); > if (recid =3D=3D 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 +=3D len + 5; > + i +=3D len; > } >=20 > 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) >=20 > #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) >=20 > /* > * 43.2 SDR Type 02h. Compact Sensor Record