The @skb argument only dereferences the &skb_shared_info pointer, so it doesn't need a writable pointer. Constify it to be able to pass const pointers to the code which uses this function and give the compilers a little more room for optimization. As an example, constify the @skb argument of tpacket_get_timestamp() and __packet_set_timestamp() of the AF_PACKET core code. There are lot more places in the kernel where the similar micro-opts can be done in the future. Signed-off-by: Alexander Lobakin <alexandr.lobakin@xxxxxxxxx> --- include/linux/skbuff.h | 3 ++- net/packet/af_packet.c | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 1c308511acbb..0a95f753c1d9 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -1617,7 +1617,8 @@ int skb_zerocopy_iter_stream(struct sock *sk, struct sk_buff *skb, /* Internal */ #define skb_shinfo(SKB) ((struct skb_shared_info *)(skb_end_pointer(SKB))) -static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb) +static inline struct skb_shared_hwtstamps * +skb_hwtstamps(const struct sk_buff *skb) { return &skb_shinfo(skb)->hwtstamps; } diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index d08c4728523b..20eac049e69e 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -449,10 +449,10 @@ static int __packet_get_status(const struct packet_sock *po, void *frame) } } -static __u32 tpacket_get_timestamp(struct sk_buff *skb, struct timespec64 *ts, - unsigned int flags) +static __u32 tpacket_get_timestamp(const struct sk_buff *skb, + struct timespec64 *ts, unsigned int flags) { - struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb); + const struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb); if (shhwtstamps && (flags & SOF_TIMESTAMPING_RAW_HARDWARE) && @@ -467,7 +467,7 @@ static __u32 tpacket_get_timestamp(struct sk_buff *skb, struct timespec64 *ts, } static __u32 __packet_set_timestamp(struct packet_sock *po, void *frame, - struct sk_buff *skb) + const struct sk_buff *skb) { union tpacket_uhdr h; struct timespec64 ts; -- 2.36.1