From patchwork Mon Oct 29 06:34:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hangbin Liu X-Patchwork-Id: 10658791 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C121E13BF for ; Mon, 29 Oct 2018 06:34:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B14432951D for ; Mon, 29 Oct 2018 06:34:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A3E662969D; Mon, 29 Oct 2018 06:34:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from bastion.fedoraproject.org (bastion01.fedoraproject.org [209.132.181.2]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 48D6E2951D for ; Mon, 29 Oct 2018 06:34:54 +0000 (UTC) Received: from mailman01.phx2.fedoraproject.org (mailman01.phx2.fedoraproject.org [10.5.126.36]) by bastion01.phx2.fedoraproject.org (Postfix) with ESMTP id 99DD560748F1; Mon, 29 Oct 2018 06:34:52 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 bastion01.phx2.fedoraproject.org 99DD560748F1 Received: from mailman01.phx2.fedoraproject.org (localhost [IPv6:::1]) by mailman01.phx2.fedoraproject.org (Postfix) with ESMTP id 91F2E23EE18BE; Mon, 29 Oct 2018 06:34:52 +0000 (UTC) Received: by mailman01.phx2.fedoraproject.org (Postfix, from userid 991) id 579D623EE18BE; Mon, 29 Oct 2018 06:34:50 +0000 (UTC) Received: from smtp-mm-osuosl01.fedoraproject.org (smtp-mm-osuosl01.vpn.fedoraproject.org [192.168.1.23]) by mailman01.phx2.fedoraproject.org (Postfix) with ESMTP id D8C9823EE18B7 for ; Mon, 29 Oct 2018 06:34:49 +0000 (UTC) Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by smtp-mm-osuosl01.fedoraproject.org (Postfix) with ESMTPS id 9744598070 for ; Mon, 29 Oct 2018 06:34:49 +0000 (UTC) Received: by mail-pf1-x442.google.com with SMTP id u4-v6so1125400pfh.12 for ; Sun, 28 Oct 2018 23:34:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=as+bkSRcWY/DE0vy6cPtANrX+FHtGLQhxiO+Xm0P+aY=; b=NqeH1y4rjhoLc8V0EuFZ+eJycE0BezfpjEWiRbqeRgdVpp2EaKpWhPcsuxnXwBriaK diYI8oO+Y7xfIIUddgUbd21ChfabMfiVY3UFj4klBrI0sEjqUU1844/w9ynjJLnAxrSt 1rQc0x7SLXOz2hEKsUF267vgT4xalUqVEuFDA0XOWJ7NGrSEXJ2MuG6aC8SGRS0hcgKz LjTUjLkjNdPEs/+0YHtE2d0t+yXMnVl5KAjrh60PsLAr6JxgCSyyv7Cx3LqFtowvgcY3 BjPD2x5qpQ/p2KNXB05hDgA9asjcoatH9b5I5/pVC6mh6Gqp1p6/6V6RD9v2m0oFCJPW 3Igw== X-Gm-Message-State: AGRZ1gKD8ltWtICpTcMmlgsEnsx2sI+8zWDWlZLHUSbArRw8Vluj0sRs 2vGAjTdzVt5nkjvOYA+uSjjW3dzmmOc= X-Google-Smtp-Source: AJdET5cIq6Z2lgjtVc63l539gl8S1CKC73IB6OunWFaSBsbMJit1ciHslWMx7XwilMX/3AjVnVBs+g== X-Received: by 2002:a63:1a1c:: with SMTP id a28-v6mr12362504pga.157.1540794888884; Sun, 28 Oct 2018 23:34:48 -0700 (PDT) Received: from leo.usersys.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id h6-v6sm22730330pgm.14.2018.10.28.23.34.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Oct 2018 23:34:48 -0700 (PDT) From: Hangbin Liu To: libteam@lists.fedorahosted.org Subject: [PATCH] libteam/options: fix s32/u32 data storage on big endian Date: Mon, 29 Oct 2018 14:34:29 +0800 Message-Id: <1540794869-3078-1-git-send-email-liuhangbin@gmail.com> X-Mailer: git-send-email 2.5.5 Message-ID-Hash: 7OFL7OERDYH2P2PS3T4763KZLCFBBI33 X-Message-ID-Hash: 7OFL7OERDYH2P2PS3T4763KZLCFBBI33 X-MailFrom: liuhangbin@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Hangbin Liu , Jiri Pirko X-Mailman-Version: 3.1.1 Precedence: list List-Id: Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP 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 --- libteam/options.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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: