[RFC,bpf-next,04/13] bpf: No need to check if id is 0

Message ID 20230326092208.13613-5-laoar.shao@gmail.com
State New
Headers
Series bpf: Introduce BPF namespace |

Commit Message

Yafang Shao March 26, 2023, 9:21 a.m. UTC
  idr_alloc_cyclic() will return -ENOSPC if there's no available IDs, so
don't need to check if the id is less than the start number.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 kernel/bpf/syscall.c | 7 -------
 1 file changed, 7 deletions(-)
  

Patch

diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index e18ac7f..f3664f2 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -387,9 +387,6 @@  static int bpf_map_alloc_id(struct bpf_map *map)
 	spin_unlock_bh(&map_idr_lock);
 	idr_preload_end();
 
-	if (WARN_ON_ONCE(!id))
-		return -ENOSPC;
-
 	return id > 0 ? 0 : id;
 }
 
@@ -2032,10 +2029,6 @@  static int bpf_prog_alloc_id(struct bpf_prog *prog)
 	spin_unlock_bh(&prog_idr_lock);
 	idr_preload_end();
 
-	/* id is in [1, INT_MAX) */
-	if (WARN_ON_ONCE(!id))
-		return -ENOSPC;
-
 	return id > 0 ? 0 : id;
 }