History

ihex: Share code between ihex_validate_fw() and ihex_next_binrec()

Convert both ihex_validate_fw() and ihex_next_binrec() to use a helper function to calculate next record offest. This way we only have one place implementing next record offset calculation logic. No functional change intended.

Andrey Smirnov committed 7 years ago

Commit 8092e791 parent 570d0201 file · +13 −8Browse files

Showing the changes to include/linux (1 of 1 file). Show all

Unified · Split

include/linux/ihex.h+13−8
@@ -23,29 +23,34 @@ struct ihex_binrec { · 22 unmodified lines
2323
2424 /* Find the next record, taking into account the 4-byte alignment */
2525 static inline const struct ihex_binrec *
26−ihex_next_binrec(const struct ihex_binrec *rec)
26+__ihex_next_binrec(const struct ihex_binrec *rec)
2727 {
2828 int next = ((be16_to_cpu(rec->len) + 5) & ~3) - 2;
2929 rec = (void *)&rec->data[next];
3030
31+ return rec;
32+}
33+
34+static inline const struct ihex_binrec *
35+ihex_next_binrec(const struct ihex_binrec *rec)
36+{
37+ rec = __ihex_next_binrec(rec);
38+
3139 return be16_to_cpu(rec->len) ? rec : NULL;
3240 }
3341
3442 /* Check that ihex_next_binrec() won't take us off the end of the image... */
3543 static inline int ihex_validate_fw(const struct firmware *fw)
3644 {
37− const struct ihex_binrec *rec;
38− size_t ofs = 0;
45+ const struct ihex_binrec *end, *rec;
3946
40− while (ofs <= fw->size - sizeof(*rec)) {
41− rec = (void *)&fw->data[ofs];
47+ rec = (const void *)fw->data;
48+ end = (const void *)&fw->data[fw->size - sizeof(*end)];
4249
50+ for (; rec <= end; rec = __ihex_next_binrec(rec)) {
4351 /* Zero length marks end of records */
4452 if (!be16_to_cpu(rec->len))
4553 return 0;
46−
47− /* Point to next record... */
48− ofs += (sizeof(*rec) + be16_to_cpu(rec->len) + 3) & ~3;
4954 }
5055 return -EINVAL;
5156 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t