| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * A generic kernel FIFO implementation |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2013 Stefani Seibold <stefani@seibold.net> |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 8 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | | - * (at your option) any later version. |
|---|
| 10 | | - * |
|---|
| 11 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 12 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | | - * GNU General Public License for more details. |
|---|
| 15 | | - * |
|---|
| 16 | | - * You should have received a copy of the GNU General Public License |
|---|
| 17 | | - * along with this program; if not, write to the Free Software |
|---|
| 18 | | - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 19 | | - * |
|---|
| 20 | 6 | */ |
|---|
| 21 | 7 | |
|---|
| 22 | 8 | #ifndef _LINUX_KFIFO_H |
|---|
| .. | .. |
|---|
| 258 | 244 | ({ \ |
|---|
| 259 | 245 | typeof((fifo) + 1) __tmpq = (fifo); \ |
|---|
| 260 | 246 | __tmpq->kfifo.in == __tmpq->kfifo.out; \ |
|---|
| 247 | +}) |
|---|
| 248 | + |
|---|
| 249 | +/** |
|---|
| 250 | + * kfifo_is_empty_spinlocked - returns true if the fifo is empty using |
|---|
| 251 | + * a spinlock for locking |
|---|
| 252 | + * @fifo: address of the fifo to be used |
|---|
| 253 | + * @lock: spinlock to be used for locking |
|---|
| 254 | + */ |
|---|
| 255 | +#define kfifo_is_empty_spinlocked(fifo, lock) \ |
|---|
| 256 | +({ \ |
|---|
| 257 | + unsigned long __flags; \ |
|---|
| 258 | + bool __ret; \ |
|---|
| 259 | + spin_lock_irqsave(lock, __flags); \ |
|---|
| 260 | + __ret = kfifo_is_empty(fifo); \ |
|---|
| 261 | + spin_unlock_irqrestore(lock, __flags); \ |
|---|
| 262 | + __ret; \ |
|---|
| 263 | +}) |
|---|
| 264 | + |
|---|
| 265 | +/** |
|---|
| 266 | + * kfifo_is_empty_spinlocked_noirqsave - returns true if the fifo is empty |
|---|
| 267 | + * using a spinlock for locking, doesn't disable interrupts |
|---|
| 268 | + * @fifo: address of the fifo to be used |
|---|
| 269 | + * @lock: spinlock to be used for locking |
|---|
| 270 | + */ |
|---|
| 271 | +#define kfifo_is_empty_spinlocked_noirqsave(fifo, lock) \ |
|---|
| 272 | +({ \ |
|---|
| 273 | + bool __ret; \ |
|---|
| 274 | + spin_lock(lock); \ |
|---|
| 275 | + __ret = kfifo_is_empty(fifo); \ |
|---|
| 276 | + spin_unlock(lock); \ |
|---|
| 277 | + __ret; \ |
|---|
| 261 | 278 | }) |
|---|
| 262 | 279 | |
|---|
| 263 | 280 | /** |
|---|
| .. | .. |
|---|
| 531 | 548 | __ret; \ |
|---|
| 532 | 549 | }) |
|---|
| 533 | 550 | |
|---|
| 551 | +/** |
|---|
| 552 | + * kfifo_in_spinlocked_noirqsave - put data into fifo using a spinlock for |
|---|
| 553 | + * locking, don't disable interrupts |
|---|
| 554 | + * @fifo: address of the fifo to be used |
|---|
| 555 | + * @buf: the data to be added |
|---|
| 556 | + * @n: number of elements to be added |
|---|
| 557 | + * @lock: pointer to the spinlock to use for locking |
|---|
| 558 | + * |
|---|
| 559 | + * This is a variant of kfifo_in_spinlocked() but uses spin_lock/unlock() |
|---|
| 560 | + * for locking and doesn't disable interrupts. |
|---|
| 561 | + */ |
|---|
| 562 | +#define kfifo_in_spinlocked_noirqsave(fifo, buf, n, lock) \ |
|---|
| 563 | +({ \ |
|---|
| 564 | + unsigned int __ret; \ |
|---|
| 565 | + spin_lock(lock); \ |
|---|
| 566 | + __ret = kfifo_in(fifo, buf, n); \ |
|---|
| 567 | + spin_unlock(lock); \ |
|---|
| 568 | + __ret; \ |
|---|
| 569 | +}) |
|---|
| 570 | + |
|---|
| 534 | 571 | /* alias for kfifo_in_spinlocked, will be removed in a future release */ |
|---|
| 535 | 572 | #define kfifo_in_locked(fifo, buf, n, lock) \ |
|---|
| 536 | 573 | kfifo_in_spinlocked(fifo, buf, n, lock) |
|---|
| .. | .. |
|---|
| 583 | 620 | }) \ |
|---|
| 584 | 621 | ) |
|---|
| 585 | 622 | |
|---|
| 623 | +/** |
|---|
| 624 | + * kfifo_out_spinlocked_noirqsave - get data from the fifo using a spinlock |
|---|
| 625 | + * for locking, don't disable interrupts |
|---|
| 626 | + * @fifo: address of the fifo to be used |
|---|
| 627 | + * @buf: pointer to the storage buffer |
|---|
| 628 | + * @n: max. number of elements to get |
|---|
| 629 | + * @lock: pointer to the spinlock to use for locking |
|---|
| 630 | + * |
|---|
| 631 | + * This is a variant of kfifo_out_spinlocked() which uses spin_lock/unlock() |
|---|
| 632 | + * for locking and doesn't disable interrupts. |
|---|
| 633 | + */ |
|---|
| 634 | +#define kfifo_out_spinlocked_noirqsave(fifo, buf, n, lock) \ |
|---|
| 635 | +__kfifo_uint_must_check_helper( \ |
|---|
| 636 | +({ \ |
|---|
| 637 | + unsigned int __ret; \ |
|---|
| 638 | + spin_lock(lock); \ |
|---|
| 639 | + __ret = kfifo_out(fifo, buf, n); \ |
|---|
| 640 | + spin_unlock(lock); \ |
|---|
| 641 | + __ret; \ |
|---|
| 642 | +}) \ |
|---|
| 643 | +) |
|---|
| 644 | + |
|---|
| 586 | 645 | /* alias for kfifo_out_spinlocked, will be removed in a future release */ |
|---|
| 587 | 646 | #define kfifo_out_locked(fifo, buf, n, lock) \ |
|---|
| 588 | 647 | kfifo_out_spinlocked(fifo, buf, n, lock) |
|---|
| .. | .. |
|---|
| 629 | 688 | * writer, you don't need extra locking to use these macro. |
|---|
| 630 | 689 | */ |
|---|
| 631 | 690 | #define kfifo_to_user(fifo, to, len, copied) \ |
|---|
| 632 | | -__kfifo_uint_must_check_helper( \ |
|---|
| 691 | +__kfifo_int_must_check_helper( \ |
|---|
| 633 | 692 | ({ \ |
|---|
| 634 | 693 | typeof((fifo) + 1) __tmp = (fifo); \ |
|---|
| 635 | 694 | void __user *__to = (to); \ |
|---|