Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kfifo: fix kfifo_alloc() to return a signed int value

Add a new __kfifo_int_must_check_helper() helper function, which is needed
for kfifo_alloc() to return the right signed integer value.

The origin __kfifo_must_check_helper() helper was renamed into
__kfifo_uint_must_check_helper() to show the sign which is expected and
returned.

(And revert the temporary disabling of __kfifo_must_check_helper())

Signed-off-by: Stefani Seibold <stefani@seibold.net>
Acked-by: Randy Dunlap <randy.dunlap@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Stefani Seibold and committed by
Linus Torvalds
144ecf31 12aa4c64

+21 -12
+21 -12
include/linux/kfifo.h
··· 171 171 } 172 172 173 173 174 - /* __kfifo_must_check_helper() is temporarily disabled because it was faulty */ 175 - #define __kfifo_must_check_helper(x) (x) 174 + static inline unsigned int __must_check 175 + __kfifo_uint_must_check_helper(unsigned int val) 176 + { 177 + return val; 178 + } 179 + 180 + static inline int __must_check 181 + __kfifo_int_must_check_helper(int val) 182 + { 183 + return val; 184 + } 176 185 177 186 /** 178 187 * kfifo_initialized - Check if the fifo is initialized ··· 273 264 * @fifo: address of the fifo to be used 274 265 */ 275 266 #define kfifo_avail(fifo) \ 276 - __kfifo_must_check_helper( \ 267 + __kfifo_uint_must_check_helper( \ 277 268 ({ \ 278 269 typeof((fifo) + 1) __tmpq = (fifo); \ 279 270 const size_t __recsize = sizeof(*__tmpq->rectype); \ ··· 306 297 * This function returns the size of the next fifo record in number of bytes. 307 298 */ 308 299 #define kfifo_peek_len(fifo) \ 309 - __kfifo_must_check_helper( \ 300 + __kfifo_uint_must_check_helper( \ 310 301 ({ \ 311 302 typeof((fifo) + 1) __tmp = (fifo); \ 312 303 const size_t __recsize = sizeof(*__tmp->rectype); \ ··· 329 320 * Return 0 if no error, otherwise an error code. 330 321 */ 331 322 #define kfifo_alloc(fifo, size, gfp_mask) \ 332 - __kfifo_must_check_helper( \ 323 + __kfifo_int_must_check_helper( \ 333 324 ({ \ 334 325 typeof((fifo) + 1) __tmp = (fifo); \ 335 326 struct __kfifo *__kfifo = &__tmp->kfifo; \ ··· 425 416 * writer, you don't need extra locking to use these macro. 426 417 */ 427 418 #define kfifo_get(fifo, val) \ 428 - __kfifo_must_check_helper( \ 419 + __kfifo_uint_must_check_helper( \ 429 420 ({ \ 430 421 typeof((fifo) + 1) __tmp = (fifo); \ 431 422 typeof((val) + 1) __val = (val); \ ··· 466 457 * writer, you don't need extra locking to use these macro. 467 458 */ 468 459 #define kfifo_peek(fifo, val) \ 469 - __kfifo_must_check_helper( \ 460 + __kfifo_uint_must_check_helper( \ 470 461 ({ \ 471 462 typeof((fifo) + 1) __tmp = (fifo); \ 472 463 typeof((val) + 1) __val = (val); \ ··· 558 549 * writer, you don't need extra locking to use these macro. 559 550 */ 560 551 #define kfifo_out(fifo, buf, n) \ 561 - __kfifo_must_check_helper( \ 552 + __kfifo_uint_must_check_helper( \ 562 553 ({ \ 563 554 typeof((fifo) + 1) __tmp = (fifo); \ 564 555 typeof((buf) + 1) __buf = (buf); \ ··· 586 577 * copied. 587 578 */ 588 579 #define kfifo_out_spinlocked(fifo, buf, n, lock) \ 589 - __kfifo_must_check_helper( \ 580 + __kfifo_uint_must_check_helper( \ 590 581 ({ \ 591 582 unsigned long __flags; \ 592 583 unsigned int __ret; \ ··· 615 606 * writer, you don't need extra locking to use these macro. 616 607 */ 617 608 #define kfifo_from_user(fifo, from, len, copied) \ 618 - __kfifo_must_check_helper( \ 609 + __kfifo_uint_must_check_helper( \ 619 610 ({ \ 620 611 typeof((fifo) + 1) __tmp = (fifo); \ 621 612 const void __user *__from = (from); \ ··· 643 634 * writer, you don't need extra locking to use these macro. 644 635 */ 645 636 #define kfifo_to_user(fifo, to, len, copied) \ 646 - __kfifo_must_check_helper( \ 637 + __kfifo_uint_must_check_helper( \ 647 638 ({ \ 648 639 typeof((fifo) + 1) __tmp = (fifo); \ 649 640 void __user *__to = (to); \ ··· 770 761 * writer, you don't need extra locking to use these macro. 771 762 */ 772 763 #define kfifo_out_peek(fifo, buf, n) \ 773 - __kfifo_must_check_helper( \ 764 + __kfifo_uint_must_check_helper( \ 774 765 ({ \ 775 766 typeof((fifo) + 1) __tmp = (fifo); \ 776 767 typeof((buf) + 1) __buf = (buf); \