Skip to content

Commit d2ec43b

Browse files
vlendecsmfrench
authored andcommitted
cifs: Simplify SMB2_open_init()
Reduce code duplication by calculating req->CreateContextsLength in one place. This is the last reference to "req" in the add_*_context functions, remove that parameter. Signed-off-by: Volker Lendecke <[email protected]> Reviewed-by: Enzo Matsumiya <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 2a8d138 commit d2ec43b

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

fs/cifs/smb2pdu.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,6 @@ create_posix_buf(umode_t mode)
821821
static int
822822
add_posix_context(struct kvec *iov, unsigned int *num_iovec, umode_t mode)
823823
{
824-
struct smb2_create_req *req = iov[0].iov_base;
825824
unsigned int num = *num_iovec;
826825

827826
iov[num].iov_base = create_posix_buf(mode);
@@ -830,7 +829,6 @@ add_posix_context(struct kvec *iov, unsigned int *num_iovec, umode_t mode)
830829
if (iov[num].iov_base == NULL)
831830
return -ENOMEM;
832831
iov[num].iov_len = sizeof(struct create_posix);
833-
le32_add_cpu(&req->CreateContextsLength, sizeof(struct create_posix));
834832
*num_iovec = num + 1;
835833
return 0;
836834
}
@@ -2179,8 +2177,6 @@ add_lease_context(struct TCP_Server_Info *server, struct kvec *iov,
21792177
return -ENOMEM;
21802178
iov[num].iov_len = server->vals->create_lease_size;
21812179
req->RequestedOplockLevel = SMB2_OPLOCK_LEVEL_LEASE;
2182-
le32_add_cpu(&req->CreateContextsLength,
2183-
server->vals->create_lease_size);
21842180
*num_iovec = num + 1;
21852181
return 0;
21862182
}
@@ -2259,14 +2255,12 @@ static int
22592255
add_durable_v2_context(struct kvec *iov, unsigned int *num_iovec,
22602256
struct cifs_open_parms *oparms)
22612257
{
2262-
struct smb2_create_req *req = iov[0].iov_base;
22632258
unsigned int num = *num_iovec;
22642259

22652260
iov[num].iov_base = create_durable_v2_buf(oparms);
22662261
if (iov[num].iov_base == NULL)
22672262
return -ENOMEM;
22682263
iov[num].iov_len = sizeof(struct create_durable_v2);
2269-
le32_add_cpu(&req->CreateContextsLength, sizeof(struct create_durable_v2));
22702264
*num_iovec = num + 1;
22712265
return 0;
22722266
}
@@ -2275,7 +2269,6 @@ static int
22752269
add_durable_reconnect_v2_context(struct kvec *iov, unsigned int *num_iovec,
22762270
struct cifs_open_parms *oparms)
22772271
{
2278-
struct smb2_create_req *req = iov[0].iov_base;
22792272
unsigned int num = *num_iovec;
22802273

22812274
/* indicate that we don't need to relock the file */
@@ -2285,8 +2278,6 @@ add_durable_reconnect_v2_context(struct kvec *iov, unsigned int *num_iovec,
22852278
if (iov[num].iov_base == NULL)
22862279
return -ENOMEM;
22872280
iov[num].iov_len = sizeof(struct create_durable_handle_reconnect_v2);
2288-
le32_add_cpu(&req->CreateContextsLength,
2289-
sizeof(struct create_durable_handle_reconnect_v2));
22902281
*num_iovec = num + 1;
22912282
return 0;
22922283
}
@@ -2295,7 +2286,6 @@ static int
22952286
add_durable_context(struct kvec *iov, unsigned int *num_iovec,
22962287
struct cifs_open_parms *oparms, bool use_persistent)
22972288
{
2298-
struct smb2_create_req *req = iov[0].iov_base;
22992289
unsigned int num = *num_iovec;
23002290

23012291
if (use_persistent) {
@@ -2315,7 +2305,6 @@ add_durable_context(struct kvec *iov, unsigned int *num_iovec,
23152305
if (iov[num].iov_base == NULL)
23162306
return -ENOMEM;
23172307
iov[num].iov_len = sizeof(struct create_durable);
2318-
le32_add_cpu(&req->CreateContextsLength, sizeof(struct create_durable));
23192308
*num_iovec = num + 1;
23202309
return 0;
23212310
}
@@ -2349,14 +2338,12 @@ create_twarp_buf(__u64 timewarp)
23492338
static int
23502339
add_twarp_context(struct kvec *iov, unsigned int *num_iovec, __u64 timewarp)
23512340
{
2352-
struct smb2_create_req *req = iov[0].iov_base;
23532341
unsigned int num = *num_iovec;
23542342

23552343
iov[num].iov_base = create_twarp_buf(timewarp);
23562344
if (iov[num].iov_base == NULL)
23572345
return -ENOMEM;
23582346
iov[num].iov_len = sizeof(struct crt_twarp_ctxt);
2359-
le32_add_cpu(&req->CreateContextsLength, sizeof(struct crt_twarp_ctxt));
23602347
*num_iovec = num + 1;
23612348
return 0;
23622349
}
@@ -2479,15 +2466,13 @@ create_sd_buf(umode_t mode, bool set_owner, unsigned int *len)
24792466
static int
24802467
add_sd_context(struct kvec *iov, unsigned int *num_iovec, umode_t mode, bool set_owner)
24812468
{
2482-
struct smb2_create_req *req = iov[0].iov_base;
24832469
unsigned int num = *num_iovec;
24842470
unsigned int len = 0;
24852471

24862472
iov[num].iov_base = create_sd_buf(mode, set_owner, &len);
24872473
if (iov[num].iov_base == NULL)
24882474
return -ENOMEM;
24892475
iov[num].iov_len = len;
2490-
le32_add_cpu(&req->CreateContextsLength, len);
24912476
*num_iovec = num + 1;
24922477
return 0;
24932478
}
@@ -2518,14 +2503,12 @@ create_query_id_buf(void)
25182503
static int
25192504
add_query_id_context(struct kvec *iov, unsigned int *num_iovec)
25202505
{
2521-
struct smb2_create_req *req = iov[0].iov_base;
25222506
unsigned int num = *num_iovec;
25232507

25242508
iov[num].iov_base = create_query_id_buf();
25252509
if (iov[num].iov_base == NULL)
25262510
return -ENOMEM;
25272511
iov[num].iov_len = sizeof(struct crt_query_id_ctxt);
2528-
le32_add_cpu(&req->CreateContextsLength, sizeof(struct crt_query_id_ctxt));
25292512
*num_iovec = num + 1;
25302513
return 0;
25312514
}
@@ -2889,6 +2872,7 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server,
28892872
req->CreateContextsOffset = cpu_to_le32(
28902873
sizeof(struct smb2_create_req) +
28912874
iov[1].iov_len);
2875+
req->CreateContextsLength = 0;
28922876

28932877
for (unsigned int i = 2; i < (n_iov-1); i++) {
28942878
struct kvec *v = &iov[i];
@@ -2897,7 +2881,10 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server,
28972881
(struct create_context *)v->iov_base;
28982882

28992883
cctx->Next = cpu_to_le32(len);
2884+
le32_add_cpu(&req->CreateContextsLength, len);
29002885
}
2886+
le32_add_cpu(&req->CreateContextsLength,
2887+
iov[n_iov-1].iov_len);
29012888
}
29022889

29032890
rqst->rq_nvec = n_iov;

0 commit comments

Comments
 (0)