ksmbd: ipc: use kzalloc_flex and __counted_by
Subsystems (2)
PATCH 1/1 ksmbd: ipc: use kzalloc_flex and __counted_by
The former is just a nice macro and the latter allows runtime analysis of the allocation and its size.
--- fs/smb/server/transport_ipc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
fs/smb/server/transport_ipc.c +2 -3
@@ -55,7 +55,7 @@ static bool ksmbd_ipc_validate_version(struct genl_info *m)struct ksmbd_ipc_msg {unsigned int type;unsigned int sz; -unsigned char payload[]; + unsigned char payload[] __counted_by(sz); };struct ipc_msg_table_entry {
@@ -242,9 +242,8 @@ static void ipc_update_last_active(void)static struct ksmbd_ipc_msg *ipc_msg_alloc (size_t sz) {struct ksmbd_ipc_msg *msg; -size_t msg_sz = sz +sizeof (struct ksmbd_ipc_msg ); - msg =kvzalloc (msg_sz,KSMBD_DEFAULT_GFP ); + msg =kvzalloc_flex (*msg, payload, sz,KSMBD_DEFAULT_GFP );if (msg) msg->sz = sz;return msg;
Signature · 1 line
2.53.0
Quoted 5 lines · Rosen Penev
The former is just a nice macro and the latter allows runtime analysis of the allocation and its size.
Signed-off-by Rosen Penev <[email protected]>
Applied it to #ksmbd-for-next-next.
Thanks!
Namjae Jeon
maintainerQuoted 23 lines · Rosen Penev
The former is just a nice macro and the latter allows runtime analysis of the allocation and its size.
Signed-off-by Rosen Penev <[email protected]>--- fs/smb/server/transport_ipc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)fs/smb/server/transport_ipc.c +1
-1@@ -55,7 +55,7 @@ static bool ksmbd_ipc_validate_version(struct genl_info *m)struct ksmbd_ipc_msg {unsigned int type;unsigned int sz; -unsigned char payload[]; + unsigned char payload[] __counted_by(sz); };struct ipc_msg_table_entry {
fs/smb/server/transport_ipc.c static void ipc_update_last_active(void) · line 248
Quoted 9 lines
fs/smb/server/transport_ipc.c +1
-2@@ -242,9 +242,8 @@ static void ipc_update_last_active(void)static struct ksmbd_ipc_msg *ipc_msg_alloc (size_t sz) {struct ksmbd_ipc_msg *msg; -size_t msg_sz = sz +sizeof (struct ksmbd_ipc_msg ); - msg =kvzalloc (msg_sz,KSMBD_DEFAULT_GFP ); + msg =kvzalloc_flex (*msg, payload, sz,KSMBD_DEFAULT_GFP );if (msg) msg->sz = sz;
We don't need to manually set msg->sz if the flexible array member is properly annotated with __counted_by(sz) ?kvmalloc_flex() automatically sets the counter via internal __set_flex_counter().
Quoted 30 lines · Namjae Jeon
Quoted 28 lines · Rosen Penev
The former is just a nice macro and the latter allows runtime analysis of the allocation and its size.
Signed-off-by Rosen Penev <[email protected]>--- fs/smb/server/transport_ipc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)fs/smb/server/transport_ipc.c +1
-2@@ -55,7 +55,7 @@ static bool ksmbd_ipc_validate_version(struct genl_info *m)struct ksmbd_ipc_msg {unsigned int type;unsigned int sz; -unsigned char payload[]; + unsigned char payload[] __counted_by(sz); };struct ipc_msg_table_entry {@@ -242,9 +242,8 @@ static void ipc_update_last_active(void)static struct ksmbd_ipc_msg *ipc_msg_alloc (size_t sz) {struct ksmbd_ipc_msg *msg; -size_t msg_sz = sz +sizeof (struct ksmbd_ipc_msg );
Quoted 8 lines
fs/smb/server/transport_ipc.c static void ipc_update_last_active(void) · line 248
Quoted 4 lines
fs/smb/server/transport_ipc.c +1
-1- msg =kvzalloc (msg_sz,KSMBD_DEFAULT_GFP ); + msg =kvzalloc_flex (*msg, payload, sz,KSMBD_DEFAULT_GFP );if (msg) msg->sz = sz;We don't need to manually set
msg->szif the flexible array member is properly annotated with__counted_by(sz)?kvmalloc_flex()automatically sets the counter via internal__set_flex_counter().
Needs GCC15.