switch netlink_getsockbyfilp() to taking descriptor

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>
This commit is contained in:
Al Viro 2024-07-14 21:49:04 -04:00
parent 4dd53b84ff
commit f302edb9d8
3 changed files with 9 additions and 10 deletions

View File

@ -239,7 +239,7 @@ int netlink_register_notifier(struct notifier_block *nb);
int netlink_unregister_notifier(struct notifier_block *nb); int netlink_unregister_notifier(struct notifier_block *nb);
/* finegrained unicast helpers: */ /* 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, int netlink_attachskb(struct sock *sk, struct sk_buff *skb,
long *timeo, struct sock *ssk); long *timeo, struct sock *ssk);
void netlink_detachskb(struct sock *sk, struct sk_buff *skb); void netlink_detachskb(struct sock *sk, struct sk_buff *skb);

View File

@ -1355,13 +1355,7 @@ static int do_mq_notify(mqd_t mqdes, const struct sigevent *notification)
skb_put(nc, NOTIFY_COOKIE_LEN); skb_put(nc, NOTIFY_COOKIE_LEN);
/* and attach it to the socket */ /* and attach it to the socket */
retry: retry:
f = fdget(notification->sigev_signo); sock = netlink_getsockbyfd(notification->sigev_signo);
if (!fd_file(f)) {
ret = -EBADF;
goto out;
}
sock = netlink_getsockbyfilp(fd_file(f));
fdput(f);
if (IS_ERR(sock)) { if (IS_ERR(sock)) {
ret = PTR_ERR(sock); ret = PTR_ERR(sock);
goto free_skb; goto free_skb;

View File

@ -1180,11 +1180,16 @@ static struct sock *netlink_getsockbyportid(struct sock *ssk, u32 portid)
return sock; 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; struct sock *sock;
if (fd_empty(f))
return ERR_PTR(-EBADF);
inode = file_inode(fd_file(f));
if (!S_ISSOCK(inode->i_mode)) if (!S_ISSOCK(inode->i_mode))
return ERR_PTR(-ENOTSOCK); return ERR_PTR(-ENOTSOCK);