Skip to contentSkip to conversation

ipmi: fix SDR length value

PATCH Superseded Cédric Le Goater 3 participants 5 messages Jan 5, 2016 – Jan 12, 2016

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/8 ipmi: fix SDR length value

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.

---

Maybe we could use a sdr struct/typedef to clarify the code. See patch 7: "ipmi: introduce an ipmi_bmc_init_sensor() API"

 hw/ipmi/ipmi_bmc_sim.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
hw/ipmi/ipmi_bmc_sim.c +7 -7
index 0a59e539f549..559e1398d669 100644
@@ -362,7 +362,7 @@ static int sdr_find_entry(IPMISdr *sdr, uint16_t recid,
 
     while (pos < sdr->next_free) {
         uint16_t trec = sdr->sdr[pos] | (sdr->sdr[pos + 1] << 8);
-        unsigned int nextpos = pos + sdr->sdr[pos + 4];
+        unsigned int nextpos = pos + sdr->sdr[pos + 4] + 5;
 
         if (trec == recid) {
             if (nextrec) {
@@ -1198,7 +1198,7 @@ static void get_sdr(IPMIBmcSim *ibs,
         rsp[2] = IPMI_CC_REQ_ENTRY_NOT_PRESENT;
         goto out;
     }
-    if (cmd[6] > (ibs->sdr.sdr[pos + 4])) {
+    if (cmd[6] > (ibs->sdr.sdr[pos + 4] + 5)) {
         rsp[2] = IPMI_CC_PARM_OUT_OF_RANGE;
         goto out;
     }
@@ -1207,7 +1207,7 @@ static void get_sdr(IPMIBmcSim *ibs,
     IPMI_ADD_RSP_DATA((nextrec >> 8) & 0xff);
 
     if (cmd[7] == 0xff) {
-        cmd[7] = ibs->sdr.sdr[pos + 4] - cmd[6];
+        cmd[7] = ibs->sdr.sdr[pos + 4] + 5 - cmd[6];
     }
 
     if ((cmd[7] + *rsp_len) > max_rsp_len) {
@@ -1709,20 +1709,20 @@ static void ipmi_sim_init(Object *obj)
     for (i = 0;;) {
         int len;
         if ((i + 5) > sizeof(init_sdrs)) {
-            error_report("Problem with recid 0x%4.4x: \n", i);
+            error_report("Problem with recid 0x%4.4x\n", i);
             return;
         }
-        len = init_sdrs[i + 4];
+        len = init_sdrs[i + 4] + 5;
         recid = init_sdrs[i] | (init_sdrs[i + 1] << 8);
         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\n", i);
             return;
         }
         sdr_add_entry(ibs, init_sdrs + i, len, NULL);
-        i += len + 5;
+        i += len;
     }
 
     ipmi_init_sensors_from_sdrs(ibs);
Signature · 1 line
2.1.4
#1 lore raw

On 01/05/2016 10:29 AM, Cédric Le Goater wrote:

[meta-comment] Your messages were not marked in-reply-to: the 0/8 cover letter, but came through as separate threads. This makes it harder to follow, especially in mail clients that sort top-level threads by most recent activity on the thread.

Quoted 19 lines

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.

---

Maybe we could use a sdr struct/typedef to clarify the code. See patch 7: "ipmi: introduce an ipmi_bmc_init_sensor() API"

 hw/ipmi/ipmi_bmc_sim.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
hw/ipmi/ipmi_bmc_sim.c +0 -0
index 0a59e539f549..559e1398d669 100644

hw/ipmi/ipmi_bmc_sim.c static int sdr_find_entry(IPMISdr *sdr, uint16_t recid, · line 365

Quoted 5 lines
hw/ipmi/ipmi_bmc_sim.c +1 -1
@@ -362,7 +362,7 @@ static int sdr_find_entry(IPMISdr *sdr, uint16_t recid,
 
     while (pos < sdr->next_free) {
         uint16_t trec = sdr->sdr[pos] | (sdr->sdr[pos + 1] << 8);
-        unsigned int nextpos = pos + sdr->sdr[pos + 4];
+        unsigned int nextpos = pos + sdr->sdr[pos + 4] + 5;

5 feels like a magic number; should you use a #define and name it?

hw/ipmi/ipmi_bmc_sim.c static void ipmi_sim_init(Object *obj) · line 1712

Quoted 6 lines
hw/ipmi/ipmi_bmc_sim.c +1 -1
@@ -1709,20 +1709,20 @@ static void ipmi_sim_init(Object *obj)
     for (i = 0;;) {
         int len;
         if ((i + 5) > sizeof(init_sdrs)) {
-            error_report("Problem with recid 0x%4.4x: \n", i);
+            error_report("Problem with recid 0x%4.4x\n", i);

Please drop the trailing \n as long as you are touching this.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
Quoted 6 lines · Eric Blake

On 01/05/2016 10:29 AM, Cédric Le Goater wrote:

[meta-comment] Your messages were not marked in-reply-to: the 0/8 cover letter, but came through as separate threads. This makes it harder to follow, especially in mail clients that sort top-level threads by most recent activity on the thread.

Yes. My bad. I put 'thread = false' in my .gitconfig for some reason and didn't check before sending. This is fixed.

Quoted 20 lines
Quoted 20 lines

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.

---

Maybe we could use a sdr struct/typedef to clarify the code. See patch 7: "ipmi: introduce an ipmi_bmc_init_sensor() API"

 hw/ipmi/ipmi_bmc_sim.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
hw/ipmi/ipmi_bmc_sim.c +0 -0
index 0a59e539f549..559e1398d669 100644
@@ -362,7 +362,7 @@ static int sdr_find_entry(IPMISdr *sdr, uint16_t recid,
 
Quoted 6 lines

hw/ipmi/ipmi_bmc_sim.c static int sdr_find_entry(IPMISdr *sdr, uint16_t recid, · line 365

Quoted 4 lines
hw/ipmi/ipmi_bmc_sim.c +1 -1
     while (pos < sdr->next_free) {
         uint16_t trec = sdr->sdr[pos] | (sdr->sdr[pos + 1] << 8);
-        unsigned int nextpos = pos + sdr->sdr[pos + 4];
+        unsigned int nextpos = pos + sdr->sdr[pos + 4] + 5;

5 feels like a magic number; should you use a #define and name it?

Yes. 5 being the sdr header length.

The simulator uses a lot of these byte offsets and I think the code would gain to use a struct as proposed in patch 7:

"ipmi: introduce an ipmi_bmc_init_sensor() API".

Corey, is there a reason for not doing so ?

Quoted 8 lines

hw/ipmi/ipmi_bmc_sim.c static void ipmi_sim_init(Object *obj) · line 1712

Quoted 6 lines
hw/ipmi/ipmi_bmc_sim.c +1 -1
@@ -1709,20 +1709,20 @@ static void ipmi_sim_init(Object *obj)
     for (i = 0;;) {
         int len;
         if ((i + 5) > sizeof(init_sdrs)) {
-            error_report("Problem with recid 0x%4.4x: \n", i);
+            error_report("Problem with recid 0x%4.4x\n", i);

Please drop the trailing \n as long as you are touching this.

Sure.

Thanks,

C.

#3 lore raw
Quoted 35 lines · Cédric Le Goater
Quoted 6 lines · Eric Blake

On 01/05/2016 10:29 AM, Cédric Le Goater wrote:

[meta-comment] Your messages were not marked in-reply-to: the 0/8 cover letter, but came through as separate threads. This makes it harder to follow, especially in mail clients that sort top-level threads by most recent activity on the thread.

Yes. My bad. I put 'thread = false' in my .gitconfig for some reason and didn't check before sending. This is fixed.

Quoted 20 lines
Quoted 20 lines

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.

---

Maybe we could use a sdr struct/typedef to clarify the code. See patch 7: "ipmi: introduce an ipmi_bmc_init_sensor() API"

  hw/ipmi/ipmi_bmc_sim.c | 14 +++++++-------
  1 file changed, 7 insertions(+), 7 deletions(-)
hw/ipmi/ipmi_bmc_sim.c +0 -0
index 0a59e539f549..559e1398d669 100644
@@ -362,7 +362,7 @@ static int sdr_find_entry(IPMISdr *sdr, uint16_t recid,
 
Quoted 5 lines

hw/ipmi/ipmi_bmc_sim.c static int sdr_find_entry(IPMISdr *sdr, uint16_t recid, · line 365

Quoted 4 lines
hw/ipmi/ipmi_bmc_sim.c +1 -1
      while (pos < sdr->next_free) {
          uint16_t trec = sdr->sdr[pos] | (sdr->sdr[pos + 1] << 8);
-        unsigned int nextpos = pos + sdr->sdr[pos + 4];
+        unsigned int nextpos = pos + sdr->sdr[pos + 4] + 5;

5 feels like a magic number; should you use a #define and name it?

Quoted 8 lines

Yes. 5 being the sdr header length.

The simulator uses a lot of these byte offsets and I think the code would gain to use a struct as proposed in patch 7:

"ipmi: introduce an ipmi_bmc_init_sensor() API".

Corey, is there a reason for not doing so ?

I was just adding one and it didn't matter much at that point? Or I was lazy?

I've commented a little earlier on patch 7, the struct is a better way to go.

-corey

Quoted 15 lines
Quoted 8 lines

hw/ipmi/ipmi_bmc_sim.c static void ipmi_sim_init(Object *obj) · line 1712

Quoted 7 lines
hw/ipmi/ipmi_bmc_sim.c +1 -1
@@ -1709,20 +1709,20 @@ static void ipmi_sim_init(Object *obj)
      for (i = 0;;) {
          int len;
          if ((i + 5) > sizeof(init_sdrs)) {
-            error_report("Problem with recid 0x%4.4x: \n", i);
+            error_report("Problem with recid 0x%4.4x\n", i);

Please drop the trailing \n as long as you are touching this.

Sure.

Thanks,

C.

#4 lore raw
Quoted 41 lines · Corey Minyard
Quoted 40 lines · Cédric Le Goater
Quoted 6 lines · Eric Blake

On 01/05/2016 10:29 AM, Cédric Le Goater wrote:

[meta-comment] Your messages were not marked in-reply-to: the 0/8 cover letter, but came through as separate threads. This makes it harder to follow, especially in mail clients that sort top-level threads by most recent activity on the thread.

Yes. My bad. I put 'thread = false' in my .gitconfig for some reason and didn't check before sending. This is fixed.

Quoted 14 lines
Quoted 14 lines

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.

---

Maybe we could use a sdr struct/typedef to clarify the code. See patch 7: "ipmi: introduce an ipmi_bmc_init_sensor() API"

  hw/ipmi/ipmi_bmc_sim.c | 14 +++++++-------
  1 file changed, 7 insertions(+), 7 deletions(-)
Quoted 10 lines

hw/ipmi/ipmi_bmc_sim.c static int sdr_find_entry(IPMISdr *sdr, uint16_t recid, · line 364

Quoted 9 lines
hw/ipmi/ipmi_bmc_sim.c +1 -1
index 0a59e539f549..559e1398d669 100644
@@ -362,7 +362,7 @@ static int sdr_find_entry(IPMISdr *sdr, uint16_t recid,
        while (pos < sdr->next_free) {
          uint16_t trec = sdr->sdr[pos] | (sdr->sdr[pos + 1] << 8);
-        unsigned int nextpos = pos + sdr->sdr[pos + 4];
+        unsigned int nextpos = pos + sdr->sdr[pos + 4] + 5;

5 feels like a magic number; should you use a #define and name it?

Yes. 5 being the sdr header length.

The simulator uses a lot of these byte offsets and I think the code would gain to use a struct as proposed in patch 7:
"ipmi: introduce an ipmi_bmc_init_sensor() API".

Quoted 5 lines
Quoted 1 line

Corey, is there a reason for not doing so ?

I was just adding one and it didn't matter much at that point? Or I was lazy?

I've commented a little earlier on patch 7, the struct is a better way to go.

next version will start with this change and the commands you acked. And probably also the FRU commands. I want to take sometime to look at a SDR loader, a simple one, that would use the existing code and a file backend.

Thanks for the review.

C.

Quoted 17 lines

-corey

Quoted 14 lines
Quoted 8 lines

hw/ipmi/ipmi_bmc_sim.c static void ipmi_sim_init(Object *obj) · line 1712

Quoted 7 lines
hw/ipmi/ipmi_bmc_sim.c +1 -1
@@ -1709,20 +1709,20 @@ static void ipmi_sim_init(Object *obj)
      for (i = 0;;) {
          int len;
          if ((i + 5) > sizeof(init_sdrs)) {
-            error_report("Problem with recid 0x%4.4x: \n", i);
+            error_report("Problem with recid 0x%4.4x\n", i);

Please drop the trailing \n as long as you are touching this.

Sure.

Thanks,

C.