staging: vchiq: Refactor indentation in vchiq_dump_* functions
authorMarcelo Diop-Gonzalez <marcgonzalez@google.com>
Wed, 20 Nov 2019 20:21:01 +0000 (15:21 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 22 Nov 2019 10:40:31 +0000 (11:40 +0100)
Doing this helps with readability, and makes
the logic easier to follow.

Signed-off-by: Marcelo Diop-Gonzalez <marcgonzalez@google.com>
Reviewed-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Link: https://lore.kernel.org/r/20191120202102.249121-4-marcgonzalez@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c

index 942b476..8f9cfa0 100644 (file)
@@ -2076,40 +2076,40 @@ void
 vchiq_dump(void *dump_context, const char *str, int len)
 {
        struct dump_context *context = (struct dump_context *)dump_context;
+       int copy_bytes;
 
-       if (context->actual < context->space) {
-               int copy_bytes;
+       if (context->actual >= context->space)
+               return;
 
-               if (context->offset > 0) {
-                       int skip_bytes = min_t(int, len, context->offset);
+       if (context->offset > 0) {
+               int skip_bytes = min_t(int, len, context->offset);
 
-                       str += skip_bytes;
-                       len -= skip_bytes;
-                       context->offset -= skip_bytes;
-                       if (context->offset > 0)
-                               return;
-               }
-               copy_bytes = min_t(int, len, context->space - context->actual);
-               if (copy_bytes == 0)
+               str += skip_bytes;
+               len -= skip_bytes;
+               context->offset -= skip_bytes;
+               if (context->offset > 0)
                        return;
-               if (copy_to_user(context->buf + context->actual, str,
-                       copy_bytes))
+       }
+       copy_bytes = min_t(int, len, context->space - context->actual);
+       if (copy_bytes == 0)
+               return;
+       if (copy_to_user(context->buf + context->actual, str,
+                        copy_bytes))
+               context->actual = -EFAULT;
+       context->actual += copy_bytes;
+       len -= copy_bytes;
+
+       /*
+        * If the terminating NUL is included in the length, then it
+        * marks the end of a line and should be replaced with a
+        * carriage return.
+        */
+       if ((len == 0) && (str[copy_bytes - 1] == '\0')) {
+               char cr = '\n';
+
+               if (copy_to_user(context->buf + context->actual - 1,
+                                &cr, 1))
                        context->actual = -EFAULT;
-               context->actual += copy_bytes;
-               len -= copy_bytes;
-
-               /*
-                * If the terminating NUL is included in the length, then it
-                * marks the end of a line and should be replaced with a
-                * carriage return.
-                */
-               if ((len == 0) && (str[copy_bytes - 1] == '\0')) {
-                       char cr = '\n';
-
-                       if (copy_to_user(context->buf + context->actual - 1,
-                               &cr, 1))
-                               context->actual = -EFAULT;
-               }
        }
 }
 
@@ -2134,34 +2134,36 @@ vchiq_dump_platform_instances(void *dump_context)
                struct vchiq_service *service = state->services[i];
                struct vchiq_instance *instance;
 
-               if (service && (service->base.callback == service_callback)) {
-                       instance = service->instance;
-                       if (instance)
-                               instance->mark = 0;
-               }
+               if (!service || service->base.callback != service_callback)
+                       continue;
+
+               instance = service->instance;
+               if (instance)
+                       instance->mark = 0;
        }
 
        for (i = 0; i < state->unused_service; i++) {
                struct vchiq_service *service = state->services[i];
                struct vchiq_instance *instance;
 
-               if (service && (service->base.callback == service_callback)) {
-                       instance = service->instance;
-                       if (instance && !instance->mark) {
-                               len = snprintf(buf, sizeof(buf),
-                                       "Instance %pK: pid %d,%s completions %d/%d",
-                                       instance, instance->pid,
-                                       instance->connected ? " connected, " :
-                                               "",
-                                       instance->completion_insert -
-                                               instance->completion_remove,
-                                       MAX_COMPLETIONS);
-
-                               vchiq_dump(dump_context, buf, len + 1);
-
-                               instance->mark = 1;
-                       }
-               }
+               if (!service || service->base.callback != service_callback)
+                       continue;
+
+               instance = service->instance;
+               if (!instance || instance->mark)
+                       continue;
+
+               len = snprintf(buf, sizeof(buf),
+                              "Instance %pK: pid %d,%s completions %d/%d",
+                              instance, instance->pid,
+                              instance->connected ? " connected, " :
+                              "",
+                              instance->completion_insert -
+                              instance->completion_remove,
+                              MAX_COMPLETIONS);
+
+               vchiq_dump(dump_context, buf, len + 1);
+               instance->mark = 1;
        }
 }