[PATCH 44/44] kdbus: Cleanup kdbus_gaps_install()

From: Sergei Zviagintsev
Date: Thu Oct 08 2015 - 07:35:00 EST


- Assign `false' to *out_incomplete directly on no-op cases.

- Initialize `ret' with zero during declaration instead of doing it in
the end of the function.

- Initialize `fd' and `memfd' vars during declaration to be more
concise.

Signed-off-by: Sergei Zviagintsev <sergei@xxxxxxxx>
---
ipc/kdbus/message.c | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/ipc/kdbus/message.c b/ipc/kdbus/message.c
index 75e6213e7ed5..ca20852f4ecf 100644
--- a/ipc/kdbus/message.c
+++ b/ipc/kdbus/message.c
@@ -124,18 +124,18 @@ int kdbus_gaps_install(struct kdbus_gaps *gaps, struct kdbus_pool_slice *slice,
bool incomplete_fds = false;
struct kvec kvec;
size_t i, n_fds, n_memfds;
- int ret, *fds;
+ int *fds, ret = 0;

if (!gaps) {
/* nothing to do */
- *out_incomplete = incomplete_fds;
+ *out_incomplete = false;
return 0;
}

n_fds = gaps->n_fds + gaps->n_memfds;
if (n_fds < 1) {
/* nothing to do */
- *out_incomplete = incomplete_fds;
+ *out_incomplete = false;
return 0;
}

@@ -148,9 +148,7 @@ int kdbus_gaps_install(struct kdbus_gaps *gaps, struct kdbus_pool_slice *slice,
n_fds = 0; /* n_fds now tracks the number of allocated fds */
if (gaps->n_fds > 0) {
for (i = 0; i < gaps->n_fds; ++i) {
- int fd;
-
- fd = get_unused_fd_flags(O_CLOEXEC);
+ int fd = get_unused_fd_flags(O_CLOEXEC);
if (fd < 0) {
incomplete_fds = true;
break;
@@ -183,9 +181,7 @@ int kdbus_gaps_install(struct kdbus_gaps *gaps, struct kdbus_pool_slice *slice,

n_memfds = 0;
for (i = 0; i < gaps->n_memfds && !incomplete_fds; ++i) {
- int memfd;
-
- memfd = get_unused_fd_flags(O_CLOEXEC);
+ int memfd = get_unused_fd_flags(O_CLOEXEC);
if (memfd < 0) {
incomplete_fds = true;
/* memfds are initialized to -1, skip copying it */
@@ -220,8 +216,6 @@ int kdbus_gaps_install(struct kdbus_gaps *gaps, struct kdbus_pool_slice *slice,
fd_install(fds[gaps->n_fds + i],
get_file(gaps->memfd_files[i]));

- ret = 0;
-
exit:
if (ret < 0) {
for (i = 0; i < n_fds; ++i)
--
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/