diff mbox series

[net-next,v2,1/2] net: pass const to msg_data_left()

Message ID 20250407-tcpsendmsg-v2-1-9f0ea843ef99@debian.org (mailing list archive)
State Handled Elsewhere
Headers show
Series trace: add tracepoint to tcp_sendmsg_locked | expand

Commit Message

Breno Leitao April 7, 2025, 1:40 p.m. UTC
The msg_data_left() function doesn't modify the struct msghdr parameter,
so mark it as const. This allows the function to be used with const
references, improving type safety and making the API more flexible.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 include/linux/socket.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Kuniyuki Iwashima April 8, 2025, 12:53 a.m. UTC | #1
From: Breno Leitao <leitao@debian.org>
Date: Mon, 07 Apr 2025 06:40:43 -0700
> The msg_data_left() function doesn't modify the struct msghdr parameter,
> so mark it as const. This allows the function to be used with const
> references, improving type safety and making the API more flexible.
> 
> Signed-off-by: Breno Leitao <leitao@debian.org>

Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Eric Dumazet April 8, 2025, 2:20 p.m. UTC | #2
On Mon, Apr 7, 2025 at 3:40 PM Breno Leitao <leitao@debian.org> wrote:
>
> The msg_data_left() function doesn't modify the struct msghdr parameter,
> so mark it as const. This allows the function to be used with const
> references, improving type safety and making the API more flexible.
>
> Signed-off-by: Breno Leitao <leitao@debian.org>

Reviewed-by: Eric Dumazet <edumazet@google.com>
diff mbox series

Patch

diff --git a/include/linux/socket.h b/include/linux/socket.h
index c3322eb3d6865..3b262487ec060 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -168,7 +168,7 @@  static inline struct cmsghdr * cmsg_nxthdr (struct msghdr *__msg, struct cmsghdr
 	return __cmsg_nxthdr(__msg->msg_control, __msg->msg_controllen, __cmsg);
 }
 
-static inline size_t msg_data_left(struct msghdr *msg)
+static inline size_t msg_data_left(const struct msghdr *msg)
 {
 	return iov_iter_count(&msg->msg_iter);
 }