Skip to contentSkip to conversation

Avoid a few casts from void *

PATCH In review Volker Lendecke 3 participants 10 messages Mar 17, 2023 – Apr 24, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Avoid a few casts from void *

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(-)
Signature · 1 line
2.30.2
#1 lore raw

PATCH 1/7 cifs: Avoid a cast in add_lease_context()

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

---
 fs/cifs/smb2pdu.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
fs/cifs/smb2pdu.c +4 -3
index 0e53265e1462..3eb745237459 100644
@@ -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;
Signature · 1 line
2.30.2
#3 lore raw

PATCH 3/7 cifs: Avoid a cast in add_posix_context()

In reply to Volker Lendecke

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

---
 fs/cifs/smb2pdu.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/cifs/smb2pdu.c +4 -4
index cebb8d9837d2..6b6790d8d0ee 100644
@@ -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;
 	}
Signature · 1 line
2.30.2
#6 lore raw

PATCH 6/7 cifs: Avoid a cast in add_durable_reconnect_v2_context()

In reply to Volker Lendecke

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

---
 fs/cifs/smb2pdu.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
fs/cifs/smb2pdu.c +4 -3
index 6d4a14efa79f..9e9267da28a2 100644
@@ -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,
Signature · 1 line
2.30.2
#5 lore raw

PATCH 5/7 cifs: Avoid a cast in add_durable_v2_context()

In reply to Volker Lendecke

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

---
 fs/cifs/smb2pdu.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
fs/cifs/smb2pdu.c +4 -3
index 91fc0ad3e1b4..6d4a14efa79f 100644
@@ -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) {
Signature · 1 line
2.30.2
#7 lore raw

PATCH 7/7 cifs: Avoid a cast in add_query_id_context()

In reply to Volker Lendecke

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

---
 fs/cifs/smb2pdu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/cifs/smb2pdu.c +3 -3
index 9e9267da28a2..2ea7e211391f 100644
@@ -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;
Signature · 1 line
2.30.2
#2 lore raw

PATCH 2/7 cifs: Avoid a cast in add_durable_context()

In reply to Volker Lendecke

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

---
 fs/cifs/smb2pdu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/cifs/smb2pdu.c +3 -3
index 3eb745237459..cebb8d9837d2 100644
@@ -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;
Signature · 1 line
2.30.2
#4 lore raw

PATCH 4/7 cifs: Avoid a cast in add_sd_context()

In reply to Volker Lendecke

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

---
 fs/cifs/smb2pdu.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
fs/cifs/smb2pdu.c +8 -6
index 6b6790d8d0ee..91fc0ad3e1b4 100644
@@ -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;
 		}
Signature · 1 line
2.30.2
#8 lore raw
In reply to Volker Lendecke
Quoted 12 lines · 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()

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

Reviewed-by Ralph Boehme <[email protected]>

Thanks!
-slow

#9 lore raw
In reply to Volker Lendecke

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

Quoted 19 lines · 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

Signature · 3 lines
Thanks,

Steve