linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii@kernel.org>
To: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
	martin.lau@kernel.org
Cc: viro@kernel.org, linux-fsdevel@vger.kernel.org,
	brauner@kernel.org, torvalds@linux-foundation.org,
	Andrii Nakryiko <andrii@kernel.org>,
	Al Viro <viro@zeniv.linux.org.uk>
Subject: [PATCH bpf-next 2/8] bpf: switch fdget_raw() uses to CLASS(fd_raw, ...)
Date: Tue, 13 Aug 2024 16:02:54 -0700	[thread overview]
Message-ID: <20240813230300.915127-3-andrii@kernel.org> (raw)
In-Reply-To: <20240813230300.915127-1-andrii@kernel.org>

From: Al Viro <viro@zeniv.linux.org.uk>

Swith fdget_raw() use cases in bpf_inode_storage.c to CLASS(fd_raw).

Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 kernel/bpf/bpf_inode_storage.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/kernel/bpf/bpf_inode_storage.c b/kernel/bpf/bpf_inode_storage.c
index 0a79aee6523d..29da6d3838f6 100644
--- a/kernel/bpf/bpf_inode_storage.c
+++ b/kernel/bpf/bpf_inode_storage.c
@@ -78,13 +78,12 @@ void bpf_inode_storage_free(struct inode *inode)
 static void *bpf_fd_inode_storage_lookup_elem(struct bpf_map *map, void *key)
 {
 	struct bpf_local_storage_data *sdata;
-	struct fd f = fdget_raw(*(int *)key);
+	CLASS(fd_raw, f)(*(int *)key);
 
-	if (!fd_file(f))
+	if (fd_empty(f))
 		return ERR_PTR(-EBADF);
 
 	sdata = inode_storage_lookup(file_inode(fd_file(f)), map, true);
-	fdput(f);
 	return sdata ? sdata->data : NULL;
 }
 
@@ -92,19 +91,16 @@ static long bpf_fd_inode_storage_update_elem(struct bpf_map *map, void *key,
 					     void *value, u64 map_flags)
 {
 	struct bpf_local_storage_data *sdata;
-	struct fd f = fdget_raw(*(int *)key);
+	CLASS(fd_raw, f)(*(int *)key);
 
-	if (!fd_file(f))
+	if (fd_empty(f))
 		return -EBADF;
-	if (!inode_storage_ptr(file_inode(fd_file(f)))) {
-		fdput(f);
+	if (!inode_storage_ptr(file_inode(fd_file(f))))
 		return -EBADF;
-	}
 
 	sdata = bpf_local_storage_update(file_inode(fd_file(f)),
 					 (struct bpf_local_storage_map *)map,
 					 value, map_flags, GFP_ATOMIC);
-	fdput(f);
 	return PTR_ERR_OR_ZERO(sdata);
 }
 
@@ -123,15 +119,11 @@ static int inode_storage_delete(struct inode *inode, struct bpf_map *map)
 
 static long bpf_fd_inode_storage_delete_elem(struct bpf_map *map, void *key)
 {
-	struct fd f = fdget_raw(*(int *)key);
-	int err;
+	CLASS(fd_raw, f)(*(int *)key);
 
-	if (!fd_file(f))
+	if (fd_empty(f))
 		return -EBADF;
-
-	err = inode_storage_delete(file_inode(fd_file(f)), map);
-	fdput(f);
-	return err;
+	return inode_storage_delete(file_inode(fd_file(f)), map);
 }
 
 /* *gfp_flags* is a hidden argument provided by the verifier */
-- 
2.43.5


  parent reply	other threads:[~2024-08-13 23:03 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-13 23:02 [PATCH bpf-next 0/8] BPF follow ups to struct fd refactorings Andrii Nakryiko
2024-08-13 23:02 ` [PATCH bpf-next 1/8] bpf: convert __bpf_prog_get() to CLASS(fd, ...) Andrii Nakryiko
2024-08-13 23:02 ` Andrii Nakryiko [this message]
2024-08-13 23:02 ` [PATCH bpf-next 3/8] bpf: factor out fetching bpf_map from FD and adding it to used_maps list Andrii Nakryiko
2024-08-14 21:39   ` Jiri Olsa
2024-08-14 23:17     ` Andrii Nakryiko
2024-08-13 23:02 ` [PATCH bpf-next 4/8] bpf: switch maps to CLASS(fd, ...) Andrii Nakryiko
2024-08-13 23:02 ` [PATCH bpf-next 5/8] bpf: trivial conversions for fdget() Andrii Nakryiko
2024-08-13 23:02 ` [PATCH bpf-next 6/8] bpf: more trivial fdget() conversions Andrii Nakryiko
2024-08-13 23:02 ` [PATCH bpf-next 7/8] security,bpf: constify struct path in bpf_token_create() LSM hook Andrii Nakryiko
2024-08-27 23:02   ` Andrii Nakryiko
2024-08-27 23:20     ` Paul Moore
2024-08-27 23:30       ` Andrii Nakryiko
2024-08-13 23:03 ` [PATCH bpf-next 8/8] bpf: convert bpf_token_create() to CLASS(fd, ...) Andrii Nakryiko
2024-08-27 22:55 ` [PATCH bpf-next 0/8] BPF follow ups to struct fd refactorings Andrii Nakryiko
2024-09-12 23:57   ` Al Viro
2024-09-13  0:10     ` Andrii Nakryiko
2024-09-13  0:18       ` Al Viro

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=20240813230300.915127-3-andrii@kernel.org \
    --to=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brauner@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@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 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).