diff options
Diffstat (limited to 'include/linux/kfifo.h')
| -rw-r--r-- | include/linux/kfifo.h | 88 |
1 files changed, 48 insertions, 40 deletions
diff --git a/include/linux/kfifo.h b/include/linux/kfifo.h index 311f8753d713..10308c6a3d1c 100644 --- a/include/linux/kfifo.h +++ b/include/linux/kfifo.h | |||
| @@ -172,7 +172,13 @@ struct kfifo_rec_ptr_2 __STRUCT_KFIFO_PTR(unsigned char, 2, void); | |||
| 172 | 172 | ||
| 173 | 173 | ||
| 174 | static inline unsigned int __must_check | 174 | static inline unsigned int __must_check |
| 175 | __kfifo_must_check_helper(unsigned int val) | 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) | ||
| 176 | { | 182 | { |
| 177 | return val; | 183 | return val; |
| 178 | } | 184 | } |
| @@ -214,7 +220,7 @@ __kfifo_must_check_helper(unsigned int val) | |||
| 214 | */ | 220 | */ |
| 215 | #define kfifo_reset(fifo) \ | 221 | #define kfifo_reset(fifo) \ |
| 216 | (void)({ \ | 222 | (void)({ \ |
| 217 | typeof(fifo + 1) __tmp = (fifo); \ | 223 | typeof((fifo) + 1) __tmp = (fifo); \ |
| 218 | __tmp->kfifo.in = __tmp->kfifo.out = 0; \ | 224 | __tmp->kfifo.in = __tmp->kfifo.out = 0; \ |
| 219 | }) | 225 | }) |
| 220 | 226 | ||
| @@ -228,7 +234,7 @@ __kfifo_must_check_helper(unsigned int val) | |||
| 228 | */ | 234 | */ |
| 229 | #define kfifo_reset_out(fifo) \ | 235 | #define kfifo_reset_out(fifo) \ |
| 230 | (void)({ \ | 236 | (void)({ \ |
| 231 | typeof(fifo + 1) __tmp = (fifo); \ | 237 | typeof((fifo) + 1) __tmp = (fifo); \ |
| 232 | __tmp->kfifo.out = __tmp->kfifo.in; \ | 238 | __tmp->kfifo.out = __tmp->kfifo.in; \ |
| 233 | }) | 239 | }) |
| 234 | 240 | ||
| @@ -238,7 +244,7 @@ __kfifo_must_check_helper(unsigned int val) | |||
| 238 | */ | 244 | */ |
| 239 | #define kfifo_len(fifo) \ | 245 | #define kfifo_len(fifo) \ |
| 240 | ({ \ | 246 | ({ \ |
| 241 | typeof(fifo + 1) __tmpl = (fifo); \ | 247 | typeof((fifo) + 1) __tmpl = (fifo); \ |
| 242 | __tmpl->kfifo.in - __tmpl->kfifo.out; \ | 248 | __tmpl->kfifo.in - __tmpl->kfifo.out; \ |
| 243 | }) | 249 | }) |
| 244 | 250 | ||
| @@ -248,7 +254,7 @@ __kfifo_must_check_helper(unsigned int val) | |||
| 248 | */ | 254 | */ |
| 249 | #define kfifo_is_empty(fifo) \ | 255 | #define kfifo_is_empty(fifo) \ |
| 250 | ({ \ | 256 | ({ \ |
| 251 | typeof(fifo + 1) __tmpq = (fifo); \ | 257 | typeof((fifo) + 1) __tmpq = (fifo); \ |
| 252 | __tmpq->kfifo.in == __tmpq->kfifo.out; \ | 258 | __tmpq->kfifo.in == __tmpq->kfifo.out; \ |
| 253 | }) | 259 | }) |
| 254 | 260 | ||
| @@ -258,7 +264,7 @@ __kfifo_must_check_helper(unsigned int val) | |||
| 258 | */ | 264 | */ |
| 259 | #define kfifo_is_full(fifo) \ | 265 | #define kfifo_is_full(fifo) \ |
| 260 | ({ \ | 266 | ({ \ |
| 261 | typeof(fifo + 1) __tmpq = (fifo); \ | 267 | typeof((fifo) + 1) __tmpq = (fifo); \ |
| 262 | kfifo_len(__tmpq) > __tmpq->kfifo.mask; \ | 268 | kfifo_len(__tmpq) > __tmpq->kfifo.mask; \ |
| 263 | }) | 269 | }) |
| 264 | 270 | ||
| @@ -267,9 +273,9 @@ __kfifo_must_check_helper(unsigned int val) | |||
| 267 | * @fifo: address of the fifo to be used | 273 | * @fifo: address of the fifo to be used |
| 268 | */ | 274 | */ |
| 269 | #define kfifo_avail(fifo) \ | 275 | #define kfifo_avail(fifo) \ |
| 270 | __kfifo_must_check_helper( \ | 276 | __kfifo_uint_must_check_helper( \ |
| 271 | ({ \ | 277 | ({ \ |
| 272 | typeof(fifo + 1) __tmpq = (fifo); \ | 278 | typeof((fifo) + 1) __tmpq = (fifo); \ |
| 273 | const size_t __recsize = sizeof(*__tmpq->rectype); \ | 279 | const size_t __recsize = sizeof(*__tmpq->rectype); \ |
| 274 | unsigned int __avail = kfifo_size(__tmpq) - kfifo_len(__tmpq); \ | 280 | unsigned int __avail = kfifo_size(__tmpq) - kfifo_len(__tmpq); \ |
| 275 | (__recsize) ? ((__avail <= __recsize) ? 0 : \ | 281 | (__recsize) ? ((__avail <= __recsize) ? 0 : \ |
| @@ -284,7 +290,7 @@ __kfifo_must_check_helper( \ | |||
| 284 | */ | 290 | */ |
| 285 | #define kfifo_skip(fifo) \ | 291 | #define kfifo_skip(fifo) \ |
| 286 | (void)({ \ | 292 | (void)({ \ |
| 287 | typeof(fifo + 1) __tmp = (fifo); \ | 293 | typeof((fifo) + 1) __tmp = (fifo); \ |
| 288 | const size_t __recsize = sizeof(*__tmp->rectype); \ | 294 | const size_t __recsize = sizeof(*__tmp->rectype); \ |
| 289 | struct __kfifo *__kfifo = &__tmp->kfifo; \ | 295 | struct __kfifo *__kfifo = &__tmp->kfifo; \ |
| 290 | if (__recsize) \ | 296 | if (__recsize) \ |
| @@ -300,9 +306,9 @@ __kfifo_must_check_helper( \ | |||
| 300 | * This function returns the size of the next fifo record in number of bytes. | 306 | * This function returns the size of the next fifo record in number of bytes. |
| 301 | */ | 307 | */ |
| 302 | #define kfifo_peek_len(fifo) \ | 308 | #define kfifo_peek_len(fifo) \ |
| 303 | __kfifo_must_check_helper( \ | 309 | __kfifo_uint_must_check_helper( \ |
| 304 | ({ \ | 310 | ({ \ |
| 305 | typeof(fifo + 1) __tmp = (fifo); \ | 311 | typeof((fifo) + 1) __tmp = (fifo); \ |
| 306 | const size_t __recsize = sizeof(*__tmp->rectype); \ | 312 | const size_t __recsize = sizeof(*__tmp->rectype); \ |
| 307 | struct __kfifo *__kfifo = &__tmp->kfifo; \ | 313 | struct __kfifo *__kfifo = &__tmp->kfifo; \ |
| 308 | (!__recsize) ? kfifo_len(__tmp) * sizeof(*__tmp->type) : \ | 314 | (!__recsize) ? kfifo_len(__tmp) * sizeof(*__tmp->type) : \ |
| @@ -323,9 +329,9 @@ __kfifo_must_check_helper( \ | |||
| 323 | * Return 0 if no error, otherwise an error code. | 329 | * Return 0 if no error, otherwise an error code. |
| 324 | */ | 330 | */ |
| 325 | #define kfifo_alloc(fifo, size, gfp_mask) \ | 331 | #define kfifo_alloc(fifo, size, gfp_mask) \ |
| 326 | __kfifo_must_check_helper( \ | 332 | __kfifo_int_must_check_helper( \ |
| 327 | ({ \ | 333 | ({ \ |
| 328 | typeof(fifo + 1) __tmp = (fifo); \ | 334 | typeof((fifo) + 1) __tmp = (fifo); \ |
| 329 | struct __kfifo *__kfifo = &__tmp->kfifo; \ | 335 | struct __kfifo *__kfifo = &__tmp->kfifo; \ |
| 330 | __is_kfifo_ptr(__tmp) ? \ | 336 | __is_kfifo_ptr(__tmp) ? \ |
| 331 | __kfifo_alloc(__kfifo, size, sizeof(*__tmp->type), gfp_mask) : \ | 337 | __kfifo_alloc(__kfifo, size, sizeof(*__tmp->type), gfp_mask) : \ |
| @@ -339,7 +345,7 @@ __kfifo_must_check_helper( \ | |||
| 339 | */ | 345 | */ |
| 340 | #define kfifo_free(fifo) \ | 346 | #define kfifo_free(fifo) \ |
| 341 | ({ \ | 347 | ({ \ |
| 342 | typeof(fifo + 1) __tmp = (fifo); \ | 348 | typeof((fifo) + 1) __tmp = (fifo); \ |
| 343 | struct __kfifo *__kfifo = &__tmp->kfifo; \ | 349 | struct __kfifo *__kfifo = &__tmp->kfifo; \ |
| 344 | if (__is_kfifo_ptr(__tmp)) \ | 350 | if (__is_kfifo_ptr(__tmp)) \ |
| 345 | __kfifo_free(__kfifo); \ | 351 | __kfifo_free(__kfifo); \ |
| @@ -358,7 +364,7 @@ __kfifo_must_check_helper( \ | |||
| 358 | */ | 364 | */ |
| 359 | #define kfifo_init(fifo, buffer, size) \ | 365 | #define kfifo_init(fifo, buffer, size) \ |
| 360 | ({ \ | 366 | ({ \ |
| 361 | typeof(fifo + 1) __tmp = (fifo); \ | 367 | typeof((fifo) + 1) __tmp = (fifo); \ |
| 362 | struct __kfifo *__kfifo = &__tmp->kfifo; \ | 368 | struct __kfifo *__kfifo = &__tmp->kfifo; \ |
| 363 | __is_kfifo_ptr(__tmp) ? \ | 369 | __is_kfifo_ptr(__tmp) ? \ |
| 364 | __kfifo_init(__kfifo, buffer, size, sizeof(*__tmp->type)) : \ | 370 | __kfifo_init(__kfifo, buffer, size, sizeof(*__tmp->type)) : \ |
| @@ -379,8 +385,8 @@ __kfifo_must_check_helper( \ | |||
| 379 | */ | 385 | */ |
| 380 | #define kfifo_put(fifo, val) \ | 386 | #define kfifo_put(fifo, val) \ |
| 381 | ({ \ | 387 | ({ \ |
| 382 | typeof(fifo + 1) __tmp = (fifo); \ | 388 | typeof((fifo) + 1) __tmp = (fifo); \ |
| 383 | typeof(val + 1) __val = (val); \ | 389 | typeof((val) + 1) __val = (val); \ |
| 384 | unsigned int __ret; \ | 390 | unsigned int __ret; \ |
| 385 | const size_t __recsize = sizeof(*__tmp->rectype); \ | 391 | const size_t __recsize = sizeof(*__tmp->rectype); \ |
| 386 | struct __kfifo *__kfifo = &__tmp->kfifo; \ | 392 | struct __kfifo *__kfifo = &__tmp->kfifo; \ |
| @@ -419,10 +425,10 @@ __kfifo_must_check_helper( \ | |||
| 419 | * writer, you don't need extra locking to use these macro. | 425 | * writer, you don't need extra locking to use these macro. |
| 420 | */ | 426 | */ |
| 421 | #define kfifo_get(fifo, val) \ | 427 | #define kfifo_get(fifo, val) \ |
| 422 | __kfifo_must_check_helper( \ | 428 | __kfifo_uint_must_check_helper( \ |
| 423 | ({ \ | 429 | ({ \ |
| 424 | typeof(fifo + 1) __tmp = (fifo); \ | 430 | typeof((fifo) + 1) __tmp = (fifo); \ |
| 425 | typeof(val + 1) __val = (val); \ | 431 | typeof((val) + 1) __val = (val); \ |
| 426 | unsigned int __ret; \ | 432 | unsigned int __ret; \ |
| 427 | const size_t __recsize = sizeof(*__tmp->rectype); \ | 433 | const size_t __recsize = sizeof(*__tmp->rectype); \ |
| 428 | struct __kfifo *__kfifo = &__tmp->kfifo; \ | 434 | struct __kfifo *__kfifo = &__tmp->kfifo; \ |
| @@ -460,10 +466,10 @@ __kfifo_must_check_helper( \ | |||
| 460 | * writer, you don't need extra locking to use these macro. | 466 | * writer, you don't need extra locking to use these macro. |
| 461 | */ | 467 | */ |
| 462 | #define kfifo_peek(fifo, val) \ | 468 | #define kfifo_peek(fifo, val) \ |
| 463 | __kfifo_must_check_helper( \ | 469 | __kfifo_uint_must_check_helper( \ |
| 464 | ({ \ | 470 | ({ \ |
| 465 | typeof(fifo + 1) __tmp = (fifo); \ | 471 | typeof((fifo) + 1) __tmp = (fifo); \ |
| 466 | typeof(val + 1) __val = (val); \ | 472 | typeof((val) + 1) __val = (val); \ |
| 467 | unsigned int __ret; \ | 473 | unsigned int __ret; \ |
| 468 | const size_t __recsize = sizeof(*__tmp->rectype); \ | 474 | const size_t __recsize = sizeof(*__tmp->rectype); \ |
| 469 | struct __kfifo *__kfifo = &__tmp->kfifo; \ | 475 | struct __kfifo *__kfifo = &__tmp->kfifo; \ |
| @@ -501,8 +507,8 @@ __kfifo_must_check_helper( \ | |||
| 501 | */ | 507 | */ |
| 502 | #define kfifo_in(fifo, buf, n) \ | 508 | #define kfifo_in(fifo, buf, n) \ |
| 503 | ({ \ | 509 | ({ \ |
| 504 | typeof(fifo + 1) __tmp = (fifo); \ | 510 | typeof((fifo) + 1) __tmp = (fifo); \ |
| 505 | typeof(buf + 1) __buf = (buf); \ | 511 | typeof((buf) + 1) __buf = (buf); \ |
| 506 | unsigned long __n = (n); \ | 512 | unsigned long __n = (n); \ |
| 507 | const size_t __recsize = sizeof(*__tmp->rectype); \ | 513 | const size_t __recsize = sizeof(*__tmp->rectype); \ |
| 508 | struct __kfifo *__kfifo = &__tmp->kfifo; \ | 514 | struct __kfifo *__kfifo = &__tmp->kfifo; \ |
| @@ -552,10 +558,10 @@ __kfifo_must_check_helper( \ | |||
| 552 | * writer, you don't need extra locking to use these macro. | 558 | * writer, you don't need extra locking to use these macro. |
| 553 | */ | 559 | */ |
| 554 | #define kfifo_out(fifo, buf, n) \ | 560 | #define kfifo_out(fifo, buf, n) \ |
| 555 | __kfifo_must_check_helper( \ | 561 | __kfifo_uint_must_check_helper( \ |
| 556 | ({ \ | 562 | ({ \ |
| 557 | typeof(fifo + 1) __tmp = (fifo); \ | 563 | typeof((fifo) + 1) __tmp = (fifo); \ |
| 558 | typeof(buf + 1) __buf = (buf); \ | 564 | typeof((buf) + 1) __buf = (buf); \ |
| 559 | unsigned long __n = (n); \ | 565 | unsigned long __n = (n); \ |
| 560 | const size_t __recsize = sizeof(*__tmp->rectype); \ | 566 | const size_t __recsize = sizeof(*__tmp->rectype); \ |
| 561 | struct __kfifo *__kfifo = &__tmp->kfifo; \ | 567 | struct __kfifo *__kfifo = &__tmp->kfifo; \ |
| @@ -580,7 +586,7 @@ __kfifo_must_check_helper( \ | |||
| 580 | * copied. | 586 | * copied. |
| 581 | */ | 587 | */ |
| 582 | #define kfifo_out_spinlocked(fifo, buf, n, lock) \ | 588 | #define kfifo_out_spinlocked(fifo, buf, n, lock) \ |
| 583 | __kfifo_must_check_helper( \ | 589 | __kfifo_uint_must_check_helper( \ |
| 584 | ({ \ | 590 | ({ \ |
| 585 | unsigned long __flags; \ | 591 | unsigned long __flags; \ |
| 586 | unsigned int __ret; \ | 592 | unsigned int __ret; \ |
| @@ -609,9 +615,9 @@ __kfifo_must_check_helper( \ | |||
| 609 | * writer, you don't need extra locking to use these macro. | 615 | * writer, you don't need extra locking to use these macro. |
| 610 | */ | 616 | */ |
| 611 | #define kfifo_from_user(fifo, from, len, copied) \ | 617 | #define kfifo_from_user(fifo, from, len, copied) \ |
| 612 | __kfifo_must_check_helper( \ | 618 | __kfifo_uint_must_check_helper( \ |
| 613 | ({ \ | 619 | ({ \ |
| 614 | typeof(fifo + 1) __tmp = (fifo); \ | 620 | typeof((fifo) + 1) __tmp = (fifo); \ |
| 615 | const void __user *__from = (from); \ | 621 | const void __user *__from = (from); \ |
| 616 | unsigned int __len = (len); \ | 622 | unsigned int __len = (len); \ |
| 617 | unsigned int *__copied = (copied); \ | 623 | unsigned int *__copied = (copied); \ |
| @@ -637,9 +643,9 @@ __kfifo_must_check_helper( \ | |||
| 637 | * writer, you don't need extra locking to use these macro. | 643 | * writer, you don't need extra locking to use these macro. |
| 638 | */ | 644 | */ |
| 639 | #define kfifo_to_user(fifo, to, len, copied) \ | 645 | #define kfifo_to_user(fifo, to, len, copied) \ |
| 640 | __kfifo_must_check_helper( \ | 646 | __kfifo_uint_must_check_helper( \ |
| 641 | ({ \ | 647 | ({ \ |
| 642 | typeof(fifo + 1) __tmp = (fifo); \ | 648 | typeof((fifo) + 1) __tmp = (fifo); \ |
| 643 | void __user *__to = (to); \ | 649 | void __user *__to = (to); \ |
| 644 | unsigned int __len = (len); \ | 650 | unsigned int __len = (len); \ |
| 645 | unsigned int *__copied = (copied); \ | 651 | unsigned int *__copied = (copied); \ |
| @@ -666,7 +672,7 @@ __kfifo_must_check_helper( \ | |||
| 666 | */ | 672 | */ |
| 667 | #define kfifo_dma_in_prepare(fifo, sgl, nents, len) \ | 673 | #define kfifo_dma_in_prepare(fifo, sgl, nents, len) \ |
| 668 | ({ \ | 674 | ({ \ |
| 669 | typeof(fifo + 1) __tmp = (fifo); \ | 675 | typeof((fifo) + 1) __tmp = (fifo); \ |
| 670 | struct scatterlist *__sgl = (sgl); \ | 676 | struct scatterlist *__sgl = (sgl); \ |
| 671 | int __nents = (nents); \ | 677 | int __nents = (nents); \ |
| 672 | unsigned int __len = (len); \ | 678 | unsigned int __len = (len); \ |
| @@ -690,7 +696,7 @@ __kfifo_must_check_helper( \ | |||
| 690 | */ | 696 | */ |
| 691 | #define kfifo_dma_in_finish(fifo, len) \ | 697 | #define kfifo_dma_in_finish(fifo, len) \ |
| 692 | (void)({ \ | 698 | (void)({ \ |
| 693 | typeof(fifo + 1) __tmp = (fifo); \ | 699 | typeof((fifo) + 1) __tmp = (fifo); \ |
| 694 | unsigned int __len = (len); \ | 700 | unsigned int __len = (len); \ |
| 695 | const size_t __recsize = sizeof(*__tmp->rectype); \ | 701 | const size_t __recsize = sizeof(*__tmp->rectype); \ |
| 696 | struct __kfifo *__kfifo = &__tmp->kfifo; \ | 702 | struct __kfifo *__kfifo = &__tmp->kfifo; \ |
| @@ -717,7 +723,7 @@ __kfifo_must_check_helper( \ | |||
| 717 | */ | 723 | */ |
| 718 | #define kfifo_dma_out_prepare(fifo, sgl, nents, len) \ | 724 | #define kfifo_dma_out_prepare(fifo, sgl, nents, len) \ |
| 719 | ({ \ | 725 | ({ \ |
| 720 | typeof(fifo + 1) __tmp = (fifo); \ | 726 | typeof((fifo) + 1) __tmp = (fifo); \ |
| 721 | struct scatterlist *__sgl = (sgl); \ | 727 | struct scatterlist *__sgl = (sgl); \ |
| 722 | int __nents = (nents); \ | 728 | int __nents = (nents); \ |
| 723 | unsigned int __len = (len); \ | 729 | unsigned int __len = (len); \ |
| @@ -741,7 +747,7 @@ __kfifo_must_check_helper( \ | |||
| 741 | */ | 747 | */ |
| 742 | #define kfifo_dma_out_finish(fifo, len) \ | 748 | #define kfifo_dma_out_finish(fifo, len) \ |
| 743 | (void)({ \ | 749 | (void)({ \ |
| 744 | typeof(fifo + 1) __tmp = (fifo); \ | 750 | typeof((fifo) + 1) __tmp = (fifo); \ |
| 745 | unsigned int __len = (len); \ | 751 | unsigned int __len = (len); \ |
| 746 | const size_t __recsize = sizeof(*__tmp->rectype); \ | 752 | const size_t __recsize = sizeof(*__tmp->rectype); \ |
| 747 | struct __kfifo *__kfifo = &__tmp->kfifo; \ | 753 | struct __kfifo *__kfifo = &__tmp->kfifo; \ |
| @@ -764,10 +770,10 @@ __kfifo_must_check_helper( \ | |||
| 764 | * writer, you don't need extra locking to use these macro. | 770 | * writer, you don't need extra locking to use these macro. |
| 765 | */ | 771 | */ |
| 766 | #define kfifo_out_peek(fifo, buf, n) \ | 772 | #define kfifo_out_peek(fifo, buf, n) \ |
| 767 | __kfifo_must_check_helper( \ | 773 | __kfifo_uint_must_check_helper( \ |
| 768 | ({ \ | 774 | ({ \ |
| 769 | typeof(fifo + 1) __tmp = (fifo); \ | 775 | typeof((fifo) + 1) __tmp = (fifo); \ |
| 770 | typeof(buf + 1) __buf = (buf); \ | 776 | typeof((buf) + 1) __buf = (buf); \ |
| 771 | unsigned long __n = (n); \ | 777 | unsigned long __n = (n); \ |
| 772 | const size_t __recsize = sizeof(*__tmp->rectype); \ | 778 | const size_t __recsize = sizeof(*__tmp->rectype); \ |
| 773 | struct __kfifo *__kfifo = &__tmp->kfifo; \ | 779 | struct __kfifo *__kfifo = &__tmp->kfifo; \ |
| @@ -836,6 +842,8 @@ extern void __kfifo_dma_out_finish_r(struct __kfifo *fifo, size_t recsize); | |||
| 836 | 842 | ||
| 837 | extern unsigned int __kfifo_len_r(struct __kfifo *fifo, size_t recsize); | 843 | extern unsigned int __kfifo_len_r(struct __kfifo *fifo, size_t recsize); |
| 838 | 844 | ||
| 845 | extern void __kfifo_skip_r(struct __kfifo *fifo, size_t recsize); | ||
| 846 | |||
| 839 | extern unsigned int __kfifo_out_peek_r(struct __kfifo *fifo, | 847 | extern unsigned int __kfifo_out_peek_r(struct __kfifo *fifo, |
| 840 | void *buf, unsigned int len, size_t recsize); | 848 | void *buf, unsigned int len, size_t recsize); |
| 841 | 849 | ||
