]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
spi: Fix erroneous sgs value with min_t()
authorBiju Das <biju.das.jz@bp.renesas.com>
Wed, 16 Mar 2022 17:53:17 +0000 (17:53 +0000)
committerStefan Bader <stefan.bader@canonical.com>
Wed, 27 Apr 2022 09:56:21 +0000 (11:56 +0200)
commit937df4cb272311bb2c9b7ee027e7fbdb928d231b
tree005ab3d55be05e0d33ef60101e15703cb698e4da
parent5aba15c65117127bf1e2195aa88d0e9deb92e302
spi: Fix erroneous sgs value with min_t()

BugLink: https://bugs.launchpad.net/bugs/1969110
[ Upstream commit ebc4cb43ea5ada3db46c80156fca58a54b9bbca8 ]

While computing sgs in spi_map_buf(), the data type
used in min_t() for max_seg_size is 'unsigned int' where
as that of ctlr->max_dma_len is 'size_t'.

min_t(unsigned int,x,y) gives wrong results if one of x/y is
'size_t'

Consider the below examples on a 64-bit machine (ie size_t is
64-bits, and unsigned int is 32-bit).
    case 1) min_t(unsigned int, 5, 0x100000001);
    case 2) min_t(size_t, 5, 0x100000001);

Case 1 returns '1', where as case 2 returns '5'. As you can see
the result from case 1 is wrong.

This patch fixes the above issue by using the data type of the
parameters that are used in min_t with maximum data length.

Fixes: commit 1a4e53d2fc4f68aa ("spi: Fix invalid sgs value")
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Suggested-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Link: https://lore.kernel.org/r/20220316175317.465-1-biju.das.jz@bp.renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit 8745973cdfc6a833d6d405d63760c9b92d78ff9e)
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
drivers/spi/spi.c