[PATCH v3 2/6] Add GPIO ioctl decoding

Dmitry V. Levin ldv at altlinux.org
Sat Jan 23 00:33:12 UTC 2021


On Sat, Jan 23, 2021 at 08:04:01AM +0800, Kent Gibson wrote:
> Decode the GPIO character device ioctls first introduced in Linux v4.8,
> as well as those added in subsequent kernel releases up to Linux v5.7.
[...]
> +static int
> +print_gpiohandle_request(struct tcb *const tcp, const kernel_ulong_t arg)
> +{
> +	struct gpiohandle_request hr;
> +
> +	if (entering(tcp))
> +		tprints(", ");
> +	else if (syserror(tcp))
> +		return RVAL_IOCTL_DECODED;
> +	else
> +		tprints(" => ");
> +
> +	if (umove_or_printaddr(tcp, arg, &hr))
> +		return RVAL_IOCTL_DECODED;
> +
> +	if (!entering(tcp)) {
> +		/* exiting */

There is a macro called exiting() which means !entering(),
it can be used here and in other similar cases.

> +		PRINT_FIELD_FD("{", hr, fd, tcp);
> +		tprints("}");
> +		return RVAL_IOCTL_DECODED;
> +	}
> +
> +	/* entering */
> +	PRINT_FIELD_U("{", hr, lines);
> +	if (hr.lines > GPIOHANDLES_MAX)
> +		hr.lines = GPIOHANDLES_MAX;
> +	PRINT_FIELD_ARRAY_UPTO(", ", hr, lineoffsets, hr.lines, tcp,
> +			       print_uint32_array_member);
> +	PRINT_FIELD_FLAGS(", ", hr, flags, gpio_handle_flags,
> +			  "GPIOHANDLE_REQUEST_???");
> +	PRINT_FIELD_ARRAY_UPTO(", ", hr, default_values, hr.lines, tcp,
> +			       print_uint8_array_member);
> +	PRINT_FIELD_CSTRING(", ", hr, consumer_label);
> +	tprints("}");

PRINT_FIELD_ARRAY_UPTO already does the clamping, see the definition of
print_local_array_upto(), so hr.lines doesn't require additional checks.
This applies to all uses of PRINT_FIELD_ARRAY_UPTO.

Also, hr.lines is printed before other fields, while in the structure it's
one before the last.  It's usually a good idea to print fields in the
order they follow in their structure.


-- 
ldv


More information about the Strace-devel mailing list