Skip to content

Commit

Permalink
net: marvell: prestera: fix incorrect return of port_find
Browse files Browse the repository at this point in the history
In case, when some ports is in list and we don't find requested - we
return last iterator state and not return NULL as expected.

Fixes: 501ef30 ("net: marvell: prestera: Add driver for Prestera family ASIC devices")
Signed-off-by: Yevhen Orlov <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
OrlovEI authored and kuba-moo committed Dec 18, 2021
1 parent f845fe5 commit 8b681bd
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions drivers/net/ethernet/marvell/prestera/prestera_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ int prestera_port_pvid_set(struct prestera_port *port, u16 vid)
struct prestera_port *prestera_port_find_by_hwid(struct prestera_switch *sw,
u32 dev_id, u32 hw_id)
{
struct prestera_port *port = NULL;
struct prestera_port *port = NULL, *tmp;

read_lock(&sw->port_list_lock);
list_for_each_entry(port, &sw->port_list, list) {
if (port->dev_id == dev_id && port->hw_id == hw_id)
list_for_each_entry(tmp, &sw->port_list, list) {
if (tmp->dev_id == dev_id && tmp->hw_id == hw_id) {
port = tmp;
break;
}
}
read_unlock(&sw->port_list_lock);

Expand All @@ -68,12 +70,14 @@ struct prestera_port *prestera_port_find_by_hwid(struct prestera_switch *sw,

struct prestera_port *prestera_find_port(struct prestera_switch *sw, u32 id)
{
struct prestera_port *port = NULL;
struct prestera_port *port = NULL, *tmp;

read_lock(&sw->port_list_lock);
list_for_each_entry(port, &sw->port_list, list) {
if (port->id == id)
list_for_each_entry(tmp, &sw->port_list, list) {
if (tmp->id == id) {
port = tmp;
break;
}
}
read_unlock(&sw->port_list_lock);

Expand Down

0 comments on commit 8b681bd

Please sign in to comment.