linux/net/llc
Avinash Duduskar 3931012141 llc: avoid sparse cast-truncates warning in counter clamps
llc_conn_ac_inc_npta_value() and llc_conn_ac_inc_tx_win_size()
clamp their counters to the maximum valid 7-bit value via
(u8) ~LLC_2_SEQ_NBR_MODULO. LLC_2_SEQ_NBR_MODULO is defined as
((u8) 128) in include/net/llc_pdu.h, but the (u8) cast does not
prevent integer promotion of the operand of ~: ~128 is computed
as int (0xffffff7f), and the surrounding (u8) cast truncates
back to 0x7f. The result is correct (127), but the implicit
truncation is flagged by sparse:

  net/llc/llc_c_ac.c:1008:38: warning: cast truncates bits from
      constant value (ffffff7f becomes 7f)
  (and three more at lines 1009, 1099, 1100)

Replace the (u8) ~LLC_2_SEQ_NBR_MODULO expression with
LLC_2_SEQ_NBR_MODULO - 1, which evaluates to 127 directly and
silences sparse.

The same ~LLC_2_SEQ_NBR_MODULO pattern also appears in
include/net/llc_pdu.h:148 as part of PDU_GET_NEXT_Vr, but there
the result is immediately &-masked, so the int promotion is
harmless and sparse does not flag it; it is left alone.

This patch is the minimum diff to silence the warning. The
counter-clamp idiom itself could be modernized to
min_t(u8, ..., LLC_2_SEQ_NBR_MODULO - 1), but that is a
separate cleanup left for another patch.

No functional change.

Signed-off-by: Avinash Duduskar <avinash.duduskar@gmail.com>
Link: https://patch.msgid.link/20260513092253.3035961-1-avinash.duduskar@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2026-05-15 17:42:10 -07:00
..
af_llc.c llc: convert to getsockopt_iter 2026-05-10 10:11:08 -07:00
Kconfig net: remove redundant 'depends on NET' 2021-01-27 17:04:12 -08:00
llc_c_ac.c llc: avoid sparse cast-truncates warning in counter clamps 2026-05-15 17:42:10 -07:00
llc_c_ev.c net: llc: Correct some function names in header 2021-03-26 15:24:14 -07:00
llc_c_st.c llc: Constify struct llc_conn_state_trans 2024-07-15 08:51:01 -07:00
llc_conn.c treewide: Switch/rename to timer_delete[_sync]() 2025-04-05 10:30:12 +02:00
llc_core.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
llc_if.c llc: Check netns in llc_estab_match() and llc_listener_match(). 2023-07-20 10:46:28 +02:00
llc_input.c net: llc: reset skb->transport_header 2024-12-27 11:23:37 -08:00
llc_output.c llc/snap: constify dev_addr passing 2021-10-13 09:40:46 -07:00
llc_pdu.c net: llc: Correct function name llc_pdu_set_pf_bit() in header 2021-03-26 15:24:14 -07:00
llc_proc.c net: remove sock_i_uid() 2025-06-23 17:04:03 -07:00
llc_s_ac.c llc: do not use skb_get() before dev_queue_xmit() 2025-03-03 14:00:04 +00:00
llc_s_ev.c
llc_s_st.c llc: Constify struct llc_sap_state_trans 2024-07-15 08:51:19 -07:00
llc_sap.c llc: Constify struct llc_sap_state_trans 2024-07-15 08:51:19 -07:00
llc_station.c llc: verify mac len before reading mac header 2023-11-01 22:21:32 -07:00
Makefile llc: fix whitespace issues 2018-07-24 14:10:42 -07:00
sysctl_net_llc.c sysctl net: Remove macro checks for CONFIG_SYSCTL 2025-01-20 12:01:34 -08:00