Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1651494 > unrolled thread

[PATCH v2 12/27] thunderbolt: Refactor and fix parsing of port drom entries

Started byMika Westerberg <mika.westerberg@linux.intel.com>
First post2017-05-26 18:20 +0200
Last post2017-05-27 17:50 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH v2 12/27] thunderbolt: Refactor and fix parsing of port drom entries Mika Westerberg <mika.westerberg@linux.intel.com> - 2017-05-26 18:20 +0200
    Re: [PATCH v2 12/27] thunderbolt: Refactor and fix parsing of port  drom entries Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-05-27 17:50 +0200

#1651494 — [PATCH v2 12/27] thunderbolt: Refactor and fix parsing of port drom entries

FromMika Westerberg <mika.westerberg@linux.intel.com>
Date2017-05-26 18:20 +0200
Subject[PATCH v2 12/27] thunderbolt: Refactor and fix parsing of port drom entries
Message-ID<tLq83-87A-57@gated-at.bofh.it>
From: Lukas Wunner <lukas@wunner.de>

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.

Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
 drivers/thunderbolt/eeprom.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/thunderbolt/eeprom.c b/drivers/thunderbolt/eeprom.c
index e2c1f8a45522..5c7d80a109b1 100644
--- a/drivers/thunderbolt/eeprom.c
+++ b/drivers/thunderbolt/eeprom.c
@@ -295,25 +295,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)
@@ -332,7 +320,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;
 }
@@ -347,6 +338,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);
@@ -356,7 +348,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;
 	}
-- 
2.11.0

[toc] | [next] | [standalone]


#1651904 — Re: [PATCH v2 12/27] thunderbolt: Refactor and fix parsing of port drom entries

FromAndy Shevchenko <andy.shevchenko@gmail.com>
Date2017-05-27 17:50 +0200
SubjectRe: [PATCH v2 12/27] thunderbolt: Refactor and fix parsing of port drom entries
Message-ID<tLM8x-5Sc-17@gated-at.bofh.it>
In reply to#1651494
On Fri, May 26, 2017 at 7:09 PM, Mika Westerberg
<mika.westerberg@linux.intel.com> wrote:
> From: Lukas Wunner <lukas@wunner.de>
>
> 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.
>

FWIW:
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

> Signed-off-by: Lukas Wunner <lukas@wunner.de>
> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> ---
>  drivers/thunderbolt/eeprom.c | 32 ++++++++++++++++----------------
>  1 file changed, 16 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/thunderbolt/eeprom.c b/drivers/thunderbolt/eeprom.c
> index e2c1f8a45522..5c7d80a109b1 100644
> --- a/drivers/thunderbolt/eeprom.c
> +++ b/drivers/thunderbolt/eeprom.c
> @@ -295,25 +295,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)
> @@ -332,7 +320,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;
>  }
> @@ -347,6 +338,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);
> @@ -356,7 +348,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;
>         }
> --
> 2.11.0
>



-- 
With Best Regards,
Andy Shevchenko

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web