diff options
| author | Jakub Kicinski <kuba@kernel.org> | 2023-02-09 12:05:25 -0800 |
|---|---|---|
| committer | Jakub Kicinski <kuba@kernel.org> | 2023-02-09 12:25:40 -0800 |
| commit | 8697a258ae24703267d2a37d91ab757c91ef027e (patch) | |
| tree | 7a1798898ac64c72e6cf77d2320f036c963a16c1 /lib/dec_and_lock.c | |
| parent | 0b34d68049b09821499b93d50b5a9d7d2ca449f6 (diff) | |
| parent | 35674e787518768626d3a0ffce1c13a7eeed922d (diff) | |
| download | linux-8697a258ae24703267d2a37d91ab757c91ef027e.tar.gz linux-8697a258ae24703267d2a37d91ab757c91ef027e.tar.bz2 linux-8697a258ae24703267d2a37d91ab757c91ef027e.zip | |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net
net/devlink/leftover.c / net/core/devlink.c:
565b4824c39f ("devlink: change port event netdev notifier from per-net to global")
f05bd8ebeb69 ("devlink: move code to a dedicated directory")
687125b5799c ("devlink: split out core code")
https://lore.kernel.org/all/20230208094657.379f2b1a@canb.auug.org.au/
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'lib/dec_and_lock.c')
| -rw-r--r-- | lib/dec_and_lock.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/dec_and_lock.c b/lib/dec_and_lock.c index 9555b68bb774..1dcca8f2e194 100644 --- a/lib/dec_and_lock.c +++ b/lib/dec_and_lock.c @@ -49,3 +49,34 @@ int _atomic_dec_and_lock_irqsave(atomic_t *atomic, spinlock_t *lock, return 0; } EXPORT_SYMBOL(_atomic_dec_and_lock_irqsave); + +int _atomic_dec_and_raw_lock(atomic_t *atomic, raw_spinlock_t *lock) +{ + /* Subtract 1 from counter unless that drops it to 0 (ie. it was 1) */ + if (atomic_add_unless(atomic, -1, 1)) + return 0; + + /* Otherwise do it the slow way */ + raw_spin_lock(lock); + if (atomic_dec_and_test(atomic)) + return 1; + raw_spin_unlock(lock); + return 0; +} +EXPORT_SYMBOL(_atomic_dec_and_raw_lock); + +int _atomic_dec_and_raw_lock_irqsave(atomic_t *atomic, raw_spinlock_t *lock, + unsigned long *flags) +{ + /* Subtract 1 from counter unless that drops it to 0 (ie. it was 1) */ + if (atomic_add_unless(atomic, -1, 1)) + return 0; + + /* Otherwise do it the slow way */ + raw_spin_lock_irqsave(lock, *flags); + if (atomic_dec_and_test(atomic)) + return 1; + raw_spin_unlock_irqrestore(lock, *flags); + return 0; +} +EXPORT_SYMBOL(_atomic_dec_and_raw_lock_irqsave); |
