Permalink
Browse files

thunderbolt: Refactor and fix parsing of port drom entries

Currently tb_drom_parse_entry() is only able to parse drom entries of
type TB_DROM_ENTRY_PORT. Rename it to tb_drom_parse_entry_port().
Fold tb_drom_parse_port_entry() into it.

Its return value is currently ignored. Evaluate it and abort parsing on
error.

Change tb_drom_parse_entries() to accommodate for parsing of other entry
types than TB_DROM_ENTRY_PORT.

Cc: Andreas Noever <andreas.noever@gmail.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
  • Loading branch information...
l1k committed Dec 26, 2015
1 parent 2ea659a commit b6c9db73258b1ee3d9483713b1afa7ee5e43515e
Showing with 16 additions and 16 deletions.
  1. +16 −16 drivers/thunderbolt/eeprom.c
@@ -292,25 +292,13 @@ int tb_drom_read_uid_only(struct tb_switch *sw, u64 *uid)
return 0;
}
static void tb_drom_parse_port_entry(struct tb_port *port,
struct tb_drom_entry_port *entry)
{
port->link_nr = entry->link_nr;
if (entry->has_dual_link_port)
port->dual_link_port =
&port->sw->ports[entry->dual_link_port_nr];
}
static int tb_drom_parse_entry(struct tb_switch *sw,
struct tb_drom_entry_header *header)
static int tb_drom_parse_entry_port(struct tb_switch *sw,
struct tb_drom_entry_header *header)
{
struct tb_port *port;
int res;
enum tb_port_type type;
if (header->type != TB_DROM_ENTRY_PORT)
return 0;
port = &sw->ports[header->index];
port->disabled = header->port_disabled;
if (port->disabled)
@@ -329,7 +317,10 @@ static int tb_drom_parse_entry(struct tb_switch *sw,
header->len, sizeof(struct tb_drom_entry_port));
return -EIO;
}
tb_drom_parse_port_entry(port, entry);
port->link_nr = entry->link_nr;
if (entry->has_dual_link_port)
port->dual_link_port =
&port->sw->ports[entry->dual_link_port_nr];
}
return 0;
}
@@ -344,6 +335,7 @@ static int tb_drom_parse_entries(struct tb_switch *sw)
struct tb_drom_header *header = (void *) sw->drom;
u16 pos = sizeof(*header);
u16 drom_size = header->data_len + TB_DROM_DATA_START;
int res;
while (pos < drom_size) {
struct tb_drom_entry_header *entry = (void *) (sw->drom + pos);
@@ -353,7 +345,15 @@ static int tb_drom_parse_entries(struct tb_switch *sw)
return -EIO;
}
tb_drom_parse_entry(sw, entry);
switch (entry->type) {
case TB_DROM_ENTRY_GENERIC:
break;
case TB_DROM_ENTRY_PORT:
res = tb_drom_parse_entry_port(sw, entry);
break;
}
if (res)
return res;
pos += entry->len;
}

0 comments on commit b6c9db7

Please sign in to comment.