]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
switch netlink_getsockbyfilp() to taking descriptor
authorAl Viro <viro@zeniv.linux.org.uk>
Mon, 15 Jul 2024 01:49:04 +0000 (21:49 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Sun, 3 Nov 2024 06:28:06 +0000 (01:28 -0500)
the only call site (in do_mq_notify()) obtains the argument
from an immediately preceding fdget() and it is immediately
followed by fdput(); might as well just replace it with
a variant that would take a descriptor instead of struct file *
and have file lookups handled inside that function.

Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
include/linux/netlink.h
ipc/mqueue.c
net/netlink/af_netlink.c

index b332c2048c75576cd265a2f7940d8cab715beacd..a48a30842d84288d8fd0dc371972662555e62137 100644 (file)
@@ -239,7 +239,7 @@ int netlink_register_notifier(struct notifier_block *nb);
 int netlink_unregister_notifier(struct notifier_block *nb);
 
 /* finegrained unicast helpers: */
-struct sock *netlink_getsockbyfilp(struct file *filp);
+struct sock *netlink_getsockbyfd(int fd);
 int netlink_attachskb(struct sock *sk, struct sk_buff *skb,
                      long *timeo, struct sock *ssk);
 void netlink_detachskb(struct sock *sk, struct sk_buff *skb);
index 34fa0bd8bb11a9d76b0c10392f0d418ce31c25e0..fd05e3d4f7b632ce15336dc0918ac1b549b40636 100644 (file)
@@ -1355,13 +1355,7 @@ static int do_mq_notify(mqd_t mqdes, const struct sigevent *notification)
                        skb_put(nc, NOTIFY_COOKIE_LEN);
                        /* and attach it to the socket */
 retry:
-                       f = fdget(notification->sigev_signo);
-                       if (!fd_file(f)) {
-                               ret = -EBADF;
-                               goto out;
-                       }
-                       sock = netlink_getsockbyfilp(fd_file(f));
-                       fdput(f);
+                       sock = netlink_getsockbyfd(notification->sigev_signo);
                        if (IS_ERR(sock)) {
                                ret = PTR_ERR(sock);
                                goto free_skb;
index 0b7a89db3ab74e13837ec697d0343cd9839f38b1..42451ac355d0e8fa57ee99d85f61deb3b00ef733 100644 (file)
@@ -1180,11 +1180,16 @@ static struct sock *netlink_getsockbyportid(struct sock *ssk, u32 portid)
        return sock;
 }
 
-struct sock *netlink_getsockbyfilp(struct file *filp)
+struct sock *netlink_getsockbyfd(int fd)
 {
-       struct inode *inode = file_inode(filp);
+       CLASS(fd, f)(fd);
+       struct inode *inode;
        struct sock *sock;
 
+       if (fd_empty(f))
+               return ERR_PTR(-EBADF);
+
+       inode = file_inode(fd_file(f));
        if (!S_ISSOCK(inode->i_mode))
                return ERR_PTR(-ENOTSOCK);