linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/7] Avoid a few casts from void *
@ 2023-03-17 11:15 Volker Lendecke
  2023-03-17 11:15 ` [PATCH 1/7] cifs: Avoid a cast in add_lease_context() Volker Lendecke
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Volker Lendecke @ 2023-03-17 11:15 UTC (permalink / raw)
  To: linux-cifs; +Cc: Volker Lendecke

We should not go through void * without type-checking if it's not
really necessary.

Volker Lendecke (7):
  cifs: Avoid a cast in add_lease_context()
  cifs: Avoid a cast in add_durable_context()
  cifs: Avoid a cast in add_posix_context()
  cifs: Avoid a cast in add_sd_context()
  cifs: Avoid a cast in add_durable_v2_context()
  cifs: Avoid a cast in add_durable_reconnect_v2_context()
  cifs: Avoid a cast in add_query_id_context()

 fs/cifs/smb2pdu.c | 55 ++++++++++++++++++++++++++---------------------
 1 file changed, 30 insertions(+), 25 deletions(-)

-- 
2.30.2


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

* [PATCH 1/7] cifs: Avoid a cast in add_lease_context()
  2023-03-17 11:15 [PATCH 0/7] Avoid a few casts from void * Volker Lendecke
@ 2023-03-17 11:15 ` Volker Lendecke
  2023-03-17 11:15 ` [PATCH 2/7] cifs: Avoid a cast in add_durable_context() Volker Lendecke
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Volker Lendecke @ 2023-03-17 11:15 UTC (permalink / raw)
  To: linux-cifs; +Cc: Volker Lendecke

We have the correctly-typed struct smb2_create_req * available in the
caller.

Signed-off-by: Volker Lendecke <vl@samba.org>
---
 fs/cifs/smb2pdu.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 0e53265e1462..3eb745237459 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -2148,10 +2148,11 @@ smb2_parse_contexts(struct TCP_Server_Info *server,
 }
 
 static int
-add_lease_context(struct TCP_Server_Info *server, struct kvec *iov,
+add_lease_context(struct TCP_Server_Info *server,
+		  struct smb2_create_req *req,
+		  struct kvec *iov,
 		  unsigned int *num_iovec, u8 *lease_key, __u8 *oplock)
 {
-	struct smb2_create_req *req = iov[0].iov_base;
 	unsigned int num = *num_iovec;
 
 	iov[num].iov_base = server->ops->create_lease_buf(lease_key, *oplock);
@@ -2833,7 +2834,7 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server,
 		  (oparms->create_options & CREATE_NOT_FILE))
 		req->RequestedOplockLevel = *oplock; /* no srv lease support */
 	else {
-		rc = add_lease_context(server, iov, &n_iov,
+		rc = add_lease_context(server, req, iov, &n_iov,
 				       oparms->fid->lease_key, oplock);
 		if (rc)
 			return rc;
-- 
2.30.2


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

* [PATCH 2/7] cifs: Avoid a cast in add_durable_context()
  2023-03-17 11:15 [PATCH 0/7] Avoid a few casts from void * Volker Lendecke
  2023-03-17 11:15 ` [PATCH 1/7] cifs: Avoid a cast in add_lease_context() Volker Lendecke
@ 2023-03-17 11:15 ` Volker Lendecke
  2023-03-17 11:15 ` [PATCH 3/7] cifs: Avoid a cast in add_posix_context() Volker Lendecke
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Volker Lendecke @ 2023-03-17 11:15 UTC (permalink / raw)
  To: linux-cifs; +Cc: Volker Lendecke

We have the correctly-typed struct smb2_create_req * available in the
caller.

Signed-off-by: Volker Lendecke <vl@samba.org>
---
 fs/cifs/smb2pdu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 3eb745237459..cebb8d9837d2 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -2285,10 +2285,10 @@ add_durable_reconnect_v2_context(struct kvec *iov, unsigned int *num_iovec,
 }
 
 static int
