On 2/24/25 3:25 PM, Andrii Nakryiko wrote: > On Mon, Feb 24, 2025 at 3:15 PM Ihor Solodrai <ihor.solodrai@xxxxxxxxx> wrote: >> >> On 2/24/25 2:05 PM, Andrii Nakryiko wrote: >> >>> [...] >>> >>> arg_bitshift is stored as char (which could be signed), so that's why >>> you were getting signed division, just cast to unsigned and keep >>> division: >>> >>> return (64 - (unsigned)arg_spec->arg_bitshift) / 8; >> >> As it turns out, this doesn't work either. Presumably because >> (64 - (u8)x) is still a signed int. > > hm... ok, surprising, but fine > >> >> This works, however: >> >> return (unsigned char)(64 - arg_spec->arg_bitshift) / 8; >> > > > nit: just unsigned (int), BPF doesn't have single-byte division > anyways, so it will be upconverted to 32-bit (or 64-bit for noalu32). > So let's be bold and use 32-bits here ;) oh I specified a type because: $ ./scripts/checkpatch.pl /tmpfs/0001-libbpf-implement-bpf_usdt_arg_size-BPF-function.patch WARNING: Prefer 'unsigned int' to bare use of 'unsigned' #56: FILE: tools/lib/bpf/usdt.bpf.h:140: + return (64 - (unsigned)arg_spec->arg_bitshift) / 8; (unsigned int) it is then > >>> >>>> [...]