]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commit
kfifo: fix ternary sign extension bugs
authorDan Carpenter <dan.carpenter@oracle.com>
Fri, 30 Apr 2021 05:54:15 +0000 (22:54 -0700)
committerKelsey Skunberg <kelsey.skunberg@canonical.com>
Mon, 24 May 2021 23:46:44 +0000 (17:46 -0600)
commit3ece1b3f4581f19ded10936bcafe5a7fa1dfe451
tree6d89190e5638947d5fcec94bd8de5d055cb6d0e0
parent0a4f618856f8861a4b34bd7677fe07c80d678642
kfifo: fix ternary sign extension bugs

BugLink: https://bugs.launchpad.net/bugs/1929455
[ Upstream commit 926ee00ea24320052b46745ef4b00d91c05bd03d ]

The intent with this code was to return negative error codes but instead
it returns positives.

The problem is how type promotion works with ternary operations.  These
functions return long, "ret" is an int and "copied" is a u32.  The
negative error code is first cast to u32 so it becomes a high positive and
then cast to long where it's still a positive.

We could fix this by declaring "ret" as a ssize_t but let's just get rid
of the ternaries instead.

Link: https://lkml.kernel.org/r/YIE+/cK1tBzSuQPU@mwanda
Fixes: 5bf2b19320ec ("kfifo: add example files to the kernel sample directory")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Stefani Seibold <stefani@seibold.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
samples/kfifo/bytestream-example.c
samples/kfifo/inttype-example.c
samples/kfifo/record-example.c