]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
greybus: operation: fix callback handling and documentation
authorJohan Hovold <johan@hovoldconsulting.com>
Fri, 27 Mar 2015 11:41:12 +0000 (12:41 +0100)
committerGreg Kroah-Hartman <greg@kroah.com>
Mon, 30 Mar 2015 13:10:06 +0000 (15:10 +0200)
Fix up obsolete comments referring to null callback pointers for
synchronous operations, and make sure a callback is always provided when
sending a request.

Also document that the callback is responsible for dropping the initial
(and not necessarily final) reference to the operation.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
drivers/staging/greybus/operation.c

index 41a3deb760feacf63a86bc9b4917fb5ae45a2bd2..c64b2bf47a43d12a6982404e90cde17de3d08692 100644 (file)
@@ -244,10 +244,9 @@ static void gb_operation_work(struct work_struct *work)
        struct gb_operation *operation;
 
        operation = container_of(work, struct gb_operation, work);
-       if (operation->callback) {
-               operation->callback(operation);
-               operation->callback = NULL;
-       }
+
+       operation->callback(operation);
+
        gb_operation_put(operation);
 }
 
@@ -526,7 +525,6 @@ gb_operation_create_common(struct gb_connection *connection, u8 type,
        operation->errno = -EBADR;  /* Initial value--means "never set" */
 
        INIT_WORK(&operation->work, gb_operation_work);
-       operation->callback = NULL;     /* set at submit time */
        init_completion(&operation->completion);
        kref_init(&operation->kref);
 
@@ -632,16 +630,12 @@ static void gb_operation_sync_callback(struct gb_operation *operation)
 }
 
 /*
- * Send an operation request message.  The caller has filled in
- * any payload so the request message is ready to go.  If non-null,
- * the callback function supplied will be called when the response
- * message has arrived indicating the operation is complete.  In
- * that case, the callback function is responsible for fetching the
- * result of the operation using gb_operation_result() if desired,
- * and dropping the final reference to (i.e., destroying) the
- * operation.  A null callback function is used for a synchronous
- * request; in that case return from this function won't occur until
- * the operation is complete.
+ * Send an operation request message. The caller has filled in any payload so
+ * the request message is ready to go. The callback function supplied will be
+ * called when the response message has arrived indicating the operation is
+ * complete. In that case, the callback function is responsible for fetching
+ * the result of the operation using gb_operation_result() if desired, and
+ * dropping the initial reference to the operation.
  */
 int gb_operation_request_send(struct gb_operation *operation,
                                gb_operation_callback callback)
@@ -650,6 +644,9 @@ int gb_operation_request_send(struct gb_operation *operation,
        struct gb_operation_msg_hdr *header;
        unsigned int cycle;
 
+       if (!callback)
+               return -EINVAL;
+
        if (connection->state != GB_CONNECTION_STATE_ENABLED)
                return -ENOTCONN;
 
@@ -805,10 +802,8 @@ static void gb_connection_recv_request(struct gb_connection *connection,
         * request handler to be the operation's callback function.
         *
         * The last thing the handler does is send a response
-        * message.  The callback function is then cleared (in
-        * gb_operation_work()).  The original reference to the
-        * operation will be dropped when the response has been
-        * sent.
+        * message. The original reference to the operation will be
+        * dropped when the response has been sent.
         */
        operation->callback = gb_operation_request_handle;
        if (gb_operation_result_set(operation, -EINPROGRESS))