]> www.infradead.org Git - users/dwmw2/linux.git/commit
soc: fsl_qbman: use be16_to_cpu() in qm_sg_entry_get_off()
authorVladimir Oltean <vladimir.oltean@nxp.com>
Tue, 29 Oct 2024 16:43:15 +0000 (18:43 +0200)
committerJakub Kicinski <kuba@kernel.org>
Tue, 5 Nov 2024 02:44:43 +0000 (18:44 -0800)
commita12fcef429e17cb3db47cde0692a185d3ca712a3
treeedb1c55900736523b7ced6142fe40e59beb01938
parentd2068805f688ce6e9c6099f3636879fa76e76497
soc: fsl_qbman: use be16_to_cpu() in qm_sg_entry_get_off()

struct qm_sg_entry :: offset is a 13-bit field, declared as __be16.

When using be32_to_cpu(), a wrong value will be calculated on little
endian systems (Arm), because type promotion from 16-bit to 32-bit,
which is done before the byte swap and always in the CPU native
endianness, changes the value of the scatter/gather list entry offset in
big-endian interpretation (adds two zero bytes in the LSB interpretation).
The result of the byte swap is ANDed with GENMASK(12, 0), so the result
is always zero, because only those bytes added by type promotion remain
after the application of the bit mask.

The impact of the bug is that scatter/gather frames with a non-zero
offset into the buffer are treated by the driver as if they had a zero
offset. This is all in theory, because in practice, qm_sg_entry_get_off()
has a single caller, where the bug is inconsequential, because at that
call site the buffer offset will always be zero, as will be explained in
the subsequent change.

Flagged by sparse:

warning: cast to restricted __be32
warning: cast from restricted __be16

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Breno Leitao <leitao@debian.org>
Acked-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Acked-by: Madalin Bucur <madalin.bucur@oss.nxp.com>
Link: https://patch.msgid.link/20241029164317.50182-2-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/soc/fsl/qman.h