[PATCH 2/4] Drivers: hv: Support the newly introduced KVP messages in the driver

Dan Carpenter dan.carpenter at oracle.com
Sun Mar 11 10:42:31 UTC 2012


On Sat, Mar 10, 2012 at 03:32:09PM -0800, K. Y. Srinivasan wrote:
> +		switch (message->kvp_hdr.operation) {
> +		case KVP_OP_SET:
> +			switch (in_msg->body.kvp_set.data.value_type) {
> +			case REG_SZ:
> +				/*
> +				 * The value is a string - utf16 encoding.
> +				 */
> +				message->body.kvp_set.data.value_size =
> +				utf16s_to_utf8s(
> +				(wchar_t *)
> +				in_msg->body.kvp_set.data.value,
> +				in_msg->body.kvp_set.data.value_size,
> +				UTF16_LITTLE_ENDIAN,
> +				message->body.kvp_set.data.value,
> +				HV_KVP_EXCHANGE_MAX_VALUE_SIZE) + 1;
> +				break;
> +

This block of unreadable text is so nasty.

You could return directly if the msg = kmalloc() fails and pull
everything in one indent level.  It's normally more readable to
handle errors as soon as possible anyway.

Probably that's not enough to make a difference and we'd need to
introduce a new function.

Btw I don't know if utf16s_to_utf8s() counts the NUL char or not.
It feels like maybe we could end up with ->value_size equal to
HV_KVP_EXCHANGE_MAX_VALUE_SIZE + 1.

regards,
dan carpenter
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://driverdev.linuxdriverproject.org/pipermail/driverdev-devel/attachments/20120311/5d19eaec/attachment.asc>


More information about the devel mailing list