Skip to content

Commit e2080b7

Browse files
elfringsmfrench
authored andcommitted
smb: client: Improve unlocking of a mutex in cifs_get_swn_reg()
Use two additional labels so that another bit of common code can be better reused at the end of this function implementation. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 0a98b40 commit e2080b7

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

fs/smb/client/cifs_swn.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,17 +313,15 @@ static struct cifs_swn_reg *cifs_get_swn_reg(struct cifs_tcon *tcon)
313313
reg = cifs_find_swn_reg(tcon);
314314
if (!IS_ERR(reg)) {
315315
kref_get(&reg->ref_count);
316-
mutex_unlock(&cifs_swnreg_idr_mutex);
317-
return reg;
316+
goto unlock;
318317
} else if (PTR_ERR(reg) != -EEXIST) {
319-
mutex_unlock(&cifs_swnreg_idr_mutex);
320-
return reg;
318+
goto unlock;
321319
}
322320

323321
reg = kmalloc(sizeof(struct cifs_swn_reg), GFP_ATOMIC);
324322
if (reg == NULL) {
325-
mutex_unlock(&cifs_swnreg_idr_mutex);
326-
return ERR_PTR(-ENOMEM);
323+
ret = -ENOMEM;
324+
goto fail_unlock;
327325
}
328326

329327
kref_init(&reg->ref_count);
@@ -354,7 +352,7 @@ static struct cifs_swn_reg *cifs_get_swn_reg(struct cifs_tcon *tcon)
354352
reg->ip_notify = (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT);
355353

356354
reg->tcon = tcon;
357-
355+
unlock:
358356
mutex_unlock(&cifs_swnreg_idr_mutex);
359357

360358
return reg;
@@ -365,6 +363,7 @@ static struct cifs_swn_reg *cifs_get_swn_reg(struct cifs_tcon *tcon)
365363
idr_remove(&cifs_swnreg_idr, reg->id);
366364
fail:
367365
kfree(reg);
366+
fail_unlock:
368367
mutex_unlock(&cifs_swnreg_idr_mutex);
369368
return ERR_PTR(ret);
370369
}

0 commit comments

Comments
 (0)