-add_durable_context(struct kvec *iov, unsigned int *num_iovec,
+add_durable_context(struct smb2_create_req *req,
+		    struct kvec *iov, unsigned int *num_iovec,
 		    struct cifs_open_parms *oparms, bool use_persistent)
 {
-	struct smb2_create_req *req = iov[0].iov_base;
 	unsigned int num = *num_iovec;
 
 	if (use_persistent) {
@@ -2849,7 +2849,7 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server,
 				cpu_to_le32(server->vals->create_lease_size);
 		}
 
-		rc = add_durable_context(iov, &n_iov, oparms,
+		rc = add_durable_context(req, iov, &n_iov, oparms,
 					tcon->use_persistent);
 		if (rc)
 			return rc;
-- 
2.30.2


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

* [PATCH 3/7] cifs: Avoid a cast in add_posix_context()
  2023-03-17 11:15 [PATCH 0/7] Avoid a few casts from void * Volker Lendecke
  2023-03-17 11:15 ` [PATCH 1/7] cifs: Avoid a cast in add_lease_context() Volker Lendecke
  2023-03-17 11:15 ` [PATCH 2/7] cifs: Avoid a cast in add_durable_context() Volker Lendecke
@ 2023-03-17 11:15 ` Volker Lendecke
  2023-03-17 11:15 ` [PATCH 4/7] cifs: Avoid a cast in add_sd_context() Volker Lendecke
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Volker Lendecke @ 2023-03-17 11:15 UTC (permalink / raw)
  To: linux-cifs; +Cc: Volker Lendecke

We have the correctly-typed struct smb2_create_req * available in the
caller.

Signed-off-by: Volker Lendecke <vl@samba.org>
---
 fs/cifs/smb2pdu.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index cebb8d9837d2..6b6790d8d0ee 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -795,9 +795,9 @@ create_posix_buf(umode_t mode)
 }
 
 static int
-add_posix_context(struct kvec *iov, unsigned int *num_iovec, umode_t mode)
+add_posix_context(struct smb2_create_req *req,
+		  struct kvec *iov, unsigned int *num_iovec, umode_t mode)
 {
-	struct smb2_create_req *req = iov[0].iov_base;
 	unsigned int num = *num_iovec;
 
 	iov[num].iov_base = create_posix_buf(mode);
@@ -2694,7 +2694,7 @@ int smb311_posix_mkdir(const unsigned int xid, struct inode *inode,
 
 	if (tcon->posix_extensions) {
 		/* resource #3: posix buf */
-		rc = add_posix_context(iov, &n_iov, mode);
+		rc = add_posix_context(req, iov, &n_iov, mode);
 		if (rc)
 			goto err_free_req;
 		pc_buf = iov[n_iov-1].iov_base;
@@ -2863,7 +2863,7 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server,
 				cpu_to_le32(iov[n_iov-1].iov_len);
 		}
 
-		rc = add_posix_context(iov, &n_iov, oparms->mode);
+		rc = add_posix_context(req, iov, &n_iov, oparms->mode);
 		if (rc)
 			return rc;
 	}
-- 
2.30.2


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

* [PATCH 4/7] cifs: Avoid a cast in add_sd_context()
  2023-03-17 11:15 [PATCH 0/7] Avoid a few casts from void * Volker Lendecke
                   ` (2 preceding siblings ...)
  2023-03-17 11:15 ` [PATCH 3/7] cifs: Avoid a cast in add_posix_context() Volker Lendecke
@ 2023-03-17 11:15 ` Volker Lendecke
  2023-03-17 11:15 ` [PATCH 5/7] cifs: Avoid a cast in add_durable_v2_context() Volker Lendecke
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Volker Lendecke @ 2023-03-17 11:15 UTC (permalink / raw)
  To: linux-cifs; +Cc: Volker Lendecke

We have the correctly-typed struct smb2_create_req * available in the
caller.

Signed-off-by: Volker Lendecke <vl@samba.org>
---
 fs/cifs/smb2pdu.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 6b6790d8d0ee..91fc0ad3e1b4 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -2344,9 +2344,9 @@ create_twarp_buf(__u64 timewarp)
 
 /* See MS-SMB2 2.2.13.2.7 */
 static int
-add_twarp_context(struct kvec *iov, unsigned int *num_iovec, __u64 timewarp)
+add_twarp_context(struct smb2_create_req *req,
+		  struct kvec *iov, unsigned int *num_iovec, __u64 timewarp)
 {
-	struct smb2_create_req *req = iov[0].iov_base;
 	unsigned int num = *num_iovec;
 
 	iov[num].iov_base = create_twarp_buf(timewarp);
@@ -2478,9 +2478,10 @@ create_sd_buf(umode_t mode, bool set_owner, unsigned int *len)
 }
 
 static int
-add_sd_context(struct kvec *iov, unsigned int *num_iovec, umode_t mode, bool set_owner)
+add_sd_context(struct smb2_create_req *req,
+	       struct kvec *iov, unsigned int *num_iovec, umode_t mode,
+	       bool set_owner)
 {
-	struct smb2_create_req *req = iov[0].iov_base;
 	unsigned int num = *num_iovec;
 	unsigned int len = 0;
 
@@ -2877,7 +2878,7 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server,
 				cpu_to_le32(iov[n_iov-1].iov_len);
 		}
 
-		rc = add_twarp_context(iov, &n_iov, tcon->snapshot_time);
+		rc = add_twarp_context(req, iov, &n_iov, tcon->snapshot_time);
 		if (rc)
 			return rc;
 	}
@@ -2907,7 +2908,8 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server,
 			}
 
 			cifs_dbg(FYI, "add sd with mode 0x%x\n", oparms->mode);
-			rc = add_sd_context(iov, &n_iov, oparms->mode, set_owner);
+			rc = add_sd_context(req, iov, &n_iov, oparms->mode,
+					    set_owner);
 			if (rc)
 				return rc;
 		}
