diff options
| author | NeilBrown <neilb@suse.com> | 2019-04-23 22:00:08 -0400 |
|---|---|---|
| committer | J. Bruce Fields <bfields@redhat.com> | 2019-04-24 09:51:48 -0400 |
| commit | 5926459e7c897ee348c134f44da520c8bf234b05 (patch) | |
| tree | d2134d1e9433de3caeac5dcf636c32580ae26c8d | |
| parent | 0ca0c9d7edcf4996da3ebf07947c4484d1e3de16 (diff) | |
locks: move checks from locks_free_lock() to locks_release_private()
Code that allocates locks using locks_alloc_lock() will free it
using locks_free_lock(), and will benefit from the BUG_ON()
consistency checks therein.
However some code (nfsd and lockd) allocate a lock embedded in
some other data structure, and so free the lock themselves after
calling locks_release_private(). This path does not benefit from
the consistency checks.
To help catch future errors, move the BUG_ON() checks to
locks_release_private() - which locks_free_lock() already calls.
This ensures that all users for locks will find out if the lock
isn't detached properly before being free.
Signed-off-by: NeilBrown <neilb@suse.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
| -rw-r--r-- | fs/locks.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/fs/locks.c b/fs/locks.c index 71d0c6c2aac5..456a3782c6ca 100644 --- a/fs/locks.c +++ b/fs/locks.c | |||
| @@ -352,6 +352,12 @@ EXPORT_SYMBOL_GPL(locks_alloc_lock); | |||
| 352 | 352 | ||
| 353 | void locks_release_private(struct file_lock *fl) | 353 | void locks_release_private(struct file_lock *fl) |
| 354 | { | 354 | { |
| 355 | BUG_ON(waitqueue_active(&fl->fl_wait)); | ||
| 356 | BUG_ON(!list_empty(&fl->fl_list)); | ||
| 357 | BUG_ON(!list_empty(&fl->fl_blocked_requests)); | ||
| 358 | BUG_ON(!list_empty(&fl->fl_blocked_member)); | ||
| 359 | BUG_ON(!hlist_unhashed(&fl->fl_link)); | ||
| 360 | |||
| 355 | if (fl->fl_ops) { | 361 | if (fl->fl_ops) { |
| 356 | if (fl->fl_ops->fl_release_private) | 362 | if (fl->fl_ops->fl_release_private) |
| 357 | fl->fl_ops->fl_release_private(fl); | 363 | fl->fl_ops->fl_release_private(fl); |
| @@ -371,12 +377,6 @@ EXPORT_SYMBOL_GPL(locks_release_private); | |||
| 371 | /* Free a lock which is not in use. */ | 377 | /* Free a lock which is not in use. */ |
| 372 | void locks_free_lock(struct file_lock *fl) | 378 | void locks_free_lock(struct file_lock *fl) |
| 373 | { | 379 | { |
| 374 | BUG_ON(waitqueue_active(&fl->fl_wait)); | ||
| 375 | BUG_ON(!list_empty(&fl->fl_list)); | ||
| 376 | BUG_ON(!list_empty(&fl->fl_blocked_requests)); | ||
| 377 | BUG_ON(!list_empty(&fl->fl_blocked_member)); | ||
| 378 | BUG_ON(!hlist_unhashed(&fl->fl_link)); | ||
| 379 | |||
| 380 | locks_release_private(fl); | 380 | locks_release_private(fl); |
| 381 | kmem_cache_free(filelock_cache, fl); | 381 | kmem_cache_free(filelock_cache, fl); |
| 382 | } | 382 | } |
