projects
/
carl9170fw.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
kconfig: rename depends_list to comment_option_list
[carl9170fw.git]
/
tools
/
lib
/
carlfw.c
diff --git
a/tools/lib/carlfw.c
b/tools/lib/carlfw.c
index de942219833ecc87c3ca713d25a6022fcd8c6fdf..79a7467ad3f5e0e0f547f5263d8215b91b1d560d 100644
(file)
--- a/
tools/lib/carlfw.c
+++ b/
tools/lib/carlfw.c
@@
-1,5
+1,5
@@
/*
/*
- * Copyright 2010
,
Christian Lamparter <chunkeey@googlemail.com>
+ * Copyright 2010
-2011
Christian Lamparter <chunkeey@googlemail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@
-170,7
+170,7
@@
static int __carlfw_load(struct carlfw_file *file, const char *name, const char
err = fread(file->data, file->len, 1, fh);
if (err != 1)
err = fread(file->data, file->len, 1, fh);
if (err != 1)
- return ferror(fh);
+ return
-
ferror(fh);
file->name = strdup(name);
fclose(fh);
file->name = strdup(name);
fclose(fh);
@@
-186,26
+186,34
@@
static void *__carlfw_find_desc(struct carlfw_file *file,
unsigned int len,
uint8_t compatible_revision)
{
unsigned int len,
uint8_t compatible_revision)
{
- int scan
= file->len
, found = 0;
+ int scan, found = 0;
struct carl9170fw_desc_head *tmp = NULL;
struct carl9170fw_desc_head *tmp = NULL;
- while (scan >= 0) {
- if (file->data[scan] == descid[sizeof(descid) - found - 1])
+ /*
+ * Note: the last desc also has atleast a full desc_head.
+ * There's no reason for looking beyond that point.
+ */
+ scan = (file->len - 1) - (sizeof(*tmp) - CARL9170FW_MAGIC_SIZE);
+ while (scan > 0) {
+ if (file->data[scan] == descid[CARL9170FW_MAGIC_SIZE - found - 1])
found++;
else
found = 0;
found++;
else
found = 0;
- if (found ==
sizeof(descid)
)
+ if (found ==
CARL9170FW_MAGIC_SIZE
)
break;
scan--;
}
break;
scan--;
}
- if (found == sizeof(descid)) {
+ if (found == CARL9170FW_MAGIC_SIZE) {
+ u16 tmp_desc_len;
+
tmp = (void *) &file->data[scan];
tmp = (void *) &file->data[scan];
+ tmp_desc_len = le16_to_cpu(tmp->length);
if (!CHECK_HDR_VERSION(tmp, compatible_revision) &&
if (!CHECK_HDR_VERSION(tmp, compatible_revision) &&
- (
le16_to_cpu(tmp->length)
>= len))
+ (
scan + tmp_desc_len <= file->len) && (tmp_desc_len
>= len))
return tmp;
}
return tmp;
}
@@
-280,7
+288,7
@@
void carlfw_desc_del(struct carlfw *fw,
}
void *carlfw_desc_mod_len(struct carlfw *fw __unused,
}
void *carlfw_desc_mod_len(struct carlfw *fw __unused,
- struct carl9170fw_desc_head *desc,
in
t len)
+ struct carl9170fw_desc_head *desc,
size_
t len)
{
struct carlfw_list_entry *obj, tmp;
int new_len = le16_to_cpu(desc->length) + len;
{
struct carlfw_list_entry *obj, tmp;
int new_len = le16_to_cpu(desc->length) + len;
@@
-409,19
+417,10
@@
struct carlfw *carlfw_load(const char *basename)
init_list_head(&fw->desc_list);
init_list_head(&fw->desc_list);
- snprintf(filename, sizeof(filename), "%s.dsc", basename);
- err = __carlfw_load(&fw->hdr, filename, "r");
-
- snprintf(filename, sizeof(filename), "%s.fw", basename);
- err = __carlfw_load(&fw->fw, filename, "r");
- if (!err)
- goto found;
-
err = __carlfw_load(&fw->fw, basename, "r");
if (err)
goto err_out;
err = __carlfw_load(&fw->fw, basename, "r");
if (err)
goto err_out;
-found:
if (fw->hdr.name)
hdr_file = &fw->hdr;
else
if (fw->hdr.name)
hdr_file = &fw->hdr;
else
@@
-563,14
+562,14
@@
int carlfw_store(struct carlfw *fw)
err = fwrite(iter->data, elen, 1, fh);
if (err != 1) {
err = fwrite(iter->data, elen, 1, fh);
if (err != 1) {
- err = ferror(fh);
+ err =
-
ferror(fh);
goto close_out;
}
}
err = fwrite(&last_desc, sizeof(last_desc), 1, fh);
if (err != 1) {
goto close_out;
}
}
err = fwrite(&last_desc, sizeof(last_desc), 1, fh);
if (err != 1) {
- err = ferror(fh);
+ err =
-
ferror(fh);
goto close_out;
}
goto close_out;
}