netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Al Viro <viro@zeniv.linux.org.uk>
To: ye.xingchen@zte.com.cn
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net: socket: Use fdget() and fdput()
Date: Thu, 11 May 2023 06:24:26 +0100	[thread overview]
Message-ID: <20230511052426.GH3390869@ZenIV> (raw)
In-Reply-To: <202305051706416319733@zte.com.cn>

On Fri, May 05, 2023 at 05:06:41PM +0800, ye.xingchen@zte.com.cn wrote:
> By using the fdget function, the socket object, can be quickly obtained
> from the process's file descriptor table without the need to obtain the
> file descriptor first before passing it as a parameter to the fget
> function.

>  struct socket *sockfd_lookup(int fd, int *err)
>  {
> -	struct file *file;
> +	struct fd f = fdget(fd);
>  	struct socket *sock;
> 
> -	file = fget(fd);
> -	if (!file) {
> +	if (!f.file) {
>  		*err = -EBADF;
>  		return NULL;
>  	}
> 
> -	sock = sock_from_file(file);
> +	sock = sock_from_file(f.file);
>  	if (!sock) {
>  		*err = -ENOTSOCK;
> -		fput(file);
> +		fdput(f);
>  	}
>  	return sock;

Suppose you've got that far.  If descriptor table had been shared, you've
bumped the refcount of struct file.  If it hadn't been, that refcount
had remained unchanged.  And there is no way for the caller of this
function to tell one outcome from another.

That can't work.

      parent reply	other threads:[~2023-05-11  5:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-05  9:06 [PATCH] net: socket: Use fdget() and fdput() ye.xingchen
2023-05-05 10:37 ` Eric Dumazet
2023-05-11  5:24 ` Al Viro [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230511052426.GH3390869@ZenIV \
    --to=viro@zeniv.linux.org.uk \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=ye.xingchen@zte.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).