From: Jeff Layton <jlay...@kernel.org>

[ Upstream commit 9a6bed4fe0c8bf57785cbc4db9f86086cb9b193d ]

If the caller passes in a NULL cap_reservation, and we can't allocate
one then ensure that we fail gracefully.

Signed-off-by: Jeff Layton <jlay...@kernel.org>
Signed-off-by: Ilya Dryomov <idryo...@gmail.com>
Signed-off-by: Sasha Levin <sas...@kernel.org>
---
 fs/ceph/inode.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
index c07407586ce87..660a878e20ef2 100644
--- a/fs/ceph/inode.c
+++ b/fs/ceph/inode.c
@@ -754,8 +754,11 @@ static int fill_inode(struct inode *inode, struct page 
*locked_page,
        info_caps = le32_to_cpu(info->cap.caps);
 
        /* prealloc new cap struct */
-       if (info_caps && ceph_snap(inode) == CEPH_NOSNAP)
+       if (info_caps && ceph_snap(inode) == CEPH_NOSNAP) {
                new_cap = ceph_get_cap(mdsc, caps_reservation);
+               if (!new_cap)
+                       return -ENOMEM;
+       }
 
        /*
         * prealloc xattr data, if it looks like we'll need it.  only
-- 
2.25.1

Reply via email to