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
23 23
24/* Find the next record, taking into account the 4-byte alignment */24/* Find the next record, taking into account the 4-byte alignment */
25static inline const struct ihex_binrec *25static inline const struct ihex_binrec *
26ihex_next_binrec(const struct ihex_binrec *rec)26__ihex_next_binrec(const struct ihex_binrec *rec)
27{27{
28 int next = ((be16_to_cpu(rec->len) + 5) & ~3) - 2;28 int next = ((be16_to_cpu(rec->len) + 5) & ~3) - 2;
29 rec = (void *)&rec->data[next];29 rec = (void *)&rec->data[next];
30 30
31 return rec;
32}
33
34static inline const struct ihex_binrec *
35ihex_next_binrec(const struct ihex_binrec *rec)
36{
37 rec = __ihex_next_binrec(rec);
38
31 return be16_to_cpu(rec->len) ? rec : NULL;39 return be16_to_cpu(rec->len) ? rec : NULL;
32}40}
33 41
34/* Check that ihex_next_binrec() won't take us off the end of the image... */42/* Check that ihex_next_binrec() won't take us off the end of the image... */
35static inline int ihex_validate_fw(const struct firmware *fw)43static inline int ihex_validate_fw(const struct firmware *fw)
36{44{
37 const struct ihex_binrec *rec;45 const struct ihex_binrec *end, *rec;
38 size_t ofs = 0;
39 46
40 while (ofs <= fw->size - sizeof(*rec)) {47 rec = (const void *)fw->data;
41 rec = (void *)&fw->data[ofs];48 end = (const void *)&fw->data[fw->size - sizeof(*end)];
42 49
50 for (; rec <= end; rec = __ihex_next_binrec(rec)) {
43 /* Zero length marks end of records */51 /* Zero length marks end of records */
44 if (!be16_to_cpu(rec->len))52 if (!be16_to_cpu(rec->len))
45 return 0;53 return 0;
46
47 /* Point to next record... */
48 ofs += (sizeof(*rec) + be16_to_cpu(rec->len) + 3) & ~3;
49 }54 }
50 return -EINVAL;55 return -EINVAL;
51}56}

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