diff mbox series

[1/4] smb: client: remove extra @chan_count check in __cifs_put_smb_ses()

Message ID 20231030201956.2660-1-pc@manguebit.com (mailing list archive)
State New, archived
Headers show
Series [1/4] smb: client: remove extra @chan_count check in __cifs_put_smb_ses() | expand

Commit Message

Paulo Alcantara Oct. 30, 2023, 8:19 p.m. UTC
If @ses->chan_count <= 1, then for-loop body will not be executed so
no need to check it twice.

Signed-off-by: Paulo Alcantara (SUSE) <pc@manguebit.com>
---
 fs/smb/client/connect.c | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)

Comments

Steve French Oct. 31, 2023, 3:24 a.m. UTC | #1
tentatively merged into cifs-2.6.git for-next pending review/testing

On Mon, Oct 30, 2023 at 3:20 PM Paulo Alcantara <pc@manguebit.com> wrote:
>
> If @ses->chan_count <= 1, then for-loop body will not be executed so
> no need to check it twice.
>
> Signed-off-by: Paulo Alcantara (SUSE) <pc@manguebit.com>
> ---
>  fs/smb/client/connect.c | 23 +++++++++--------------
>  1 file changed, 9 insertions(+), 14 deletions(-)
>
> diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c
> index 7b923e36501b..a017ee552256 100644
> --- a/fs/smb/client/connect.c
> +++ b/fs/smb/client/connect.c
> @@ -1969,9 +1969,10 @@ cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb3_fs_context *ctx)
>
>  void __cifs_put_smb_ses(struct cifs_ses *ses)
>  {
> -       unsigned int rc, xid;
> -       unsigned int chan_count;
>         struct TCP_Server_Info *server = ses->server;
> +       unsigned int xid;
> +       size_t i;
> +       int rc;
>
>         spin_lock(&ses->ses_lock);
>         if (ses->ses_status == SES_EXITING) {
> @@ -2017,20 +2018,14 @@ void __cifs_put_smb_ses(struct cifs_ses *ses)
>         list_del_init(&ses->smb_ses_list);
>         spin_unlock(&cifs_tcp_ses_lock);
>
> -       chan_count = ses->chan_count;
> -
>         /* close any extra channels */
> -       if (chan_count > 1) {
> -               int i;
> -
> -               for (i = 1; i < chan_count; i++) {
> -                       if (ses->chans[i].iface) {
> -                               kref_put(&ses->chans[i].iface->refcount, release_iface);
> -                               ses->chans[i].iface = NULL;
> -                       }
> -                       cifs_put_tcp_session(ses->chans[i].server, 0);
> -                       ses->chans[i].server = NULL;
> +       for (i = 1; i < ses->chan_count; i++) {
> +               if (ses->chans[i].iface) {
> +                       kref_put(&ses->chans[i].iface->refcount, release_iface);
> +                       ses->chans[i].iface = NULL;
>                 }
> +               cifs_put_tcp_session(ses->chans[i].server, 0);
> +               ses->chans[i].server = NULL;
>         }
>
>         sesInfoFree(ses);
> --
> 2.42.0
>
Shyam Prasad N Nov. 2, 2023, 12:30 p.m. UTC | #2
On Tue, Oct 31, 2023 at 8:54 AM Steve French <smfrench@gmail.com> wrote:
>
> tentatively merged into cifs-2.6.git for-next pending review/testing
>
> On Mon, Oct 30, 2023 at 3:20 PM Paulo Alcantara <pc@manguebit.com> wrote:
> >
> > If @ses->chan_count <= 1, then for-loop body will not be executed so
> > no need to check it twice.
> >
> > Signed-off-by: Paulo Alcantara (SUSE) <pc@manguebit.com>
> > ---
> >  fs/smb/client/connect.c | 23 +++++++++--------------
> >  1 file changed, 9 insertions(+), 14 deletions(-)
> >
> > diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c
> > index 7b923e36501b..a017ee552256 100644
> > --- a/fs/smb/client/connect.c
> > +++ b/fs/smb/client/connect.c
> > @@ -1969,9 +1969,10 @@ cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb3_fs_context *ctx)
> >
> >  void __cifs_put_smb_ses(struct cifs_ses *ses)
> >  {
> > -       unsigned int rc, xid;
> > -       unsigned int chan_count;
> >         struct TCP_Server_Info *server = ses->server;
> > +       unsigned int xid;
> > +       size_t i;
> > +       int rc;
> >
> >         spin_lock(&ses->ses_lock);
> >         if (ses->ses_status == SES_EXITING) {
> > @@ -2017,20 +2018,14 @@ void __cifs_put_smb_ses(struct cifs_ses *ses)
> >         list_del_init(&ses->smb_ses_list);
> >         spin_unlock(&cifs_tcp_ses_lock);
> >
> > -       chan_count = ses->chan_count;
> > -
> >         /* close any extra channels */
> > -       if (chan_count > 1) {
> > -               int i;
> > -
> > -               for (i = 1; i < chan_count; i++) {
> > -                       if (ses->chans[i].iface) {
> > -                               kref_put(&ses->chans[i].iface->refcount, release_iface);
> > -                               ses->chans[i].iface = NULL;
> > -                       }
> > -                       cifs_put_tcp_session(ses->chans[i].server, 0);
> > -                       ses->chans[i].server = NULL;
> > +       for (i = 1; i < ses->chan_count; i++) {
> > +               if (ses->chans[i].iface) {
> > +                       kref_put(&ses->chans[i].iface->refcount, release_iface);
> > +                       ses->chans[i].iface = NULL;
> >                 }
> > +               cifs_put_tcp_session(ses->chans[i].server, 0);
> > +               ses->chans[i].server = NULL;
> >         }
> >
> >         sesInfoFree(ses);
> > --
> > 2.42.0
> >
>
>
> --
> Thanks,
>
> Steve

Looks good to me.
You can add my RB.
diff mbox series

Patch

diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c
index 7b923e36501b..a017ee552256 100644
--- a/fs/smb/client/connect.c
+++ b/fs/smb/client/connect.c
@@ -1969,9 +1969,10 @@  cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb3_fs_context *ctx)
 
 void __cifs_put_smb_ses(struct cifs_ses *ses)
 {
-	unsigned int rc, xid;
-	unsigned int chan_count;
 	struct TCP_Server_Info *server = ses->server;
+	unsigned int xid;
+	size_t i;
+	int rc;
 
 	spin_lock(&ses->ses_lock);
 	if (ses->ses_status == SES_EXITING) {
@@ -2017,20 +2018,14 @@  void __cifs_put_smb_ses(struct cifs_ses *ses)
 	list_del_init(&ses->smb_ses_list);
 	spin_unlock(&cifs_tcp_ses_lock);
 
-	chan_count = ses->chan_count;
-
 	/* close any extra channels */
-	if (chan_count > 1) {
-		int i;
-
-		for (i = 1; i < chan_count; i++) {
-			if (ses->chans[i].iface) {
-				kref_put(&ses->chans[i].iface->refcount, release_iface);
-				ses->chans[i].iface = NULL;
-			}
-			cifs_put_tcp_session(ses->chans[i].server, 0);
-			ses->chans[i].server = NULL;
+	for (i = 1; i < ses->chan_count; i++) {
+		if (ses->chans[i].iface) {
+			kref_put(&ses->chans[i].iface->refcount, release_iface);
+			ses->chans[i].iface = NULL;
 		}
+		cifs_put_tcp_session(ses->chans[i].server, 0);
+		ses->chans[i].server = NULL;
 	}
 
 	sesInfoFree(ses);