]> www.infradead.org Git - users/hch/misc.git/commitdiff
smb: client: Improve unlocking of a mutex in cifs_get_swn_reg()
authorMarkus Elfring <elfring@users.sourceforge.net>
Tue, 7 Oct 2025 15:45:28 +0000 (17:45 +0200)
committerSteve French <stfrench@microsoft.com>
Tue, 7 Oct 2025 16:12:23 +0000 (11:12 -0500)
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>
fs/smb/client/cifs_swn.c

index 7233c6a7e6d70b03336737d8acc5bb302d3067d2..35a3e73c1958062db6d68759eb0b0477fad26ab9 100644 (file)
@@ -313,17 +313,15 @@ static struct cifs_swn_reg *cifs_get_swn_reg(struct cifs_tcon *tcon)
        reg = cifs_find_swn_reg(tcon);
        if (!IS_ERR(reg)) {
                kref_get(&reg->ref_count);
-               mutex_unlock(&cifs_swnreg_idr_mutex);
-               return reg;
+               goto unlock;
        } else if (PTR_ERR(reg) != -EEXIST) {
-               mutex_unlock(&cifs_swnreg_idr_mutex);
-               return reg;
+               goto unlock;
        }
 
        reg = kmalloc(sizeof(struct cifs_swn_reg), GFP_ATOMIC);
        if (reg == NULL) {
-               mutex_unlock(&cifs_swnreg_idr_mutex);
-               return ERR_PTR(-ENOMEM);
+               ret = -ENOMEM;
+               goto fail_unlock;
        }
 
        kref_init(&reg->ref_count);
@@ -354,7 +352,7 @@ static struct cifs_swn_reg *cifs_get_swn_reg(struct cifs_tcon *tcon)
        reg->ip_notify = (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT);
 
        reg->tcon = tcon;
-
+unlock:
        mutex_unlock(&cifs_swnreg_idr_mutex);
 
        return reg;
@@ -365,6 +363,7 @@ fail_idr:
        idr_remove(&cifs_swnreg_idr, reg->id);
 fail:
        kfree(reg);
+fail_unlock:
        mutex_unlock(&cifs_swnreg_idr_mutex);
        return ERR_PTR(ret);
 }