diff options
Diffstat (limited to 'fs/kernfs/file.c')
-rw-r--r-- | fs/kernfs/file.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c index 4a5863b79de9..fa053151fa96 100644 --- a/fs/kernfs/file.c +++ b/fs/kernfs/file.c | |||
@@ -421,6 +421,16 @@ static int kernfs_file_mmap(struct file *file, struct vm_area_struct *vma) | |||
421 | const struct kernfs_ops *ops; | 421 | const struct kernfs_ops *ops; |
422 | int rc; | 422 | int rc; |
423 | 423 | ||
424 | /* | ||
425 | * mmap path and of->mutex are prone to triggering spurious lockdep | ||
426 | * warnings and we don't want to add spurious locking dependency | ||
427 | * between the two. Check whether mmap is actually implemented | ||
428 | * without grabbing @of->mutex by testing HAS_MMAP flag. See the | ||
429 | * comment in kernfs_file_open() for more details. | ||
430 | */ | ||
431 | if (!(of->sd->s_flags & SYSFS_FLAG_HAS_MMAP)) | ||
432 | return -ENODEV; | ||
433 | |||
424 | mutex_lock(&of->mutex); | 434 | mutex_lock(&of->mutex); |
425 | 435 | ||
426 | rc = -ENODEV; | 436 | rc = -ENODEV; |
@@ -428,10 +438,7 @@ static int kernfs_file_mmap(struct file *file, struct vm_area_struct *vma) | |||
428 | goto out_unlock; | 438 | goto out_unlock; |
429 | 439 | ||
430 | ops = kernfs_ops(of->sd); | 440 | ops = kernfs_ops(of->sd); |
431 | if (ops->mmap) | 441 | rc = ops->mmap(of, vma); |
432 | rc = ops->mmap(of, vma); | ||
433 | if (rc) | ||
434 | goto out_put; | ||
435 | 442 | ||
436 | /* | 443 | /* |
437 | * PowerPC's pci_mmap of legacy_mem uses shmem_zero_setup() | 444 | * PowerPC's pci_mmap of legacy_mem uses shmem_zero_setup() |
@@ -596,6 +603,9 @@ static int kernfs_file_open(struct inode *inode, struct file *file) | |||
596 | * happen on the same file. At this point, we can't easily give | 603 | * happen on the same file. At this point, we can't easily give |
597 | * each file a separate locking class. Let's differentiate on | 604 | * each file a separate locking class. Let's differentiate on |
598 | * whether the file has mmap or not for now. | 605 | * whether the file has mmap or not for now. |
606 | * | ||
607 | * Both paths of the branch look the same. They're supposed to | ||
608 | * look that way and give @of->mutex different static lockdep keys. | ||
599 | */ | 609 | */ |
600 | if (has_mmap) | 610 | if (has_mmap) |
601 | mutex_init(&of->mutex); | 611 | mutex_init(&of->mutex); |