Skip to content

Commit f302edb

Browse files
author
Al Viro
committed
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 <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 4dd53b8 commit f302edb

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

include/linux/netlink.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ int netlink_register_notifier(struct notifier_block *nb);
239239
int netlink_unregister_notifier(struct notifier_block *nb);
240240

241241
/* finegrained unicast helpers: */
242-
struct sock *netlink_getsockbyfilp(struct file *filp);
242+
struct sock *netlink_getsockbyfd(int fd);
243243
int netlink_attachskb(struct sock *sk, struct sk_buff *skb,
244244
long *timeo, struct sock *ssk);
245245
void netlink_detachskb(struct sock *sk, struct sk_buff *skb);

ipc/mqueue.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,13 +1355,7 @@ static int do_mq_notify(mqd_t mqdes, const struct sigevent *notification)
13551355
skb_put(nc, NOTIFY_COOKIE_LEN);
13561356
/* and attach it to the socket */
13571357
retry:
1358-
f = fdget(notification->sigev_signo);
1359-
if (!fd_file(f)) {
1360-
ret = -EBADF;
1361-
goto out;
1362-
}
1363-
sock = netlink_getsockbyfilp(fd_file(f));
1364-
fdput(f);
1358+
sock = netlink_getsockbyfd(notification->sigev_signo);
13651359
if (IS_ERR(sock)) {
13661360
ret = PTR_ERR(sock);
13671361
goto free_skb;

net/netlink/af_netlink.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,11 +1180,16 @@ static struct sock *netlink_getsockbyportid(struct sock *ssk, u32 portid)
11801180
return sock;
11811181
}
11821182

1183-
struct sock *netlink_getsockbyfilp(struct file *filp)
1183+
struct sock *netlink_getsockbyfd(int fd)
11841184
{
1185-
struct inode *inode = file_inode(filp);
1185+
CLASS(fd, f)(fd);
1186+
struct inode *inode;
11861187
struct sock *sock;
11871188

1189+
if (fd_empty(f))
1190+
return ERR_PTR(-EBADF);
1191+
1192+
inode = file_inode(fd_file(f));
11881193
if (!S_ISSOCK(inode->i_mode))
11891194
return ERR_PTR(-ENOTSOCK);
11901195

0 commit comments

Comments
 (0)