From 1caf7a70a93f81fad622131e34ce68d131a71064 Mon Sep 17 00:00:00 2001 From: Lukas Bulwahn Date: Thu, 11 Apr 2019 05:53:52 +0200 Subject: fs: drop unused fput_atomic definition commit d7065da03822 ("get rid of the magic around f_count in aio") added fput_atomic to include/linux/fs.h, motivated by its use in __aio_put_req() in fs/aio.c. Later, commit 3ffa3c0e3f6e ("aio: now fput() is OK from interrupt context; get rid of manual delayed __fput()") removed the only use of fput_atomic in __aio_put_req(), but did not remove the since then unused fput_atomic definition in include/linux/fs.h. We curate this now and finally remove the unused definition. This issue was identified during a code review due to a coccinelle warning from the atomic_as_refcounter.cocci rule pointing to the use of atomic_t in fput_atomic. Suggested-by: Krystian Radlak Signed-off-by: Lukas Bulwahn Signed-off-by: Al Viro --- include/linux/fs.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index dd28e7679089..79b2f43b945d 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -969,7 +969,6 @@ static inline struct file *get_file(struct file *f) #define get_file_rcu_many(x, cnt) \ atomic_long_add_unless(&(x)->f_count, (cnt), 0) #define get_file_rcu(x) get_file_rcu_many((x), 1) -#define fput_atomic(x) atomic_long_add_unless(&(x)->f_count, -1, 1) #define file_count(x) atomic_long_read(&(x)->f_count) #define MAX_NON_LFS ((1UL<<31) - 1) -- cgit v1.2.3-59-g8ed1b From 79ea35bc20a1b16f2ebd0f70a5a1041a121a2366 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Fri, 12 Apr 2019 20:38:01 -0400 Subject: don't open-code file_count() Signed-off-by: Al Viro --- drivers/gpu/drm/i915/i915_gem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 8558e81fdc2a..3c724cc949a5 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -4354,7 +4354,7 @@ static bool discard_backing_storage(struct drm_i915_gem_object *obj) * acquiring such a reference whilst we are in the middle of * freeing the object. */ - return atomic_long_read(&obj->base.filp->f_count) == 1; + return file_count(obj->base.filp) == 1; } static void __i915_gem_free_objects(struct drm_i915_private *i915, -- cgit v1.2.3-59-g8ed1b From 95ce0bce20fe67c750c0c26491a8c6819daeab94 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sun, 14 Apr 2019 12:49:44 -0400 Subject: amdgpu: switch to fdget() Signed-off-by: Al Viro --- drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c index 0767a93e4d91..639297250c21 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c @@ -53,26 +53,25 @@ static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev, int fd, enum drm_sched_priority priority) { - struct file *filp = fget(fd); + struct fd f = fdget(fd); struct amdgpu_fpriv *fpriv; struct amdgpu_ctx *ctx; uint32_t id; int r; - if (!filp) + if (!f.file) return -EINVAL; - r = amdgpu_file_to_fpriv(filp, &fpriv); + r = amdgpu_file_to_fpriv(f.file, &fpriv); if (r) { - fput(filp); + fdput(f); return r; } idr_for_each_entry(&fpriv->ctx_mgr.ctx_handles, ctx, id) amdgpu_ctx_priority_override(ctx, priority); - fput(filp); - + fdput(f); return 0; } @@ -81,30 +80,30 @@ static int amdgpu_sched_context_priority_override(struct amdgpu_device *adev, unsigned ctx_id, enum drm_sched_priority priority) { - struct file *filp = fget(fd); + struct fd f = fdget(fd); struct amdgpu_fpriv *fpriv; struct amdgpu_ctx *ctx; int r; - if (!filp) + if (!f.file) return -EINVAL; - r = amdgpu_file_to_fpriv(filp, &fpriv); + r = amdgpu_file_to_fpriv(f.file, &fpriv); if (r) { - fput(filp); + fdput(f); return r; } ctx = amdgpu_ctx_get(fpriv, ctx_id); if (!ctx) { - fput(filp); + fdput(f); return -EINVAL; } amdgpu_ctx_priority_override(ctx, priority); amdgpu_ctx_put(ctx); - fput(filp); + fdput(f); return 0; } -- cgit v1.2.3-59-g8ed1b From fb3862435335633edef924c2e7f2820b4c561325 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sun, 14 Apr 2019 12:50:52 -0400 Subject: drm_syncobj: switch to fdget() Signed-off-by: Al Viro --- drivers/gpu/drm/drm_syncobj.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c index e19525af0cce..8bdb4a3bd7bf 100644 --- a/drivers/gpu/drm/drm_syncobj.c +++ b/drivers/gpu/drm/drm_syncobj.c @@ -388,20 +388,19 @@ static int drm_syncobj_fd_to_handle(struct drm_file *file_private, int fd, u32 *handle) { struct drm_syncobj *syncobj; - struct file *file; + struct fd f = fdget(fd); int ret; - file = fget(fd); - if (!file) + if (!f.file) return -EINVAL; - if (file->f_op != &drm_syncobj_file_fops) { - fput(file); + if (f.file->f_op != &drm_syncobj_file_fops) { + fdput(f); return -EINVAL; } /* take a reference to put in the idr */ - syncobj = file->private_data; + syncobj = f.file->private_data; drm_syncobj_get(syncobj); idr_preload(GFP_KERNEL); @@ -416,7 +415,7 @@ static int drm_syncobj_fd_to_handle(struct drm_file *file_private, } else drm_syncobj_put(syncobj); - fput(file); + fdput(f); return ret; } -- cgit v1.2.3-59-g8ed1b From 3b85d3028e2a0f95a8425fbfa54a04056b7cbc91 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sun, 14 Apr 2019 12:55:07 -0400 Subject: media: switch to fdget() Signed-off-by: Al Viro --- drivers/media/media-request.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/media/media-request.c b/drivers/media/media-request.c index eec2e2b2f6ec..9e5fd2ac769e 100644 --- a/drivers/media/media-request.c +++ b/drivers/media/media-request.c @@ -246,38 +246,38 @@ static const struct file_operations request_fops = { struct media_request * media_request_get_by_fd(struct media_device *mdev, int request_fd) { - struct file *filp; + struct fd f; struct media_request *req; if (!mdev || !mdev->ops || !mdev->ops->req_validate || !mdev->ops->req_queue) return ERR_PTR(-EACCES); - filp = fget(request_fd); - if (!filp) + f = fdget(request_fd); + if (!f.file) goto err_no_req_fd; - if (filp->f_op != &request_fops) + if (f.file->f_op != &request_fops) goto err_fput; - req = filp->private_data; + req = f.file->private_data; if (req->mdev != mdev) goto err_fput; /* * Note: as long as someone has an open filehandle of the request, - * the request can never be released. The fget() above ensures that + * the request can never be released. The fdget() above ensures that * even if userspace closes the request filehandle, the release() * fop won't be called, so the media_request_get() always succeeds * and there is no race condition where the request was released * before media_request_get() is called. */ media_request_get(req); - fput(filp); + fdput(f); return req; err_fput: - fput(filp); + fdput(f); err_no_req_fd: dev_dbg(mdev->dev, "cannot find request_fd %d\n", request_fd); -- cgit v1.2.3-59-g8ed1b