Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For linux msm/valgrind fixes #86

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions firehose.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,24 @@ static xmlNode *firehose_response_parse(const void *buf, size_t len, int *error)
static int firehose_generic_parser(xmlNode *node, void *data)
{
xmlChar *value;
int ret = -EINVAL;

value = xmlGetProp(node, (xmlChar*)"value");
if (!value)
return -EINVAL;

if (xmlStrcmp(node->name, (xmlChar*)"log") == 0) {
printf("LOG: %s\n", value);
return -EAGAIN;
ret = -EAGAIN;
} else if (xmlStrcmp(value, (xmlChar*)"ACK") == 0) {
ret = FIREHOSE_ACK;
} else if (xmlStrcmp(value, (xmlChar*)"NAK") == 0) {
ret = FIREHOSE_NAK;
}

if (xmlStrcmp(value, (xmlChar*)"ACK") == 0)
return FIREHOSE_ACK;
if (xmlStrcmp(value, (xmlChar*)"NAK") == 0)
return FIREHOSE_NAK;
xmlFree(value);

return -EINVAL;
return ret;
}

static int firehose_read(struct qdl_device *qdl, int timeout_ms,
Expand Down Expand Up @@ -213,16 +217,23 @@ static int firehose_configure_response_parser(xmlNode *node, void *data)
size_t max_size;

value = xmlGetProp(node, (xmlChar*)"value");
if (!value)
return -EINVAL;

if (xmlStrcmp(node->name, (xmlChar*)"log") == 0) {
printf("LOG: %s\n", value);
xmlFree(value);
return -EAGAIN;
}

payload = xmlGetProp(node, (xmlChar*)"MaxPayloadSizeToTargetInBytes");
if (!value || !payload)
if (!payload) {
xmlFree(value);
return -EINVAL;
}

max_size = strtoul((char*)payload, NULL, 10);
xmlFree(payload);

/*
* When receiving an ACK the remote may indicate that we should attempt
Expand All @@ -234,9 +245,11 @@ static int firehose_configure_response_parser(xmlNode *node, void *data)
return -EINVAL;

max_size = strtoul((char*)payload, NULL, 10);
xmlFree(payload);
}

*(size_t*)data = max_size;
xmlFree(value);

return FIREHOSE_ACK;
}
Expand Down Expand Up @@ -437,6 +450,8 @@ static int firehose_program(struct qdl_device *qdl, struct program *program, int

out:
xmlFreeDoc(doc);
free(buf);

return ret == FIREHOSE_ACK ? 0 : -1;
}

Expand Down
17 changes: 17 additions & 0 deletions patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,20 @@ int patch_execute(struct qdl_device *qdl, int (*apply)(struct qdl_device *qdl, s

return 0;
}

void free_patches(void)
{
struct patch *patch = patches;
struct patch *next;

for (patch = patches; patch; patch = next) {
next = patch->next;
free((void *)patch->filename);
free((void *)patch->start_sector);
free((void *)patch->value);
free((void *)patch->what);
free(patch);
}

patches = NULL;
}
1 change: 1 addition & 0 deletions patch.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ struct patch {

int patch_load(const char *patch_file);
int patch_execute(struct qdl_device *qdl, int (*apply)(struct qdl_device *qdl, struct patch *patch));
void free_patches(void);

#endif
16 changes: 16 additions & 0 deletions program.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,19 @@ int program_find_bootable_partition(void)

return part;
}

void free_programs(void)
{
struct program *program = programes;
struct program *next;

for (program = programes; program; program = next) {
next = program->next;
free((void *)program->filename);
free((void *)program->label);
free((void *)program->start_sector);
free(program);
}

programes = NULL;
}
1 change: 1 addition & 0 deletions program.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ int program_execute(struct qdl_device *qdl, int (*apply)(struct qdl_device *qdl,
const char *incdir, bool allow_missing);
int erase_execute(struct qdl_device *qdl, int (*apply)(struct qdl_device *qdl, struct program *program));
int program_find_bootable_partition(void);
void free_programs(void);

#endif
13 changes: 9 additions & 4 deletions qdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,21 @@ int main(int argc, char **argv)

ret = qdl_open(&qdl, serial);
if (ret)
return 1;
goto out_cleanup;

qdl.mappings[0] = prog_mbn;
ret = sahara_run(&qdl, qdl.mappings, true, NULL, NULL);
if (ret < 0)
return 1;
goto out_cleanup;

ret = firehose_run(&qdl, incdir, storage, allow_missing);
if (ret < 0)
return 1;
goto out_cleanup;

out_cleanup:
qdl_close(&qdl);
free_programs();
free_patches();

return 0;
return !!ret;
}
1 change: 1 addition & 0 deletions qdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct qdl_device {
};

int qdl_open(struct qdl_device *qdl, const char *serial);
void qdl_close(struct qdl_device *qdl);
int qdl_read(struct qdl_device *qdl, void *buf, size_t len, unsigned int timeout);
int qdl_write(struct qdl_device *qdl, const void *buf, size_t len);
void qdl_set_out_chunk_size(struct qdl_device *qdl, long size);
Expand Down
7 changes: 5 additions & 2 deletions sahara.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,14 @@ struct sahara_pkt {
uint32_t compatible;
uint32_t max_len;
uint32_t mode;
uint32_t reserved[6];
} hello_req;
struct {
uint32_t version;
uint32_t compatible;
uint32_t status;
uint32_t mode;
uint32_t reserved[6];
} hello_resp;
struct {
uint32_t image;
Expand Down Expand Up @@ -153,7 +155,7 @@ static void sahara_send_reset(struct qdl_device *qdl)

static void sahara_hello(struct qdl_device *qdl, struct sahara_pkt *pkt)
{
struct sahara_pkt resp;
struct sahara_pkt resp = {};

assert(pkt->length == SAHARA_HELLO_LENGTH);

Expand Down Expand Up @@ -490,7 +492,8 @@ int sahara_run(struct qdl_device *qdl, char *img_arr[], bool single_image,
}
}

close(ramdump_dir);
if (ramdump_dir >= 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hygine spelling in the commit message

close(ramdump_dir);

return done ? 0 : -1;
}
12 changes: 10 additions & 2 deletions usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,12 @@ static int qdl_try_open(libusb_device *dev, struct qdl_device *qdl, const char *
qdl->out_chunk_size);
}

return 1;
break;
}

return 0;
libusb_free_config_descriptor(config);

return !!qdl->usb_handle;
}

int qdl_open(struct qdl_device *qdl, const char *serial)
Expand Down Expand Up @@ -208,6 +210,12 @@ int qdl_open(struct qdl_device *qdl, const char *serial)
return -1;
}

void qdl_close(struct qdl_device *qdl)
{
libusb_close(qdl->usb_handle);
libusb_exit(NULL);
}

int qdl_read(struct qdl_device *qdl, void *buf, size_t len, unsigned int timeout)
{
int actual;
Expand Down
13 changes: 9 additions & 4 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ void print_hex_dump(const char *prefix, const void *buf, size_t len)

unsigned attr_as_unsigned(xmlNode *node, const char *attr, int *errors)
{
unsigned int ret;
xmlChar *value;

value = xmlGetProp(node, (xmlChar*)attr);
Expand All @@ -92,21 +93,25 @@ unsigned attr_as_unsigned(xmlNode *node, const char *attr, int *errors)
return 0;
}

return (unsigned int) strtoul((char*)value, NULL, 0);
ret = (unsigned int) strtoul((char*)value, NULL, 0);
xmlFree(value);
return ret;
}

const char *attr_as_string(xmlNode *node, const char *attr, int *errors)
{
xmlChar *value;
char *ret = NULL;

value = xmlGetProp(node, (xmlChar*)attr);
if (!value) {
(*errors)++;
return NULL;
}

if (value[0] == '\0')
return NULL;
if (value[0] != '\0')
ret = strdup((char*)value);

return strdup((char*)value);
xmlFree(value);
return ret;
}
Loading