return message;
}
+static void gb_operation_message_init(struct greybus_host_device *hd,
+ struct gb_message *message, u16 operation_id,
+ size_t message_size, u8 type)
+{
+ struct gb_operation_msg_hdr *header;
+ u8 *buffer;
+
+ BUG_ON(message_size < sizeof(*header));
+ buffer = &message->buffer[0];
+ header = (struct gb_operation_msg_hdr *)(buffer + hd->buffer_headroom);
+
+ message->header = header;
+ message->payload = header + 1;
+ message->size = message_size;
+
+ /*
+ * The type supplied for incoming message buffers will be
+ * 0x00. Such buffers will be overwritten by arriving data
+ * so there's no need to initialize the message header.
+ */
+ if (type) {
+ /*
+ * For a request, the operation id gets filled in
+ * when the message is sent. For a response, it
+ * will be copied from the request by the caller.
+ *
+ * The result field in a request message must be
+ * zero. It will be set just prior to sending for
+ * a response.
+ */
+ header->size = cpu_to_le16(message_size);
+ header->operation_id = 0;
+ header->type = type;
+ header->result = 0;
+ }
+}
+
/*
* Allocate a message to be used for an operation request or response.
* Both types of message contain a common header. The request message
struct gb_operation_msg_hdr *header;
size_t message_size = payload_size + sizeof(*header);
size_t size;
- u8 *buffer;
if (hd->buffer_size_max > GB_OPERATION_MESSAGE_SIZE_MAX) {
pr_warn("limiting buffer size to %u\n",
message = kzalloc(size, gfp_flags);
if (!message)
return NULL;
- buffer = &message->buffer[0];
- header = (struct gb_operation_msg_hdr *)(buffer + hd->buffer_headroom);
- message->header = header;
- message->payload = header + 1;
- message->size = message_size;
-
- /*
- * The type supplied for incoming message buffers will be
- * 0x00. Such buffers will be overwritten by arriving data
- * so there's no need to initialize the message header.
- */
- if (type) {
- /*
- * For a request, the operation id gets filled in
- * when the message is sent. For a response, it
- * will be copied from the request by the caller.
- *
- * The result field in a request message must be
- * zero. It will be set just prior to sending for
- * a response.
- */
- header->size = cpu_to_le16(message_size);
- header->operation_id = 0;
- header->type = type;
- header->result = 0;
- }
+ /* Initialize the message. Operation id is filled in later. */
+ gb_operation_message_init(hd, message, 0, message_size, type);
return message;
}