cifs: Delete a stray unlock in cifs_swn_reconnect()
Subsystems (3)
PATCH 1/3 cifs: Delete a stray unlock in cifs_swn_reconnect()
The unlock is done in the caller, this is a stray which leads to a double unlock bug.
--- fs/cifs/cifs_swn.c | 2 -- 1 file changed, 2 deletions(-)
fs/cifs/cifs_swn.c +0 -2
@@ -285,8 +285,6 @@ static struct cifs_swn_reg *cifs_find_swn_reg(struct cifs_tcon *tcon)continue ; } -mutex_unlock (&cifs_swnreg_idr_mutex); -cifs_dbg (FYI ,"Existing swn registration for %s:%s found\n" , swnreg->net_name, swnreg->share_name);
Signature · 1 line
2.29.2
PATCH 2/2 cifs: Unlock on errors in cifs_swn_reconnect()
There are three error paths which need to unlock before returning.
--- fs/cifs/cifs_swn.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
fs/cifs/cifs_swn.c +7 -6
@@ -480,16 +480,16 @@ static int cifs_swn_store_swn_addr(const struct sockaddr_storage *new,static int cifs_swn_reconnect (struct cifs_tcon *tcon,struct sockaddr_storage *addr) { +int ret =0 ; +/* Store the reconnect address */ mutex_lock (&tcon->ses->server->srv_mutex);if (!cifs_sockaddr_equal (&tcon->ses->server->dstaddr, addr)) { -int ret; - ret =cifs_swn_store_swn_addr (addr, &tcon->ses->server->dstaddr, &tcon->ses->server->swn_dstaddr);if (ret <0 ) {cifs_dbg (VFS ,"%s: failed to store address: %d\n" , __func__, ret); -return ret; + goto unlock; } tcon->ses->server->use_swn_dstaddr = true;
@@ -500,7 +500,7 @@ static int cifs_swn_reconnect(struct cifs_tcon *tcon, struct sockaddr_storage *aif (ret <0 ) {cifs_dbg (VFS ,"%s: Failed to unregister for witness notifications: %d\n" , __func__, ret); -return ret; + goto unlock; }/*
@@ -511,7 +511,7 @@ static int cifs_swn_reconnect(struct cifs_tcon *tcon, struct sockaddr_storage *aif (ret <0 ) {cifs_dbg (VFS ,"%s: Failed to register for witness notifications: %d\n" , __func__, ret); -return ret; + goto unlock; }spin_lock (&GlobalMid_Lock);
@@ -519,9 +519,10 @@ static int cifs_swn_reconnect(struct cifs_tcon *tcon, struct sockaddr_storage *a tcon->ses->server->tcpStatus = CifsNeedReconnect;spin_unlock (&GlobalMid_Lock); } +unlock:mutex_unlock (&tcon->ses->server->srv_mutex); -return 0 ; +return ret; }static int cifs_swn_client_move (struct cifs_swn_reg *swnreg,struct sockaddr_storage *addr)
Signature · 1 line
2.29.2
Re: [PATCH 2/2] cifs: Unlock on errors in cifs_swn_reconnect()
Quoted 1 line · Dan Carpenter
There are three error paths which need to unlock before returning.
Thanks.
Signature · 4 lines
Samuel Cabrero / SUSE Labs Samba Team GPG: D7D6 E259 F91C F0B3 2E61 1239 3655 6EC9 7051 0856 [email protected] [email protected]
PATCH 3/3 cifs: Re-indent cifs_swn_reconnect()
In reply to Dan CarpenterThis code is slightly nicer if we flip the cifs_sockaddr_equal() around and pull all the code in one tab.
--- fs/cifs/cifs_swn.c | 64 ++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 31 deletions(-)
fs/cifs/cifs_swn.c +33 -31
@@ -484,41 +484,43 @@ static int cifs_swn_reconnect(struct cifs_tcon *tcon, struct sockaddr_storage *a/* Store the reconnect address */ mutex_lock (&tcon->ses->server->srv_mutex); -if (!cifs_sockaddr_equal (&tcon->ses->server->dstaddr, addr)) { - ret =cifs_swn_store_swn_addr (addr, &tcon->ses->server->dstaddr, - &tcon->ses->server->swn_dstaddr); -if (ret <0 ) { -cifs_dbg (VFS ,"%s: failed to store address: %d\n" , __func__, ret); - goto unlock; - } - tcon->ses->server->use_swn_dstaddr = true; +if (cifs_sockaddr_equal (&tcon->ses->server->dstaddr, addr)) + goto unlock; -/* -* Unregister to stop receiving notifications for the old IP address. -*/ - ret =cifs_swn_unregister (tcon); -if (ret <0 ) { -cifs_dbg (VFS ,"%s: Failed to unregister for witness notifications: %d\n" , - __func__, ret); - goto unlock; - } + ret =cifs_swn_store_swn_addr (addr, &tcon->ses->server->dstaddr, + &tcon->ses->server->swn_dstaddr); +if (ret <0 ) { +cifs_dbg (VFS ,"%s: failed to store address: %d\n" , __func__, ret); + goto unlock; + } + tcon->ses->server->use_swn_dstaddr = true; -/* -* And register to receive notifications for the new IP address now that we have -* stored the new address. -*/ - ret =cifs_swn_register (tcon); -if (ret <0 ) { -cifs_dbg (VFS ,"%s: Failed to register for witness notifications: %d\n" , - __func__, ret); - goto unlock; - } +/* +* Unregister to stop receiving notifications for the old IP address. +*/ + ret =cifs_swn_unregister (tcon); +if (ret <0 ) { +cifs_dbg (VFS ,"%s: Failed to unregister for witness notifications: %d\n" , + __func__, ret); + goto unlock; + } -spin_lock (&GlobalMid_Lock); -if (tcon->ses->server->tcpStatus != CifsExiting) - tcon->ses->server->tcpStatus = CifsNeedReconnect; -spin_unlock (&GlobalMid_Lock); +/* +* And register to receive notifications for the new IP address now that we have +* stored the new address. +*/ + ret =cifs_swn_register (tcon); +if (ret <0 ) { +cifs_dbg (VFS ,"%s: Failed to register for witness notifications: %d\n" , + __func__, ret); + goto unlock; } + +spin_lock (&GlobalMid_Lock); +if (tcon->ses->server->tcpStatus != CifsExiting) + tcon->ses->server->tcpStatus = CifsNeedReconnect; +spin_unlock (&GlobalMid_Lock); + unlock:mutex_unlock (&tcon->ses->server->srv_mutex);
Signature · 1 line
2.29.2
Re: [PATCH 3/3] cifs: Re-indent cifs_swn_reconnect()
Quoted 3 lines · Dan Carpenter
This code is slightly nicer if we flip the
cifs_sockaddr_equal()around and pull all the code in one tab.
I Agree.
Signature · 4 lines
Samuel Cabrero / SUSE Labs Samba Team GPG: D7D6 E259 F91C F0B3 2E61 1239 3655 6EC9 7051 0856 [email protected] [email protected]
Re: [PATCH 3/3] cifs: Re-indent cifs_swn_reconnect()
In reply to Dan Carpentertentatively merged these three into cifs-2.6.git for-next pending testing
Quoted 92 lines · Dan Carpenter via samba-technical
This code is slightly nicer if we flip the
cifs_sockaddr_equal()around and pull all the code in one tab.Signed-off-by Dan Carpenter <[email protected]>--- fs/cifs/cifs_swn.c | 64 ++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 31 deletions(-)fs/cifs/cifs_swn.c +33
-32@@ -484,41 +484,43 @@ static int cifs_swn_reconnect(struct cifs_tcon *tcon, struct sockaddr_storage *a/* Store the reconnect address */ mutex_lock (&tcon->ses->server->srv_mutex); -if (!cifs_sockaddr_equal (&tcon->ses->server->dstaddr, addr)) { - ret =cifs_swn_store_swn_addr (addr, &tcon->ses->server->dstaddr, - &tcon->ses->server->swn_dstaddr); -if (ret <0 ) { -cifs_dbg (VFS ,"%s: failed to store address: %d\n" , __func__, ret); - goto unlock; - } - tcon->ses->server->use_swn_dstaddr = true; +if (cifs_sockaddr_equal (&tcon->ses->server->dstaddr, addr)) + goto unlock; -/* -* Unregister to stop receiving notifications for the old IP address. -*/ - ret =cifs_swn_unregister (tcon); -if (ret <0 ) { -cifs_dbg (VFS ,"%s: Failed to unregister for witness notifications: %d\n" , - __func__, ret); - goto unlock; - } + ret =cifs_swn_store_swn_addr (addr, &tcon->ses->server->dstaddr, + &tcon->ses->server->swn_dstaddr); +if (ret <0 ) { +cifs_dbg (VFS ,"%s: failed to store address: %d\n" , __func__, ret); + goto unlock; + } + tcon->ses->server->use_swn_dstaddr = true; -/* -* And register to receive notifications for the new IP address now that we have -* stored the new address. -*/ - ret =cifs_swn_register (tcon); -if (ret <0 ) { -cifs_dbg (VFS ,"%s: Failed to register for witness notifications: %d\n" , - __func__, ret); - goto unlock; - } +/* +* Unregister to stop receiving notifications for the old IP address. +*/ + ret =cifs_swn_unregister (tcon); +if (ret <0 ) { +cifs_dbg (VFS ,"%s: Failed to unregister for witness notifications: %d\n" , + __func__, ret); + goto unlock; + } -spin_lock (&GlobalMid_Lock); -if (tcon->ses->server->tcpStatus != CifsExiting) - tcon->ses->server->tcpStatus = CifsNeedReconnect; -spin_unlock (&GlobalMid_Lock); +/* +* And register to receive notifications for the new IP address now that we have +* stored the new address. +*/ + ret =cifs_swn_register (tcon); +if (ret <0 ) { +cifs_dbg (VFS ,"%s: Failed to register for witness notifications: %d\n" , + __func__, ret); + goto unlock; } + +spin_lock (&GlobalMid_Lock); +if (tcon->ses->server->tcpStatus != CifsExiting) + tcon->ses->server->tcpStatus = CifsNeedReconnect; +spin_unlock (&GlobalMid_Lock); + unlock:mutex_unlock (&tcon->ses->server->srv_mutex); --2.29.2
Signature · 3 lines
Thanks, Steve
Quoted 3 lines · Dan Carpenter
The unlock is done in the caller, this is a stray which leads to a double unlock bug.
Indeed.
Signature · 4 lines
Samuel Cabrero / SUSE Labs Samba Team GPG: D7D6 E259 F91C F0B3 2E61 1239 3655 6EC9 7051 0856 [email protected] [email protected]