-- 
2.30.2


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

* [PATCH 5/7] cifs: Avoid a cast in add_durable_v2_context()
  2023-03-17 11:15 [PATCH 0/7] Avoid a few casts from void * Volker Lendecke
                   ` (3 preceding siblings ...)
  2023-03-17 11:15 ` [PATCH 4/7] cifs: Avoid a cast in add_sd_context() Volker Lendecke
@ 2023-03-17 11:15 ` Volker Lendecke
  2023-03-17 11:15 ` [PATCH 6/7] cifs: Avoid a cast in add_durable_reconnect_v2_context() Volker Lendecke
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Volker Lendecke @ 2023-03-17 11:15 UTC (permalink / raw)
  To: linux-cifs; +Cc: Volker Lendecke

We have the correctly-typed struct smb2_create_req * available in the
caller.

Signed-off-by: Volker Lendecke <vl@samba.org>
---
 fs/cifs/smb2pdu.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 91fc0ad3e1b4..6d4a14efa79f 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -2241,10 +2241,10 @@ create_reconnect_durable_v2_buf(struct cifs_fid *fid)
 }
 
 static int
-add_durable_v2_context(struct kvec *iov, unsigned int *num_iovec,
+add_durable_v2_context(struct smb2_create_req *req,
+		       struct kvec *iov, unsigned int *num_iovec,
 		    struct cifs_open_parms *oparms)
 {
-	struct smb2_create_req *req = iov[0].iov_base;
 	unsigned int num = *num_iovec;
 
 	iov[num].iov_base = create_durable_v2_buf(oparms);
@@ -2296,7 +2296,8 @@ add_durable_context(struct smb2_create_req *req,
 			return add_durable_reconnect_v2_context(iov, num_iovec,
 								oparms);
 		else
-			return add_durable_v2_context(iov, num_iovec, oparms);
+			return add_durable_v2_context(req, iov, num_iovec,
+						      oparms);
 	}
 
 	if (oparms->reconnect) {
-- 
2.30.2


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

* [PATCH 6/7] cifs: Avoid a cast in add_durable_reconnect_v2_context()
  2023-03-17 11:15 [PATCH 0/7] Avoid a few casts from void * Volker Lendecke
                   ` (4 preceding siblings ...)
  2023-03-17 11:15 ` [PATCH 5/7] cifs: Avoid a cast in add_durable_v2_context() Volker Lendecke
@ 2023-03-17 11:15 ` Volker Lendecke
  2023-03-17 11:15 ` [PATCH 7/7] cifs: Avoid a cast in add_query_id_context() Volker Lendecke
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Volker Lendecke @ 2023-03-17 11:15 UTC (permalink / raw)
  To: linux-cifs; +Cc: Volker Lendecke

We have the correctly-typed struct smb2_create_req * available in the
caller.

Signed-off-by: Volker Lendecke <vl@samba.org>
---
 fs/cifs/smb2pdu.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 6d4a14efa79f..9e9267da28a2 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -2261,10 +2261,10 @@ add_durable_v2_context(struct smb2_create_req *req,
 }
 
 static int
-add_durable_reconnect_v2_context(struct kvec *iov, unsigned int *num_iovec,
+add_durable_reconnect_v2_context(struct smb2_create_req *req,
+				 struct kvec *iov, unsigned int *num_iovec,
 		    struct cifs_open_parms *oparms)
 {
-	struct smb2_create_req *req = iov[0].iov_base;
 	unsigned int num = *num_iovec;
 
 	/* indicate that we don't need to relock the file */
@@ -2293,7 +2293,8 @@ add_durable_context(struct smb2_create_req *req,
 
 	if (use_persistent) {
 		if (oparms->reconnect)
-			return add_durable_reconnect_v2_context(iov, num_iovec,
+			return add_durable_reconnect_v2_context(req,
+								iov, num_iovec,
 								oparms);
 		else
 			return add_durable_v2_context(req, iov, num_iovec,
-- 
2.30.2


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

* [PATCH 7/7] cifs: Avoid a cast in add_query_id_context()
  2023-03-17 11:15 [PATCH 0/7] Avoid a few casts from void * Volker Lendecke
                   ` (5 preceding siblings ...)
  2023-03-17 11:15 ` [PATCH 6/7] cifs: Avoid a cast in add_durable_reconnect_v2_context() Volker Lendecke
@ 2023-03-17 11:15 ` Volker Lendecke
  2023-03-27 14:56 ` [PATCH 0/7] Avoid a few casts from void * Ralph Boehme
  2023-04-24  2:22 ` Steve French
  8 siblings, 0 replies; 10+ messages in thread
From: Volker Lendecke @ 2023-03-17 11:15 UTC (permalink / raw)
  To: linux-cifs; +Cc: Volker Lendecke

We have the correctly-typed struct smb2_create_req * available in the
caller.

Signed-off-by: Volker Lendecke <vl@samba.org>
---
 fs/cifs/smb2pdu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 9e9267da28a2..2ea7e211391f 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -2524,9 +2524,9 @@ create_query_id_buf(void)
 
 /* See MS-SMB2 2.2.13.2.9 */
 static int
-add_query_id_context(struct kvec *iov, unsigned int *num_iovec)
+add_query_id_context(struct smb2_create_req *req,
+		     struct kvec *iov, unsigned int *num_iovec)
 {
-	struct smb2_create_req *req = iov[0].iov_base;
 	unsigned int num = *num_iovec;
 
 	iov[num].iov_base = create_query_id_buf();
@@ -2922,7 +2922,7 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server,
 			(struct create_context *)iov[n_iov-1].iov_base;
 		ccontext->Next = cpu_to_le32(iov[n_iov-1].iov_len);
 	}
-	add_query_id_context(iov, &n_iov);
+	add_query_id_context(req, iov, &n_iov);
 
 	rqst->rq_nvec = n_iov;
 	return 0;
-- 
2.30.2


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

* Re: [PATCH 0/7] Avoid a few casts from void *
  2023-03-17 11:15 [PATCH 0/7] Avoid a few casts from void * Volker Lendecke
                   ` (6 preceding siblings ...)
  2023-03-17 11:15 ` [PATCH 7/7] cifs: Avoid a cast in add_query_id_context() Volker Lendecke
@ 2023-03-27 14:56 ` Ralph Boehme
  2023-04-24  2:22 ` Steve French
  8 siblings, 0 replies; 10+ messages in thread
From: Ralph Boehme @ 2023-03-27 14:56 UTC (permalink / raw)
  To: Volker Lendecke, linux-cifs


[-- Attachment #1.1: Type: text/plain, Size: 722 bytes --]

On 3/17/23 12:15, Volker Lendecke wrote:
> We should not go through void * without type-checking if it's not
> really necessary.
> 
> Volker Lendecke (7):
>    cifs: Avoid a cast in add_lease_context()
>    cifs: Avoid a cast in add_durable_context()
>    cifs: Avoid a cast in add_posix_context()
>    cifs: Avoid a cast in add_sd_context()
>    cifs: Avoid a cast in add_durable_v2_context()
>    cifs: Avoid a cast in add_durable_reconnect_v2_context()
>    cifs: Avoid a cast in add_query_id_context()
> 
>   fs/cifs/smb2pdu.c | 55 ++++++++++++++++++++++++++---------------------
>   1 file changed, 30 insertions(+), 25 deletions(-)
> 

Reviewed-by Ralph Boehme <slow@samba.org>

Thanks!
-slow


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

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

* Re: [PATCH 0/7] Avoid a few casts from void *
  2023-03-17 11:15 [PATCH 0/7] Avoid a few casts from void * Volker Lendecke
                   ` (7 preceding siblings ...)
  2023-03-27 14:56 ` [PATCH 0/7] Avoid a few casts from void * Ralph Boehme
@ 2023-04-24  2:22 ` Steve French
  8 siblings, 0 replies; 10+ messages in thread
From: Steve French @ 2023-04-24  2:22 UTC (permalink / raw)
  To: Volker Lendecke; +Cc: linux-cifs, Ralph Böhme

I merged patch one of this series but looks like the other ones were
obsoleted by the other three cleanup patches you did for
SMB2_open_init.  Let me know about patches I may have missed, as we
get this updated for the merge window

On Fri, Mar 17, 2023 at 6:19 AM Volker Lendecke <vl@samba.org> wrote:
>
> We should not go through void * without type-checking if it's not
> really necessary.
>
> Volker Lendecke (7):
>   cifs: Avoid a cast in add_lease_context()
>   cifs: Avoid a cast in add_durable_context()
>   cifs: Avoid a cast in add_posix_context()
>   cifs: Avoid a cast in add_sd_context()
>   cifs: Avoid a cast in add_durable_v2_context()
>   cifs: Avoid a cast in add_durable_reconnect_v2_context()
>   cifs: Avoid a cast in add_query_id_context()
>
>  fs/cifs/smb2pdu.c | 55 ++++++++++++++++++++++++++---------------------
>  1 file changed, 30 insertions(+), 25 deletions(-)
>
> --
> 2.30.2
>


-- 
Thanks,

Steve

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

end of thread, other threads:[~2023-04-24  2:22 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-17 11:15 [PATCH 0/7] Avoid a few casts from void * Volker Lendecke
2023-03-17 11:15 ` [PATCH 1/7] cifs: Avoid a cast in add_lease_context() Volker Lendecke
2023-03-17 11:15 ` [PATCH 2/7] cifs: Avoid a cast in add_durable_context() Volker Lendecke
2023-03-17 11:15 ` [PATCH 3/7] cifs: Avoid a cast in add_posix_context() Volker Lendecke
2023-03-17 11:15 ` [PATCH 4/7] cifs: Avoid a cast in add_sd_context() Volker Lendecke
2023-03-17 11:15 ` [PATCH 5/7] cifs: Avoid a cast in add_durable_v2_context() Volker Lendecke
2023-03-17 11:15 ` [PATCH 6/7] cifs: Avoid a cast in add_durable_reconnect_v2_context() Volker Lendecke
2023-03-17 11:15 ` [PATCH 7/7] cifs: Avoid a cast in add_query_id_context() Volker Lendecke
2023-03-27 14:56 ` [PATCH 0/7] Avoid a few casts from void * Ralph Boehme
2023-04-24  2:22 ` Steve French

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).