Rely on the fd exit path machinery.

Signed-off-by: Christian Brauner (Amutable) <[email protected]>
---
 kernel/seccomp.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/kernel/seccomp.c b/kernel/seccomp.c
index 86cf4460d69e..dc275ab1e031 100644
--- a/kernel/seccomp.c
+++ b/kernel/seccomp.c
@@ -1957,7 +1957,7 @@ static long seccomp_set_mode_filter(unsigned int flags,
        const unsigned long seccomp_mode = SECCOMP_MODE_FILTER;
        struct seccomp_filter *prepared = NULL;
        long ret = -EINVAL;
-       int listener = -1;
+       const struct fd_slot *listener = NULL;
        struct file *listener_f = NULL;
 
        /* Validate flags. */
@@ -1990,15 +1990,14 @@ static long seccomp_set_mode_filter(unsigned int flags,
                return PTR_ERR(prepared);
 
        if (flags & SECCOMP_FILTER_FLAG_NEW_LISTENER) {
-               listener = get_unused_fd_flags(O_CLOEXEC);
-               if (listener < 0) {
-                       ret = listener;
+               listener = fd_prepare(O_CLOEXEC);
+               if (IS_ERR(listener)) {
+                       ret = PTR_ERR(listener);
                        goto out_free;
                }
 
                listener_f = init_listener(prepared);
                if (IS_ERR(listener_f)) {
-                       put_unused_fd(listener);
                        ret = PTR_ERR(listener_f);
                        goto out_free;
                }
@@ -2038,11 +2037,9 @@ static long seccomp_set_mode_filter(unsigned int flags,
                if (ret) {
                        listener_f->private_data = NULL;
                        fput(listener_f);
-                       put_unused_fd(listener);
                        seccomp_notify_detach(prepared);
                } else {
-                       fd_install(listener, listener_f);
-                       ret = listener;
+                       ret = fd_stage(listener, listener_f);
                }
        }
 out_free:

-- 
2.53.0

Reply via email to