This is an automated email from Gerrit.

Marc Schink ([email protected]) just uploaded a new patch set to Gerrit, which you 
can find at http://openocd.zylin.com/5919

-- gerrit

commit 64f268f2e1baaea989f1a4d4061cb86ee0b00a6d
Author: Marc Schink <[email protected]>
Date:   Tue Nov 3 16:11:48 2020 +0100

    target/image: Use proper data type for 'num_sections'
    
    While at it, fix some coding style issues.
    
    Change-Id: Id521394d89e0bf787a6f812701c2cc0fe7e4e63f
    Signed-off-by: Marc Schink <[email protected]>

diff --git a/src/flash/nor/core.c b/src/flash/nor/core.c
index d563013..6182a5f 100644
--- a/src/flash/nor/core.c
+++ b/src/flash/nor/core.c
@@ -702,7 +702,7 @@ int flash_write_unlock(struct target *target, struct image 
*image,
 {
        int retval = ERROR_OK;
 
-       int section;
+       unsigned int section;
        uint32_t section_offset;
        struct flash_bank *c;
        int *padding;
@@ -727,8 +727,8 @@ int flash_write_unlock(struct target *target, struct image 
*image,
         * whereas an image can have sections out of order. */
        struct imagesection **sections = malloc(sizeof(struct imagesection *) *
                        image->num_sections);
-       int i;
-       for (i = 0; i < image->num_sections; i++)
+
+       for (unsigned int i = 0; i < image->num_sections; i++)
                sections[i] = &image->sections[i];
 
        qsort(sections, image->num_sections, sizeof(struct imagesection *),
@@ -738,7 +738,7 @@ int flash_write_unlock(struct target *target, struct image 
*image,
        while (section < image->num_sections) {
                uint32_t buffer_idx;
                uint8_t *buffer;
-               int section_last;
+               unsigned int section_last;
                target_addr_t run_address = sections[section]->base_address + 
section_offset;
                uint32_t run_size = sections[section]->size - section_offset;
                int pad_bytes = 0;
diff --git a/src/jtag/drivers/ulink.c b/src/jtag/drivers/ulink.c
index 68249dc..0ff25bb 100644
--- a/src/jtag/drivers/ulink.c
+++ b/src/jtag/drivers/ulink.c
@@ -393,7 +393,7 @@ int ulink_load_firmware_and_renumerate(struct ulink 
**device,
 int ulink_load_firmware(struct ulink *device, const char *filename)
 {
        struct image ulink_firmware_image;
-       int ret, i;
+       int ret;
 
        ret = ulink_cpu_reset(device, CPU_RESET);
        if (ret != ERROR_OK) {
@@ -411,7 +411,7 @@ int ulink_load_firmware(struct ulink *device, const char 
*filename)
        }
 
        /* Download all sections in the image to ULINK */
-       for (i = 0; i < ulink_firmware_image.num_sections; i++) {
+       for (unsigned int i = 0; i < ulink_firmware_image.num_sections; i++) {
                ret = ulink_write_firmware_section(device, 
&ulink_firmware_image, i);
                if (ret != ERROR_OK)
                        return ret;
diff --git a/src/jtag/drivers/usb_blaster/ublast2_access_libusb.c 
b/src/jtag/drivers/usb_blaster/ublast2_access_libusb.c
index f8ff66e..70c63da 100644
--- a/src/jtag/drivers/usb_blaster/ublast2_access_libusb.c
+++ b/src/jtag/drivers/usb_blaster/ublast2_access_libusb.c
@@ -162,7 +162,7 @@ static int load_usb_blaster_firmware(struct 
libusb_device_handle *libusb_dev,
                                     100);
 
        /* Download all sections in the image to ULINK */
-       for (int i = 0; i < ublast2_firmware_image.num_sections; i++) {
+       for (unsigned int i = 0; i < ublast2_firmware_image.num_sections; i++) {
                ret = ublast2_write_firmware_section(libusb_dev,
                                                     &ublast2_firmware_image, 
i);
                if (ret != ERROR_OK) {
diff --git a/src/target/etm.c b/src/target/etm.c
index 5d079ff..30c0fdd 100644
--- a/src/target/etm.c
+++ b/src/target/etm.c
@@ -650,7 +650,6 @@ static struct etm_capture_driver *etm_capture_drivers[] = {
 
 static int etm_read_instruction(struct etm_context *ctx, struct 
arm_instruction *instruction)
 {
-       int i;
        int section = -1;
        size_t size_read;
        uint32_t opcode;
@@ -660,7 +659,7 @@ static int etm_read_instruction(struct etm_context *ctx, 
struct arm_instruction
                return ERROR_TRACE_IMAGE_UNAVAILABLE;
 
        /* search for the section the current instruction belongs to */
-       for (i = 0; i < ctx->image->num_sections; i++) {
+       for (unsigned int i = 0; i < ctx->image->num_sections; i++) {
                if ((ctx->image->sections[i].base_address <= ctx->current_pc) &&
                        (ctx->image->sections[i].base_address + 
ctx->image->sections[i].size >
                        ctx->current_pc)) {
diff --git a/src/target/image.c b/src/target/image.c
index 8160e5f..a021f66 100644
--- a/src/target/image.c
+++ b/src/target/image.c
@@ -124,7 +124,6 @@ static int image_ihex_buffer_complete_inner(struct image 
*image,
        uint32_t full_address;
        uint32_t cooked_bytes;
        bool end_rec = false;
-       int i;
 
        /* we can't determine the number of sections that we'll have to create 
ahead of time,
         * so we locally hold them until parsing is finished */
@@ -207,7 +206,7 @@ static int image_ihex_buffer_complete_inner(struct image 
*image,
 
                                /* copy section information */
                                image->sections = malloc(sizeof(struct 
imagesection) * image->num_sections);
-                               for (i = 0; i < image->num_sections; i++) {
+                               for (unsigned int i = 0; i < 
image->num_sections; i++) {
                                        image->sections[i].private = 
section[i].private;
                                        image->sections[i].base_address = 
section[i].base_address;
                                        image->sections[i].size = 
section[i].size;
@@ -529,7 +528,6 @@ static int image_mot_buffer_complete_inner(struct image 
*image,
        uint32_t full_address;
        uint32_t cooked_bytes;
        bool end_rec = false;
-       int i;
 
        /* we can't determine the number of sections that we'll have to create 
ahead of time,
         * so we locally hold them until parsing is finished */
@@ -658,7 +656,7 @@ static int image_mot_buffer_complete_inner(struct image 
*image,
 
                                /* copy section information */
                                image->sections = malloc(sizeof(struct 
imagesection) * image->num_sections);
-                               for (i = 0; i < image->num_sections; i++) {
+                               for (unsigned int i = 0; i < 
image->num_sections; i++) {
                                        image->sections[i].private = 
section[i].private;
                                        image->sections[i].base_address = 
section[i].base_address;
                                        image->sections[i].size = 
section[i].size;
@@ -828,8 +826,7 @@ int image_open(struct image *image, const char *url, const 
char *type_string)
 
        if (image->base_address_set) {
                /* relocate */
-               int section;
-               for (section = 0; section < image->num_sections; section++)
+               for (unsigned int section = 0; section < image->num_sections; 
section++)
                        image->sections[section].base_address += 
image->base_address;
                                                                                
        /* we're done relocating. The two statements below are mainly
                                                                                
        * for documentation purposes: stop anyone from empirically
@@ -1009,9 +1006,7 @@ void image_close(struct image *image)
                free(image_mot->buffer);
                image_mot->buffer = NULL;
        } else if (image->type == IMAGE_BUILDER) {
-               int i;
-
-               for (i = 0; i < image->num_sections; i++) {
+               for (unsigned int i = 0; i < image->num_sections; i++) {
                        free(image->sections[i].private);
                        image->sections[i].private = NULL;
                }
diff --git a/src/target/image.h b/src/target/image.h
index 9907a5f..2472927 100644
--- a/src/target/image.h
+++ b/src/target/image.h
@@ -55,7 +55,7 @@ struct imagesection {
 struct image {
        enum image_type type;           /* image type (plain, ihex, ...) */
        void *type_private;             /* type private data */
-       int num_sections;               /* number of sections contained in the 
image */
+       unsigned int num_sections;              /* number of sections contained 
in the image */
        struct imagesection *sections;  /* array of sections */
        int base_address_set;   /* whether the image has a base address set 
(for relocation purposes) */
        long long base_address;         /* base address, if one is set */
diff --git a/src/target/target.c b/src/target/target.c
index 53d3e82..d467d3a 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -3431,7 +3431,6 @@ COMMAND_HANDLER(handle_load_image_command)
        uint32_t image_size;
        target_addr_t min_address = 0;
        target_addr_t max_address = -1;
-       int i;
        struct image image;
 
        int retval = CALL_COMMAND_HANDLER(parse_load_image_command_CMD_ARGV,
@@ -3449,7 +3448,7 @@ COMMAND_HANDLER(handle_load_image_command)
 
        image_size = 0x0;
        retval = ERROR_OK;
-       for (i = 0; i < image.num_sections; i++) {
+       for (unsigned int i = 0; i < image.num_sections; i++) {
                buffer = malloc(image.sections[i].size);
                if (buffer == NULL) {
                        command_print(CMD,
@@ -3582,7 +3581,6 @@ static 
COMMAND_HELPER(handle_verify_image_command_internal, enum verify_mode ver
        uint8_t *buffer;
        size_t buf_cnt;
        uint32_t image_size;
-       int i;
        int retval;
        uint32_t checksum = 0;
        uint32_t mem_checksum = 0;
@@ -3621,12 +3619,12 @@ static 
COMMAND_HELPER(handle_verify_image_command_internal, enum verify_mode ver
        image_size = 0x0;
        int diffs = 0;
        retval = ERROR_OK;
-       for (i = 0; i < image.num_sections; i++) {
+       for (unsigned int i = 0; i < image.num_sections; i++) {
                buffer = malloc(image.sections[i].size);
                if (buffer == NULL) {
                        command_print(CMD,
-                                       "error allocating buffer for section 
(%d bytes)",
-                                       (int)(image.sections[i].size));
+                                       "error allocating buffer for section 
(%" PRIu32 " bytes)",
+                                       image.sections[i].size);
                        break;
                }
                retval = image_read_section(&image, i, 0x0, 
image.sections[i].size, buffer, &buf_cnt);
@@ -5847,7 +5845,6 @@ COMMAND_HANDLER(handle_fast_load_image_command)
        uint32_t image_size;
        target_addr_t min_address = 0;
        target_addr_t max_address = -1;
-       int i;
 
        struct image image;
 
@@ -5873,7 +5870,7 @@ COMMAND_HANDLER(handle_fast_load_image_command)
                return ERROR_FAIL;
        }
        memset(fastload, 0, sizeof(struct FastLoad)*image.num_sections);
-       for (i = 0; i < image.num_sections; i++) {
+       for (unsigned int i = 0; i < image.num_sections; i++) {
                buffer = malloc(image.sections[i].size);
                if (buffer == NULL) {
                        command_print(CMD, "error allocating buffer for section 
(%d bytes)",
diff --git a/src/target/xscale.c b/src/target/xscale.c
index 6d1d426..7f03bdc 100644
--- a/src/target/xscale.c
+++ b/src/target/xscale.c
@@ -2582,7 +2582,6 @@ static int xscale_read_instruction(struct target *target, 
uint32_t pc,
        struct arm_instruction *instruction)
 {
        struct xscale_common *const xscale = target_to_xscale(target);
-       int i;
        int section = -1;
        size_t size_read;
        uint32_t opcode;
@@ -2592,7 +2591,7 @@ static int xscale_read_instruction(struct target *target, 
uint32_t pc,
                return ERROR_TRACE_IMAGE_UNAVAILABLE;
 
        /* search for the section the current instruction belongs to */
-       for (i = 0; i < xscale->trace.image->num_sections; i++) {
+       for (unsigned int i = 0; i < xscale->trace.image->num_sections; i++) {
                if ((xscale->trace.image->sections[i].base_address <= pc) &&
                        (xscale->trace.image->sections[i].base_address +
                        xscale->trace.image->sections[i].size > pc)) {

-- 


_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to