The fact that this malloc(1) has survived the latest purges just
goes to show how obtuse the jtag_add_xxx() code is.

Also, this patch is interesting because it shows how switching
to a 32 bit word size rather than 8 bit, would make the code
a lot less obtuse.

In this case 8 bit happens to be sufficiently wide and therefore
all those "helper" buf_set_u32() just evaporate...

With a 32 bit word size, that callback would disappear too...

Comments?

-- 
Øyvind Harboe
http://www.zylin.com/zy1000.html
ARM7 ARM9 ARM11 XScale Cortex
JTAG debugger and flash programmer
diff --git a/src/target/etb.c b/src/target/etb.c
index 925a021..b477818 100644
--- a/src/target/etb.c
+++ b/src/target/etb.c
@@ -187,14 +187,14 @@ static int etb_read_ram(etb_t *etb, uint32_t *data, int 
num_frames)
 
        fields[1].tap = etb->tap;
        fields[1].num_bits = 7;
-       fields[1].out_value = malloc(1);
-       buf_set_u32(fields[1].out_value, 0, 7, 4);
+       u8_t t = 4;
+       fields[1].out_value = &t;
        fields[1].in_value = NULL;
 
        fields[2].tap = etb->tap;
        fields[2].num_bits = 1;
-       fields[2].out_value = malloc(1);
-       buf_set_u32(fields[2].out_value, 0, 1, 0);
+       u8_t t2 = 0;
+       fields[2].out_value = &t2;
        fields[2].in_value = NULL;
 
        jtag_add_dr_scan(3, fields, jtag_get_end_state());
@@ -202,13 +202,13 @@ static int etb_read_ram(etb_t *etb, uint32_t *data, int 
num_frames)
        for (i = 0; i < num_frames; i++)
        {
                /* ensure nR/W reamins set to read */
-               buf_set_u32(fields[2].out_value, 0, 1, 0);
+               fields[2].out_value = 0;
 
                /* address remains set to 0x4 (RAM data) until we read the last 
frame */
                if (i < num_frames - 1)
-                       buf_set_u32(fields[1].out_value, 0, 7, 4);
+                       fields[1].out_value[0] = 4;
                else
-                       buf_set_u32(fields[1].out_value, 0, 7, 0);
+                       fields[1].out_value[0] = 0;
 
                fields[0].in_value = (uint8_t *)(data + i);
                jtag_add_dr_scan(3, fields, jtag_get_end_state());
@@ -216,12 +216,7 @@ static int etb_read_ram(etb_t *etb, uint32_t *data, int 
num_frames)
                jtag_add_callback(etb_getbuf, (jtag_callback_data_t)(data + i));
        }
 
-       jtag_execute_queue();
-
-       free(fields[1].out_value);
-       free(fields[2].out_value);
-
-       return ERROR_OK;
+       return jtag_execute_queue();
 }
 
 static int etb_read_reg_w_check(reg_t *reg,
_______________________________________________
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to