diff options
author | Jiri Pirko <jpirko@redhat.com> | 2012-06-19 01:54:04 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-06-19 18:00:22 -0400 |
commit | d299cd51166c156c77250f4cdd6363b74fd2f77e (patch) | |
tree | a4b94dd70e60b8496b45ff7401f17e516de8289c /drivers | |
parent | 0402788a6cda4e204a805e83eaaff64fef9e4418 (diff) |
team: for nomode use dummy struct team_mode
That leaves team->mode and all its values valid so no checks would be
needed (for example in team_mode_option_get()).
Signed-off-by: Jiri Pirko <jpirko@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/net/team/team.c | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c index bdf87a971382..343f4ffaf8f0 100644 --- a/drivers/net/team/team.c +++ b/drivers/net/team/team.c | |||
@@ -479,6 +479,20 @@ rx_handler_result_t team_dummy_receive(struct team *team, | |||
479 | return RX_HANDLER_ANOTHER; | 479 | return RX_HANDLER_ANOTHER; |
480 | } | 480 | } |
481 | 481 | ||
482 | static const struct team_mode __team_no_mode = { | ||
483 | .kind = "*NOMODE*", | ||
484 | }; | ||
485 | |||
486 | static bool team_is_mode_set(struct team *team) | ||
487 | { | ||
488 | return team->mode != &__team_no_mode; | ||
489 | } | ||
490 | |||
491 | static void team_set_no_mode(struct team *team) | ||
492 | { | ||
493 | team->mode = &__team_no_mode; | ||
494 | } | ||
495 | |||
482 | static void team_adjust_ops(struct team *team) | 496 | static void team_adjust_ops(struct team *team) |
483 | { | 497 | { |
484 | /* | 498 | /* |
@@ -487,13 +501,13 @@ static void team_adjust_ops(struct team *team) | |||
487 | */ | 501 | */ |
488 | 502 | ||
489 | if (list_empty(&team->port_list) || | 503 | if (list_empty(&team->port_list) || |
490 | !team->mode || !team->mode->ops->transmit) | 504 | !team_is_mode_set(team) || !team->mode->ops->transmit) |
491 | team->ops.transmit = team_dummy_transmit; | 505 | team->ops.transmit = team_dummy_transmit; |
492 | else | 506 | else |
493 | team->ops.transmit = team->mode->ops->transmit; | 507 | team->ops.transmit = team->mode->ops->transmit; |
494 | 508 | ||
495 | if (list_empty(&team->port_list) || | 509 | if (list_empty(&team->port_list) || |
496 | !team->mode || !team->mode->ops->receive) | 510 | !team_is_mode_set(team) || !team->mode->ops->receive) |
497 | team->ops.receive = team_dummy_receive; | 511 | team->ops.receive = team_dummy_receive; |
498 | else | 512 | else |
499 | team->ops.receive = team->mode->ops->receive; | 513 | team->ops.receive = team->mode->ops->receive; |
@@ -508,7 +522,7 @@ static int __team_change_mode(struct team *team, | |||
508 | const struct team_mode *new_mode) | 522 | const struct team_mode *new_mode) |
509 | { | 523 | { |
510 | /* Check if mode was previously set and do cleanup if so */ | 524 | /* Check if mode was previously set and do cleanup if so */ |
511 | if (team->mode) { | 525 | if (team_is_mode_set(team)) { |
512 | void (*exit_op)(struct team *team) = team->ops.exit; | 526 | void (*exit_op)(struct team *team) = team->ops.exit; |
513 | 527 | ||
514 | /* Clear ops area so no callback is called any longer */ | 528 | /* Clear ops area so no callback is called any longer */ |
@@ -518,7 +532,7 @@ static int __team_change_mode(struct team *team, | |||
518 | if (exit_op) | 532 | if (exit_op) |
519 | exit_op(team); | 533 | exit_op(team); |
520 | team_mode_put(team->mode); | 534 | team_mode_put(team->mode); |
521 | team->mode = NULL; | 535 | team_set_no_mode(team); |
522 | /* zero private data area */ | 536 | /* zero private data area */ |
523 | memset(&team->mode_priv, 0, | 537 | memset(&team->mode_priv, 0, |
524 | sizeof(struct team) - offsetof(struct team, mode_priv)); | 538 | sizeof(struct team) - offsetof(struct team, mode_priv)); |
@@ -553,7 +567,7 @@ static int team_change_mode(struct team *team, const char *kind) | |||
553 | return -EBUSY; | 567 | return -EBUSY; |
554 | } | 568 | } |
555 | 569 | ||
556 | if (team->mode && strcmp(team->mode->kind, kind) == 0) { | 570 | if (team_is_mode_set(team) && strcmp(team->mode->kind, kind) == 0) { |
557 | netdev_err(dev, "Unable to change to the same mode the team is in\n"); | 571 | netdev_err(dev, "Unable to change to the same mode the team is in\n"); |
558 | return -EINVAL; | 572 | return -EINVAL; |
559 | } | 573 | } |
@@ -912,11 +926,9 @@ static int team_port_del(struct team *team, struct net_device *port_dev) | |||
912 | * Net device ops | 926 | * Net device ops |
913 | *****************/ | 927 | *****************/ |
914 | 928 | ||
915 | static const char team_no_mode_kind[] = "*NOMODE*"; | ||
916 | |||
917 | static int team_mode_option_get(struct team *team, struct team_gsetter_ctx *ctx) | 929 | static int team_mode_option_get(struct team *team, struct team_gsetter_ctx *ctx) |
918 | { | 930 | { |
919 | ctx->data.str_val = team->mode ? team->mode->kind : team_no_mode_kind; | 931 | ctx->data.str_val = team->mode->kind; |
920 | return 0; | 932 | return 0; |
921 | } | 933 | } |
922 | 934 | ||
@@ -1014,6 +1026,7 @@ static int team_init(struct net_device *dev) | |||
1014 | 1026 | ||
1015 | team->dev = dev; | 1027 | team->dev = dev; |
1016 | mutex_init(&team->lock); | 1028 | mutex_init(&team->lock); |
1029 | team_set_no_mode(team); | ||
1017 | 1030 | ||
1018 | team->pcpu_stats = alloc_percpu(struct team_pcpu_stats); | 1031 | team->pcpu_stats = alloc_percpu(struct team_pcpu_stats); |
1019 | if (!team->pcpu_stats) | 1032 | if (!team->pcpu_stats) |