#include "greybus.h"
 
-/*
- * The top bit of the type in an operation message header indicates
- * whether the message is a request (bit clear) or response (bit set)
- */
-#define GB_OPERATION_TYPE_RESPONSE     0x80
-
 #define OPERATION_TIMEOUT_DEFAULT      1000    /* milliseconds */
 
 /*
         * 0x00.  Such buffers will be overwritten by arriving data
         * so there's no need to initialize the message header.
         */
-       if (type) {
+       if (type != GB_OPERATION_TYPE_INVALID) {
                /*
                 * For a request, the operation id gets filled in
                 * when the message is sent.  For a response, it
 {
        struct greybus_host_device *hd = connection->hd;
        struct gb_operation *operation;
-       gfp_t gfp_flags = type ? GFP_KERNEL : GFP_ATOMIC;
+       gfp_t gfp_flags;
 
+       /*
+        * An incoming request will pass an invalid operation type,
+        * because the header will get overwritten anyway.  These
+        * occur in interrupt context, so we must use GFP_ATOMIC.
+        */
+       if (type == GB_OPERATION_TYPE_INVALID)
+               gfp_flags = GFP_ATOMIC;
+       else
+               gfp_flags = GFP_KERNEL;
        operation = kmem_cache_zalloc(gb_operation_cache, gfp_flags);
        if (!operation)
                return NULL;
        operation->request->operation = operation;
 
        /* Allocate the response buffer for outgoing operations */
-       if (type)
+       if (type != GB_OPERATION_TYPE_INVALID)
                if (!gb_operation_response_alloc(operation, response_size))
                        goto err_request;
        operation->errno = -EBADR;  /* Initial value--means "never set" */
                                        u8 type, size_t request_size,
                                        size_t response_size)
 {
-       if (WARN_ON_ONCE(!type))
+       if (WARN_ON_ONCE(type == GB_OPERATION_TYPE_INVALID))
                return NULL;
        if (WARN_ON_ONCE(type & GB_OPERATION_TYPE_RESPONSE))
                type &= ~GB_OPERATION_TYPE_RESPONSE;
 {
        struct gb_operation *operation;
 
-       operation = gb_operation_create_common(connection, 0, request_size, 0);
+       operation = gb_operation_create_common(connection,
+                                       GB_OPERATION_TYPE_INVALID,
+                                       request_size, 0);
        if (operation) {
                operation->id = id;
                memcpy(operation->request->header, data, request_size);
 
 
 struct gb_operation;
 
+/*
+ * No protocol may define an operation that has numeric value 0x00.
+ * It is reserved as an explicitly invalid value.
+ */
+#define GB_OPERATION_TYPE_INVALID      ((u8)0x00)
+
+/*
+ * The top bit of the type in an operation message header indicates
+ * whether the message is a request (bit clear) or response (bit set)
+ */
+#define GB_OPERATION_TYPE_RESPONSE     ((u8)0x80)
+
 enum gb_operation_result {
        GB_OP_SUCCESS           = 0x00,
        GB_OP_INTERRUPTED       = 0x01,