Commit bee1f753 authored by Ido Schimmel's avatar Ido Schimmel Committed by David S. Miller

mlxsw: Fix bug in __mlxsw_item_bit_array_offset

When calculating the shift needed in order to access a bit array element
in a byte, we should multiply the index by the element size and not
assume it is fixed at 2-bits.

Fixes: 93c1edb2 ("mlxsw: Introduce Mellanox switch driver core")
Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4b0c2541
...@@ -187,6 +187,7 @@ __mlxsw_item_bit_array_offset(struct mlxsw_item *item, u16 index, u8 *shift) ...@@ -187,6 +187,7 @@ __mlxsw_item_bit_array_offset(struct mlxsw_item *item, u16 index, u8 *shift)
{ {
u16 max_index, be_index; u16 max_index, be_index;
u16 offset; /* byte offset inside the array */ u16 offset; /* byte offset inside the array */
u8 in_byte_index;
BUG_ON(index && !item->element_size); BUG_ON(index && !item->element_size);
if (item->offset % sizeof(u32) != 0 || if (item->offset % sizeof(u32) != 0 ||
...@@ -199,7 +200,8 @@ __mlxsw_item_bit_array_offset(struct mlxsw_item *item, u16 index, u8 *shift) ...@@ -199,7 +200,8 @@ __mlxsw_item_bit_array_offset(struct mlxsw_item *item, u16 index, u8 *shift)
max_index = (item->size.bytes << 3) / item->element_size - 1; max_index = (item->size.bytes << 3) / item->element_size - 1;
be_index = max_index - index; be_index = max_index - index;
offset = be_index * item->element_size >> 3; offset = be_index * item->element_size >> 3;
*shift = index % (BITS_PER_BYTE / item->element_size) << 1; in_byte_index = index % (BITS_PER_BYTE / item->element_size);
*shift = in_byte_index * item->element_size;
return item->offset + offset; return item->offset + offset;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment