[PATCH 30/44] kdbus: Cleanup kdbus_meta_proc_mask()

From: Sergei Zviagintsev
Date: Thu Oct 08 2015 - 07:38:51 EST


- Simplify if-statements

'proc < KDBUS_META_PROC_NORMAL' test only makes sense when we call
kdbus_proc_permission(). Include it into 'prv_pid != req_pid' branch,
remove redundant assignment of `proc' var and reduce its scope.

- Drop redundant binary operation

In 'proc < KDBUS_META_PROC_NORMAL' case we firstly do
'wanted &= ~flags' and then 'wanted & flags' in the return statement,
which is the same as 'wanted & 0'. Return 0 instead.

- Cosmetic cleanup of the return statement.

Signed-off-by: Sergei Zviagintsev <sergei@xxxxxxxx>
---
ipc/kdbus/metadata.c | 32 ++++++++++++--------------------
1 file changed, 12 insertions(+), 20 deletions(-)

diff --git a/ipc/kdbus/metadata.c b/ipc/kdbus/metadata.c
index 61215a078359..b8d094d9fb56 100644
--- a/ipc/kdbus/metadata.c
+++ b/ipc/kdbus/metadata.c
@@ -1224,7 +1224,6 @@ static u64 kdbus_meta_proc_mask(struct pid *prv_pid,
u64 wanted)
{
struct pid_namespace *prv_ns, *req_ns;
- unsigned int proc;

prv_ns = ns_of_pid(prv_pid);
req_ns = ns_of_pid(req_pid);
@@ -1243,30 +1242,23 @@ static u64 kdbus_meta_proc_mask(struct pid *prv_pid,
* provider and requestor are the same. If not, we perform rather
* expensive /proc permission checks.
*/
- if (prv_pid == req_pid)
- proc = KDBUS_META_PROC_NORMAL;
- else
- proc = kdbus_proc_permission(req_ns, req_cred, prv_pid);
-
- /* you need /proc access to read standard process attributes */
- if (proc < KDBUS_META_PROC_NORMAL)
- wanted &= ~(KDBUS_ATTACH_TID_COMM |
- KDBUS_ATTACH_PID_COMM |
- KDBUS_ATTACH_SECLABEL |
- KDBUS_ATTACH_CMDLINE |
- KDBUS_ATTACH_CGROUP |
- KDBUS_ATTACH_AUDIT |
- KDBUS_ATTACH_CAPS |
- KDBUS_ATTACH_EXE);
+ if (prv_pid != req_pid) {
+ unsigned int proc = kdbus_proc_permission(req_ns, req_cred,
+ prv_pid);
+
+ /* you need /proc access to read standard process attributes */
+ if (proc < KDBUS_META_PROC_NORMAL)
+ return 0;
+ }

/* clear all non-/proc flags */
return wanted & (KDBUS_ATTACH_TID_COMM |
KDBUS_ATTACH_PID_COMM |
KDBUS_ATTACH_SECLABEL |
- KDBUS_ATTACH_CMDLINE |
- KDBUS_ATTACH_CGROUP |
- KDBUS_ATTACH_AUDIT |
- KDBUS_ATTACH_CAPS |
+ KDBUS_ATTACH_CMDLINE |
+ KDBUS_ATTACH_CGROUP |
+ KDBUS_ATTACH_AUDIT |
+ KDBUS_ATTACH_CAPS |
KDBUS_ATTACH_EXE);
}

--
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/