Skip to contentSkip to conversation

kernel: capability: Remove unnecessary ‘0’ values from ret

PATCH In review Li zeming 2 participants 2 messages Dec 28, 2023 – Jan 10, 2024

Subsystems (2)
lore
Share & tools
lore

Li zeming

author
#0 lore raw

PATCH 1/1 kernel: capability: Remove unnecessary ‘0’ values from ret

The ret variable is assigned when it does not need to be defined, as it has already been assigned before use.

---
 kernel/capability.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/capability.c +1 -1
index dac4df77e376e..ed8a983e21da4 100644
@@ -140,7 +140,7 @@ static inline int cap_get_target_pid(pid_t pid, kernel_cap_t *pEp,
  */
 SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
 {
-	int ret = 0;
+	int ret;
 	pid_t pid;
 	unsigned tocopy;
 	kernel_cap_t pE, pI, pP;
Signature · 1 line
2.18.2
maintainer
#1 lore raw
Quoted 4 lines · Li zeming

The ret variable is assigned when it does not need to be defined, as it has already been assigned before use.

This is true, so the patch would fine now. But it has not always been the case, and a future patch could add code at the start which makes it no longer true. While I'd hope we would easily catch that, I'm just not sure it's worth it. In fact I'm curious - does the compiler recognize this situation and optimize the = 0 away?

Quoted 19 lines
---
 kernel/capability.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/capability.c +1 -1
index dac4df77e376e..ed8a983e21da4 100644
@@ -140,7 +140,7 @@ static inline int cap_get_target_pid(pid_t pid, kernel_cap_t *pEp,
  */
 SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
 {
-	int ret = 0;
+	int ret;
 	pid_t pid;
 	unsigned tocopy;
 	kernel_cap_t pE, pI, pP;
Signature · 1 line
2.18.2