libteam/options: fix s32/u32 data storage on big endian
diff mbox series

Message ID 1540794869-3078-1-git-send-email-liuhangbin@gmail.com
State New
Headers show
Series
  • libteam/options: fix s32/u32 data storage on big endian
Related show

Commit Message

Hangbin Liu Oct. 29, 2018, 6:34 a.m. UTC
When put signed/unsigned int data to long on big endian(PPC64) and read it as
singed/unsigned int, we will read from high bytes and get wrong number, e.g.
wrong active port index and priority values.

Fix it by using signed/unsiged int directly when store s32/u32 values.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 libteam/options.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

Comments

Jiri Pirko Nov. 5, 2018, 4:13 p.m. UTC | #1
Mon, Oct 29, 2018 at 07:34:29AM CET, liuhangbin@gmail.com wrote:
>When put signed/unsigned int data to long on big endian(PPC64) and read it as
>singed/unsigned int, we will read from high bytes and get wrong number, e.g.
>wrong active port index and priority values.
>
>Fix it by using signed/unsiged int directly when store s32/u32 values.
>
>Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>

Applied with "unsiged" typo fixed. Thanks!

Patch
diff mbox series

diff --git a/libteam/options.c b/libteam/options.c
index 3f444cf..71cc99e 100644
--- a/libteam/options.c
+++ b/libteam/options.c
@@ -258,12 +258,13 @@  int get_options_handler(struct nl_msg *msg, void *arg)
 		bool changed;
 		int nla_type;
 		int opt_type;
-		long tmp;
-		bool tmp_bool;
 		void *data;
 		int data_len = 0;
 		int err;
 		struct nlattr *data_attr;
+		unsigned int tmp_u32;
+		bool tmp_bool;
+		int tmp_s32;
 
 		if (nla_parse_nested(option_attrs, TEAM_ATTR_OPTION_MAX,
 				     nl_option, NULL)) {
@@ -304,8 +305,8 @@  int get_options_handler(struct nl_msg *msg, void *arg)
 
 		switch (nla_type) {
 		case NLA_U32:
-			tmp = (long) nla_get_u32(data_attr);
-			data = &tmp;
+			tmp_u32 = nla_get_u32(data_attr);
+			data = &tmp_u32;
 			opt_type = TEAM_OPTION_TYPE_U32;
 			break;
 		case NLA_STRING:
@@ -323,8 +324,8 @@  int get_options_handler(struct nl_msg *msg, void *arg)
 			opt_type = TEAM_OPTION_TYPE_BOOL;
 			break;
 		case NLA_S32:
-			tmp = (long) nla_get_s32(data_attr);
-			data = &tmp;
+			tmp_s32 = nla_get_s32(data_attr);
+			data = &tmp_s32;
 			opt_type = TEAM_OPTION_TYPE_S32;
 			break;
 		default: