Skip to content

Commit 0046b33

Browse files
Marcelo Diop-Gonzalezgregkh
authored andcommitted
staging: vchiq: Refactor indentation in vchiq_dump_* functions
Doing this helps with readability, and makes the logic easier to follow. Signed-off-by: Marcelo Diop-Gonzalez <[email protected]> Reviewed-by: Nicolas Saenz Julienne <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 00d52fb commit 0046b33

File tree

1 file changed

+53
-51
lines changed
  • drivers/staging/vc04_services/interface/vchiq_arm

1 file changed

+53
-51
lines changed

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c

Lines changed: 53 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,40 +2076,40 @@ void
20762076
vchiq_dump(void *dump_context, const char *str, int len)
20772077
{
20782078
struct dump_context *context = (struct dump_context *)dump_context;
2079+
int copy_bytes;
20792080

2080-
if (context->actual < context->space) {
2081-
int copy_bytes;
2081+
if (context->actual >= context->space)
2082+
return;
20822083

2083-
if (context->offset > 0) {
2084-
int skip_bytes = min_t(int, len, context->offset);
2084+
if (context->offset > 0) {
2085+
int skip_bytes = min_t(int, len, context->offset);
20852086

2086-
str += skip_bytes;
2087-
len -= skip_bytes;
2088-
context->offset -= skip_bytes;
2089-
if (context->offset > 0)
2090-
return;
2091-
}
2092-
copy_bytes = min_t(int, len, context->space - context->actual);
2093-
if (copy_bytes == 0)
2087+
str += skip_bytes;
2088+
len -= skip_bytes;
2089+
context->offset -= skip_bytes;
2090+
if (context->offset > 0)
20942091
return;
2095-
if (copy_to_user(context->buf + context->actual, str,
2096-
copy_bytes))
2092+
}
2093+
copy_bytes = min_t(int, len, context->space - context->actual);
2094+
if (copy_bytes == 0)
2095+
return;
2096+
if (copy_to_user(context->buf + context->actual, str,
2097+
copy_bytes))
2098+
context->actual = -EFAULT;
2099+
context->actual += copy_bytes;
2100+
len -= copy_bytes;
2101+
2102+
/*
2103+
* If the terminating NUL is included in the length, then it
2104+
* marks the end of a line and should be replaced with a
2105+
* carriage return.
2106+
*/
2107+
if ((len == 0) && (str[copy_bytes - 1] == '\0')) {
2108+
char cr = '\n';
2109+
2110+
if (copy_to_user(context->buf + context->actual - 1,
2111+
&cr, 1))
20972112
context->actual = -EFAULT;
2098-
context->actual += copy_bytes;
2099-
len -= copy_bytes;
2100-
2101-
/*
2102-
* If the terminating NUL is included in the length, then it
2103-
* marks the end of a line and should be replaced with a
2104-
* carriage return.
2105-
*/
2106-
if ((len == 0) && (str[copy_bytes - 1] == '\0')) {
2107-
char cr = '\n';
2108-
2109-
if (copy_to_user(context->buf + context->actual - 1,
2110-
&cr, 1))
2111-
context->actual = -EFAULT;
2112-
}
21132113
}
21142114
}
21152115

@@ -2134,34 +2134,36 @@ vchiq_dump_platform_instances(void *dump_context)
21342134
struct vchiq_service *service = state->services[i];
21352135
struct vchiq_instance *instance;
21362136

2137-
if (service && (service->base.callback == service_callback)) {
2138-
instance = service->instance;
2139-
if (instance)
2140-
instance->mark = 0;
2141-
}
2137+
if (!service || service->base.callback != service_callback)
2138+
continue;
2139+
2140+
instance = service->instance;
2141+
if (instance)
2142+
instance->mark = 0;
21422143
}
21432144

21442145
for (i = 0; i < state->unused_service; i++) {
21452146
struct vchiq_service *service = state->services[i];
21462147
struct vchiq_instance *instance;
21472148

2148-
if (service && (service->base.callback == service_callback)) {
2149-
instance = service->instance;
2150-
if (instance && !instance->mark) {
2151-
len = snprintf(buf, sizeof(buf),
2152-
"Instance %pK: pid %d,%s completions %d/%d",
2153-
instance, instance->pid,
2154-
instance->connected ? " connected, " :
2155-
"",
2156-
instance->completion_insert -
2157-
instance->completion_remove,
2158-
MAX_COMPLETIONS);
2159-
2160-
vchiq_dump(dump_context, buf, len + 1);
2161-
2162-
instance->mark = 1;
2163-
}
2164-
}
2149+
if (!service || service->base.callback != service_callback)
2150+
continue;
2151+
2152+
instance = service->instance;
2153+
if (!instance || instance->mark)
2154+
continue;
2155+
2156+
len = snprintf(buf, sizeof(buf),
2157+
"Instance %pK: pid %d,%s completions %d/%d",
2158+
instance, instance->pid,
2159+
instance->connected ? " connected, " :
2160+
"",
2161+
instance->completion_insert -
2162+
instance->completion_remove,
2163+
MAX_COMPLETIONS);
2164+
2165+
vchiq_dump(dump_context, buf, len + 1);
2166+
instance->mark = 1;
21652167
}
21662168
}
21672169

0 commit comments

Comments
 (0)