greybus: operation: fix callback handling and documentation

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>
diff --git a/drivers/staging/greybus/operation.c b/drivers/staging/greybus/operation.c
index 41a3deb..c64b2bf 100644
--- a/drivers/staging/greybus/operation.c
+++ b/drivers/staging/greybus/operation.c
@@ -244,10 +244,9 @@
 	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 @@
 	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 @@
 }
 
 /*
- * 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 @@
 	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 @@
 	 * 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))