Thread (3 messages) 3 messages, 3 authors, 2021-04-23

AW: [PATCH] soc: aspeed: fix a ternary sign expansion bug

From: David Laight <hidden>
Date: 2021-04-23 14:55:38
Also in: kernel-janitors, lkml

Possibly related (same subject, not in this thread)

From: Sergey Organov
Sent: 23 April 2021 15:40

Walter Harms [off-list ref] writes:
quoted
as indepentent observer,
i would go for Dans solution:

ret = kfifo_to_user();
/* if an error occurs just return */
if (ret)
   return ret;

/* otherwise return the copied number of bytes */

return copied;

there is no need for any deeper language knowledge,
Yep, but this is not idiomatic C, so one looking at this code would
tend to convert it back to ternary, and the actual problem here is that
the type of 'copied' does not match the return type of the function.
Actually changing the type of 'ret' to ssize_t is probably
the safest change.

That works until someone tries to optimise out 'ret' by doing:

	return kfifo_to_user(...) ?: count;

Or rattle through and remove the 'pass by reference' 'count'
parameter from kfifo_to_user() in favour of returning the
value the callers want.

I need to stop looking at this code :-)

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help