From: Matthew Wilcox <willy@infradead.org>
To: linmiaohe <linmiaohe@huawei.com>
Cc: Davide Libenzi <davidel@xmailserver.org>,
viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] fs: eventfd: fix obsolete comment
Date: Sat, 7 Dec 2019 09:01:39 -0800 [thread overview]
Message-ID: <20191207170139.GA32169@bombadil.infradead.org> (raw)
In-Reply-To: <1575704733-11573-1-git-send-email-linmiaohe@huawei.com>
On Sat, Dec 07, 2019 at 03:45:33PM +0800, linmiaohe wrote:
> From: Miaohe Lin <linmiaohe@huawei.com>
>
> since commit 36a7411724b1 ("eventfd_ctx_fdget(): use fdget() instead of
> fget()"), this comment become outdated and looks confusing. Fix it with
> the correct function name.
>
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
> fs/eventfd.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/eventfd.c b/fs/eventfd.c
> index 8aa0ea8c55e8..0b8466b12932 100644
> --- a/fs/eventfd.c
> +++ b/fs/eventfd.c
> @@ -352,7 +352,7 @@ EXPORT_SYMBOL_GPL(eventfd_fget);
> * Returns a pointer to the internal eventfd context, otherwise the error
> * pointers returned by the following functions:
> *
> - * eventfd_fget
> + * fdget
But this is wrong. The error pointer is returned from eventfd_ctx_fileget(),
not from fdget.
Looking at the three callers of eventfd_ctx_fileget(), I think it would
make sense to do this:
diff --git a/drivers/vfio/virqfd.c b/drivers/vfio/virqfd.c
index 997cb5d0a657..c35b614e3770 100644
--- a/drivers/vfio/virqfd.c
+++ b/drivers/vfio/virqfd.c
@@ -126,11 +126,6 @@ int vfio_virqfd_enable(void *opaque,
INIT_WORK(&virqfd->inject, virqfd_inject);
irqfd = fdget(fd);
- if (!irqfd.file) {
- ret = -EBADF;
- goto err_fd;
- }
-
ctx = eventfd_ctx_fileget(irqfd.file);
if (IS_ERR(ctx)) {
ret = PTR_ERR(ctx);
diff --git a/fs/eventfd.c b/fs/eventfd.c
index 8aa0ea8c55e8..d389ffd1dc07 100644
--- a/fs/eventfd.c
+++ b/fs/eventfd.c
@@ -349,17 +349,13 @@ EXPORT_SYMBOL_GPL(eventfd_fget);
* eventfd_ctx_fdget - Acquires a reference to the internal eventfd context.
* @fd: [in] Eventfd file descriptor.
*
- * Returns a pointer to the internal eventfd context, otherwise the error
- * pointers returned by the following functions:
- *
- * eventfd_fget
+ * Returns a pointer to the internal eventfd context, or an error pointer;
+ * see eventfd_ctx_fileget().
*/
struct eventfd_ctx *eventfd_ctx_fdget(int fd)
{
struct eventfd_ctx *ctx;
struct fd f = fdget(fd);
- if (!f.file)
- return ERR_PTR(-EBADF);
ctx = eventfd_ctx_fileget(f.file);
fdput(f);
return ctx;
@@ -368,17 +364,18 @@ EXPORT_SYMBOL_GPL(eventfd_ctx_fdget);
/**
* eventfd_ctx_fileget - Acquires a reference to the internal eventfd context.
- * @file: [in] Eventfd file pointer.
- *
- * Returns a pointer to the internal eventfd context, otherwise the error
- * pointer:
+ * @file: Eventfd file pointer.
*
- * -EINVAL : The @fd file descriptor is not an eventfd file.
+ * Return: A pointer to the internal eventfd context, or an error pointer:
+ * * -EBADF - The @file is NULL.
+ * * -EINVAL - The @file is not an eventfd file.
*/
struct eventfd_ctx *eventfd_ctx_fileget(struct file *file)
{
struct eventfd_ctx *ctx;
+ if (!file)
+ return ERR_PTR(-EBADF);
if (file->f_op != &eventfd_fops)
return ERR_PTR(-EINVAL);
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 01f3f8b665e9..74b45bc439d8 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4676,11 +4676,6 @@ static ssize_t memcg_write_event_control(struct kernfs_open_file *of,
INIT_WORK(&event->remove, memcg_event_remove);
efile = fdget(efd);
- if (!efile.file) {
- ret = -EBADF;
- goto out_kfree;
- }
-
event->eventfd = eventfd_ctx_fileget(efile.file);
if (IS_ERR(event->eventfd)) {
ret = PTR_ERR(event->eventfd);
diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
index 67b6fc153e9c..814b99c33d44 100644
--- a/virt/kvm/eventfd.c
+++ b/virt/kvm/eventfd.c
@@ -306,11 +306,6 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
seqcount_init(&irqfd->irq_entry_sc);
f = fdget(args->fd);
- if (!f.file) {
- ret = -EBADF;
- goto out;
- }
-
eventfd = eventfd_ctx_fileget(f.file);
if (IS_ERR(eventfd)) {
ret = PTR_ERR(eventfd);
(not even compile tested)
next prev parent reply other threads:[~2019-12-07 17:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-07 7:45 [PATCH] fs: eventfd: fix obsolete comment linmiaohe
2019-12-07 17:01 ` Matthew Wilcox [this message]
2019-12-09 2:44 linmiaohe
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=20191207170139.GA32169@bombadil.infradead.org \
--to=willy@infradead.org \
--cc=davidel@xmailserver.org \
--cc=linmiaohe@huawei.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.