Re: [RFC 01/14] android: Add HAL IPC commands sanity check

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Szymon,

On Wed, Nov 06, 2013, Szymon Janc wrote:
> +#define check_no_p(opcode) \
> +	case opcode: \
> +		return len == 0;
> +
> +#define check_fix_p(opcode, msg) \
> +	case opcode: \
> +		return len == sizeof(struct msg);
> +
> +#define check_var_p(opcode, msg, mp_len_name) \
> +	case opcode: \
> +	{ \
> +		const struct msg *mp = (const struct msg *) payload; \
> +		return len == (sizeof(*mp) + mp->mp_len_name); \
> +	}
> +
> +#define check_props_p(opcode, msg) \
> +	case opcode: \
> +	{ \
> +		const struct msg *mp = (const struct msg *) payload; \
> +		const struct hal_property *hp = mp->props; \
> +		const void *p = mp->props; \
> +		int i; \
> +		for (i = 0; i < mp->num_props; i++) { \
> +			if ((void *) (p + sizeof(*hp) + hp->len) > \
> +					(void *) (payload + len)) \
> +				return false; \
> +			p += sizeof(*hp) + hp->len; \
> +			hp = p; \
> +		} \
> +		return p == payload + len; \
> +	}
> +
> +static bool check_cmd_core(uint8_t opcode, const void *payload,
> +								uint16_t len)
> +{
> +	switch (opcode) {
> +	check_fix_p(HAL_OP_REGISTER_MODULE, hal_cmd_register_module);
> +	check_fix_p(HAL_OP_UNREGISTER_MODULE, hal_cmd_unregister_module);
> +	default:
> +		return false;
> +	}
> +}

I have a feeling that this kind of approach will eventually not be very
readable/maintainable. Have you looked at how this kind of stuff is
generalized using a simple table, e.g. in btmon or the kernel mgmt
command parsing code?

Johan
--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux