All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cifs: get rid of unneeded conditional in cifs_get_num_sgs()
@ 2023-01-31 16:22 Paulo Alcantara
  2023-01-31 17:28 ` Steve French
  0 siblings, 1 reply; 2+ messages in thread
From: Paulo Alcantara @ 2023-01-31 16:22 UTC (permalink / raw)
  To: smfrench; +Cc: linux-cifs, Paulo Alcantara

Just have @skip set to 0 after first iterations of the two nested
loops.

Signed-off-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
---
 fs/cifs/cifsglob.h | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index 3da302ea9d76..1d893bea4723 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -2164,6 +2164,12 @@ static inline unsigned int cifs_get_num_sgs(const struct smb_rqst *rqst,
 	unsigned long addr;
 	int i, j;
 
+	/*
+	 * The first rqst has a transform header where the first 20 bytes are
+	 * not part of the encrypted blob.
+	 */
+	skip = 20;
+
 	/* Assumes the first rqst has a transform header as the first iov.
 	 * I.e.
 	 * rqst[0].rq_iov[0]  is transform header
@@ -2171,14 +2177,9 @@ static inline unsigned int cifs_get_num_sgs(const struct smb_rqst *rqst,
 	 * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
 	 */
 	for (i = 0; i < num_rqst; i++) {
-		/*
-		 * The first rqst has a transform header where the
-		 * first 20 bytes are not part of the encrypted blob.
-		 */
 		for (j = 0; j < rqst[i].rq_nvec; j++) {
 			struct kvec *iov = &rqst[i].rq_iov[j];
 
-			skip = (i == 0) && (j == 0) ? 20 : 0;
 			addr = (unsigned long)iov->iov_base + skip;
 			if (unlikely(is_vmalloc_addr((void *)addr))) {
 				len = iov->iov_len - skip;
@@ -2187,6 +2188,7 @@ static inline unsigned int cifs_get_num_sgs(const struct smb_rqst *rqst,
 			} else {
 				nents++;
 			}
+			skip = 0;
 		}
 		nents += rqst[i].rq_npages;
 	}
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] cifs: get rid of unneeded conditional in cifs_get_num_sgs()
  2023-01-31 16:22 [PATCH] cifs: get rid of unneeded conditional in cifs_get_num_sgs() Paulo Alcantara
@ 2023-01-31 17:28 ` Steve French
  0 siblings, 0 replies; 2+ messages in thread
From: Steve French @ 2023-01-31 17:28 UTC (permalink / raw)
  To: Paulo Alcantara; +Cc: linux-cifs

added David Howell's RGB and tentatively posted to cifs-2.6.git
for-next pending testing

On Tue, Jan 31, 2023 at 10:22 AM Paulo Alcantara <pc@cjr.nz> wrote:
>
> Just have @skip set to 0 after first iterations of the two nested
> loops.
>
> Signed-off-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
> ---
>  fs/cifs/cifsglob.h | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
> index 3da302ea9d76..1d893bea4723 100644
> --- a/fs/cifs/cifsglob.h
> +++ b/fs/cifs/cifsglob.h
> @@ -2164,6 +2164,12 @@ static inline unsigned int cifs_get_num_sgs(const struct smb_rqst *rqst,
>         unsigned long addr;
>         int i, j;
>
> +       /*
> +        * The first rqst has a transform header where the first 20 bytes are
> +        * not part of the encrypted blob.
> +        */
> +       skip = 20;
> +
>         /* Assumes the first rqst has a transform header as the first iov.
>          * I.e.
>          * rqst[0].rq_iov[0]  is transform header
> @@ -2171,14 +2177,9 @@ static inline unsigned int cifs_get_num_sgs(const struct smb_rqst *rqst,
>          * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
>          */
>         for (i = 0; i < num_rqst; i++) {
> -               /*
> -                * The first rqst has a transform header where the
> -                * first 20 bytes are not part of the encrypted blob.
> -                */
>                 for (j = 0; j < rqst[i].rq_nvec; j++) {
>                         struct kvec *iov = &rqst[i].rq_iov[j];
>
> -                       skip = (i == 0) && (j == 0) ? 20 : 0;
>                         addr = (unsigned long)iov->iov_base + skip;
>                         if (unlikely(is_vmalloc_addr((void *)addr))) {
>                                 len = iov->iov_len - skip;
> @@ -2187,6 +2188,7 @@ static inline unsigned int cifs_get_num_sgs(const struct smb_rqst *rqst,
>                         } else {
>                                 nents++;
>                         }
> +                       skip = 0;
>                 }
>                 nents += rqst[i].rq_npages;
>         }
> --
> 2.39.1
>


-- 
Thanks,

Steve

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-01-31 17:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-31 16:22 [PATCH] cifs: get rid of unneeded conditional in cifs_get_num_sgs() Paulo Alcantara
2023-01-31 17:28 ` Steve French

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.