summaryrefslogtreecommitdiffstats
path: root/fs/cifs/misc.c
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2018-12-21 00:50:48 -0500
committerSteve French <stfrench@microsoft.com>2018-12-28 11:09:46 -0500
commit0544b324e62c177c3a9e9c3bdce22e6db9f34588 (patch)
tree889b401a257a882a6a4882192b8726e75c87677b /fs/cifs/misc.c
parent29cbfa1b2be2e51785f871351d321896861f2ce8 (diff)
cifs: check kzalloc return
kzalloc can return NULL so an additional check is needed. While there is a check for ret_buf there is no check for the allocation of ret_buf->crfid.fid - this check is thus added. Both call-sites of tconInfoAlloc() check for NULL return of tconInfoAlloc() so returning NULL on failure of kzalloc() here seems appropriate. As the kzalloc() is the only thing here that can fail it is moved to the beginning so as not to initialize other resources on failure of kzalloc. Fixes: 3d4ef9a15343 ("smb3: fix redundant opens on root") Signed-off-by: Joe Perches <joe@perches.com> Signed-off-by: Steve French <stfrench@microsoft.com>
Diffstat (limited to 'fs/cifs/misc.c')
-rw-r--r--fs/cifs/misc.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
index 5e315e4009e2..10ae1a35b6f7 100644
--- a/fs/cifs/misc.c
+++ b/fs/cifs/misc.c
@@ -111,21 +111,27 @@ struct cifs_tcon *
111tconInfoAlloc(void) 111tconInfoAlloc(void)
112{ 112{
113 struct cifs_tcon *ret_buf; 113 struct cifs_tcon *ret_buf;
114 ret_buf = kzalloc(sizeof(struct cifs_tcon), GFP_KERNEL); 114
115 if (ret_buf) { 115 ret_buf = kzalloc(sizeof(*ret_buf), GFP_KERNEL);
116 atomic_inc(&tconInfoAllocCount); 116 if (!ret_buf)
117 ret_buf->tidStatus = CifsNew; 117 return NULL;
118 ++ret_buf->tc_count; 118 ret_buf->crfid.fid = kzalloc(sizeof(*ret_buf->crfid.fid), GFP_KERNEL);
119 INIT_LIST_HEAD(&ret_buf->openFileList); 119 if (!ret_buf->crfid.fid) {
120 INIT_LIST_HEAD(&ret_buf->tcon_list); 120 kfree(ret_buf);
121 spin_lock_init(&ret_buf->open_file_lock); 121 return NULL;
122 mutex_init(&ret_buf->crfid.fid_mutex);
123 ret_buf->crfid.fid = kzalloc(sizeof(struct cifs_fid),
124 GFP_KERNEL);
125 spin_lock_init(&ret_buf->stat_lock);
126 atomic_set(&ret_buf->num_local_opens, 0);
127 atomic_set(&ret_buf->num_remote_opens, 0);
128 } 122 }
123
124 atomic_inc(&tconInfoAllocCount);
125 ret_buf->tidStatus = CifsNew;
126 ++ret_buf->tc_count;
127 INIT_LIST_HEAD(&ret_buf->openFileList);
128 INIT_LIST_HEAD(&ret_buf->tcon_list);
129 spin_lock_init(&ret_buf->open_file_lock);
130 mutex_init(&ret_buf->crfid.fid_mutex);
131 spin_lock_init(&ret_buf->stat_lock);
132 atomic_set(&ret_buf->num_local_opens, 0);
133 atomic_set(&ret_buf->num_remote_opens, 0);
134
129 return ret_buf; 135 return ret_buf;
130} 136}
131 137