]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blobdiff - drivers/net/ethernet/intel/fm10k/fm10k_tlv.c
Merge tag 'nfc-next-4.7-1' of git://git.kernel.org/pub/scm/linux/kernel/git/sameo...
[mirror_ubuntu-hirsute-kernel.git] / drivers / net / ethernet / intel / fm10k / fm10k_tlv.c
index ab01bb30752f9886c530de8648473d95622e7eda..f8e87bf086b938fea1ca776cd4162dfe62587402 100644 (file)
@@ -1,5 +1,5 @@
-/* Intel Ethernet Switch Host Interface Driver
- * Copyright(c) 2013 - 2015 Intel Corporation.
+/* Intel(R) Ethernet Switch Host Interface Driver
+ * Copyright(c) 2013 - 2016 Intel Corporation.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -222,7 +222,7 @@ s32 fm10k_tlv_attr_put_value(u32 *msg, u16 attr_id, s64 value, u32 len)
        attr = &msg[FM10K_TLV_DWORD_LEN(*msg)];
 
        if (len < 4) {
-               attr[1] = (u32)value & ((0x1ul << (8 * len)) - 1);
+               attr[1] = (u32)value & (BIT(8 * len) - 1);
        } else {
                attr[1] = (u32)value;
                if (len > 4)
@@ -481,7 +481,8 @@ static s32 fm10k_tlv_attr_validate(u32 *attr,
  *  up into an array of pointers stored in results.  The function will
  *  return FM10K_ERR_PARAM on any input or message error,
  *  FM10K_NOT_IMPLEMENTED for any attribute that is outside of the array
- *  and 0 on success.
+ *  and 0 on success. Any attributes not found in tlv_attr will be silently
+ *  ignored.
  **/
 static s32 fm10k_tlv_attr_parse(u32 *attr, u32 **results,
                                const struct fm10k_tlv_attr *tlv_attr)
@@ -518,14 +519,15 @@ static s32 fm10k_tlv_attr_parse(u32 *attr, u32 **results,
        while (offset < len) {
                attr_id = *attr & FM10K_TLV_ID_MASK;
 
-               if (attr_id < FM10K_TLV_RESULTS_MAX)
-                       err = fm10k_tlv_attr_validate(attr, tlv_attr);
-               else
-                       err = FM10K_NOT_IMPLEMENTED;
+               if (attr_id >= FM10K_TLV_RESULTS_MAX)
+                       return FM10K_NOT_IMPLEMENTED;
 
-               if (err < 0)
+               err = fm10k_tlv_attr_validate(attr, tlv_attr);
+               if (err == FM10K_NOT_IMPLEMENTED)
+                       ; /* silently ignore non-implemented attributes */
+               else if (err)
                        return err;
-               if (!err)
+               else
                        results[attr_id] = attr;
 
                /* update offset */
@@ -652,29 +654,29 @@ const struct fm10k_tlv_attr fm10k_tlv_msg_test_attr[] = {
  **/
 static void fm10k_tlv_msg_test_generate_data(u32 *msg, u32 attr_flags)
 {
-       if (attr_flags & (1 << FM10K_TEST_MSG_STRING))
+       if (attr_flags & BIT(FM10K_TEST_MSG_STRING))
                fm10k_tlv_attr_put_null_string(msg, FM10K_TEST_MSG_STRING,
                                               test_str);
-       if (attr_flags & (1 << FM10K_TEST_MSG_MAC_ADDR))
+       if (attr_flags & BIT(FM10K_TEST_MSG_MAC_ADDR))
                fm10k_tlv_attr_put_mac_vlan(msg, FM10K_TEST_MSG_MAC_ADDR,
                                            test_mac, test_vlan);
-       if (attr_flags & (1 << FM10K_TEST_MSG_U8))
+       if (attr_flags & BIT(FM10K_TEST_MSG_U8))
                fm10k_tlv_attr_put_u8(msg, FM10K_TEST_MSG_U8,  test_u8);
-       if (attr_flags & (1 << FM10K_TEST_MSG_U16))
+       if (attr_flags & BIT(FM10K_TEST_MSG_U16))
                fm10k_tlv_attr_put_u16(msg, FM10K_TEST_MSG_U16, test_u16);
-       if (attr_flags & (1 << FM10K_TEST_MSG_U32))
+       if (attr_flags & BIT(FM10K_TEST_MSG_U32))
                fm10k_tlv_attr_put_u32(msg, FM10K_TEST_MSG_U32, test_u32);
-       if (attr_flags & (1 << FM10K_TEST_MSG_U64))
+       if (attr_flags & BIT(FM10K_TEST_MSG_U64))
                fm10k_tlv_attr_put_u64(msg, FM10K_TEST_MSG_U64, test_u64);
-       if (attr_flags & (1 << FM10K_TEST_MSG_S8))
+       if (attr_flags & BIT(FM10K_TEST_MSG_S8))
                fm10k_tlv_attr_put_s8(msg, FM10K_TEST_MSG_S8,  test_s8);
-       if (attr_flags & (1 << FM10K_TEST_MSG_S16))
+       if (attr_flags & BIT(FM10K_TEST_MSG_S16))
                fm10k_tlv_attr_put_s16(msg, FM10K_TEST_MSG_S16, test_s16);
-       if (attr_flags & (1 << FM10K_TEST_MSG_S32))
+       if (attr_flags & BIT(FM10K_TEST_MSG_S32))
                fm10k_tlv_attr_put_s32(msg, FM10K_TEST_MSG_S32, test_s32);
-       if (attr_flags & (1 << FM10K_TEST_MSG_S64))
+       if (attr_flags & BIT(FM10K_TEST_MSG_S64))
                fm10k_tlv_attr_put_s64(msg, FM10K_TEST_MSG_S64, test_s64);
-       if (attr_flags & (1 << FM10K_TEST_MSG_LE_STRUCT))
+       if (attr_flags & BIT(FM10K_TEST_MSG_LE_STRUCT))
                fm10k_tlv_attr_put_le_struct(msg, FM10K_TEST_MSG_LE_STRUCT,
                                             test_le, 8);
 }