[LTP] [PATCH v2] uevent02: Make wait_for_uevents() order-independent

Cyril Hrubis chrubis@suse.cz
Thu Sep 3 16:42:21 CEST 2026


Hi!
>  static inline void wait_for_uevents(int fd, const struct uevent_desc *const uevents[])
>  {
> -	int i = 0;
> +	const struct uevent_desc *pending[UEVENT_MAX_PENDING];
> +	int i, cnt = 0, remaining;
> +
> +	while (uevents[cnt]) {
> +		if (cnt >= UEVENT_MAX_PENDING)
> +			tst_brk(TBROK, "Too many expected uevents, increase UEVENT_MAX_PENDING");
> +		pending[cnt] = uevents[cnt];
> +		cnt++;
> +	}
> +	remaining = cnt;

We can as well count the uevents[] first, then create the pending[]
array with the cnt. Also I would have used array of bitflags.


	while (uevents[cnt])
		cnt++;

	uint8_t not_pending[cnt] = {};

	...
		if (not_pending[i])
			continue;

		if (uevent_match(buf, len, uevents[i])) {
			not_pendig[i] = 1;
			...
		}

With that we avoid copying the pointers and static limit.

But that is largerly cosmetic changes.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list