Skip to contentSkip to conversation

cifs: cifspdu.h: Replace one-element array with flexible-array member

PATCH Applied Gustavo A. R. Silva 4 participants 5 messages Mar 26, 2021 – Apr 9, 2021

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

PATCH 1/1 cifs: cifspdu.h: Replace one-element array with flexible-array member

There is a regular need in the kernel to provide a way to declare having a dynamically sized set of trailing elements in a structure. Kernel code should always use “flexible array members”[1] for these cases. The older style of one-element or zero-length arrays should no longer be used[2].

Also, this helps with the ongoing efforts to enable -Warray-bounds by fixing the following warning:

CC [M] fs/cifs/cifssmb.o
fs/cifs/cifssmb.c: In function ‘CIFSFindNext’:
fs/cifs/cifssmb.c:4636:23: warning: array subscript 1 is above array bounds of ‘char[1]’ [-Warray-bounds]

 4636 |   pSMB->ResumeFileName[name_len+1] = 0;
      |   ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~

[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.10/process/deprecated.html#zero-length-and-one-element-arrays

---
 fs/cifs/cifspdu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/cifspdu.h +1 -1
index 64fe5a47b5e8..475a517360e5 100644
@@ -1898,7 +1898,7 @@ typedef struct smb_com_transaction2_fnext_req {
 	__le16 InformationLevel;
 	__u32 ResumeKey;
 	__le16 SearchFlags;
-	char ResumeFileName[1];
+	char ResumeFileName[];
 } __attribute__((packed)) TRANSACTION2_FNEXT_REQ;
 
 typedef struct smb_com_transaction2_fnext_rsp {
Signature · 1 line
2.27.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Gustavo A. R. Silva

There is a regular need in the kernel to provide a way to declare having a dynamically sized set of trailing elements in a structure. Kernel code should always use “flexible array members”[1] for these cases. The older style of one-element or zero-length arrays should no longer be used[2].

I've checked the usages of the struct, looks OK (we don't allocate it directly, we use memory from the small/big buff pools).

Cheers,

Signature · 4 lines
Aurélien Aptel / SUSE Labs Samba Team
GPG: 1839 CB5F 9F5B FB9B AA97  8C99 03C8 A49B 521B D5D3
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg, DE
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 247165 (AG München)
#2 lore raw
Quoted 8 lines · Aurélien Aptel
Quoted 4 lines · Gustavo A. R. Silva

There is a regular need in the kernel to provide a way to declare having a dynamically sized set of trailing elements in a structure. Kernel code should always use “flexible array members”[1] for these cases. The older style of one-element or zero-length arrays should no longer be used[2].

I've checked the usages of the struct, looks OK (we don't allocate it directly, we use memory from the small/big buff pools).

Awesome. :)

Quoted 1 line

Thank you, Aurelien.
--
Gustavo

Applied
#3 lore raw

merged into cifs-2.6.git for-next

Quoted 20 lines · Gustavo A. R. Silva
Quoted 8 lines · Aurélien Aptel
Quoted 4 lines · Gustavo A. R. Silva

There is a regular need in the kernel to provide a way to declare having a dynamically sized set of trailing elements in a structure. Kernel code should always use “flexible array members”[1] for these cases. The older style of one-element or zero-length arrays should no longer be used[2].

I've checked the usages of the struct, looks OK (we don't allocate it directly, we use memory from the small/big buff pools).

Awesome. :)

Quoted 1 line

Thank you, Aurelien.
--
Gustavo

Signature · 3 lines
Thanks,

Steve
#4 lore raw
Quoted 1 line · Steve French

merged into cifs-2.6.git for-next

Great. :)

Thanks, Steve.

--
Gustavo