linux/samples/kfifo
Dan Carpenter 926ee00ea2 kfifo: fix ternary sign extension bugs
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: 5bf2b19320 ("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>
2021-04-30 11:20:35 -07:00
..
bytestream-example.c kfifo: fix ternary sign extension bugs 2021-04-30 11:20:35 -07:00
dma-example.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 465 2019-06-19 17:09:10 +02:00
inttype-example.c kfifo: fix ternary sign extension bugs 2021-04-30 11:20:35 -07:00
Makefile treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
record-example.c kfifo: fix ternary sign extension bugs 2021-04-30 11:20:35 -07:00