Pull vfs 'struct file' related updates from Al Viro: "A bit more of 'this fget() would be better off as fdget()' whack-a-mole + a couple of ->f_count-related cleanups" * 'work.file' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: media: switch to fdget() drm_syncobj: switch to fdget() amdgpu: switch to fdget() don't open-code file_count() fs: drop unused fput_atomic definition
Unified · Split
| @@ -53,26 +53,25 @@ static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev, · 52 unmodified lines | ||
| 53 | 53 | int fd, |
| 54 | 54 | enum drm_sched_priority priority) |
| 55 | 55 | { |
| 56 | − struct file *filp = fget(fd); | |
| 56 | + struct fd f = fdget(fd); | |
| 57 | 57 | struct amdgpu_fpriv *fpriv; |
| 58 | 58 | struct amdgpu_ctx *ctx; |
| 59 | 59 | uint32_t id; |
| 60 | 60 | int r; |
| 61 | 61 | |
| 62 | − if (!filp) | |
| 62 | + if (!f.file) | |
| 63 | 63 | return -EINVAL; |
| 64 | 64 | |
| 65 | − r = amdgpu_file_to_fpriv(filp, &fpriv); | |
| 65 | + r = amdgpu_file_to_fpriv(f.file, &fpriv); | |
| 66 | 66 | if (r) { |
| 67 | − fput(filp); | |
| 67 | + fdput(f); | |
| 68 | 68 | return r; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | idr_for_each_entry(&fpriv->ctx_mgr.ctx_handles, ctx, id) |
| 72 | 72 | amdgpu_ctx_priority_override(ctx, priority); |
| 73 | 73 | |
| 74 | − fput(filp); | |
| 75 | − | |
| 74 | + fdput(f); | |
| 76 | 75 | return 0; |
| 77 | 76 | } |
| 78 | 77 | |
| @@ -81,30 +80,30 @@ static int amdgpu_sched_context_priority_override(struct amdgpu_device *adev, · 2 unmodified lines | ||
| 81 | 80 | unsigned ctx_id, |
| 82 | 81 | enum drm_sched_priority priority) |
| 83 | 82 | { |
| 84 | − struct file *filp = fget(fd); | |
| 83 | + struct fd f = fdget(fd); | |
| 85 | 84 | struct amdgpu_fpriv *fpriv; |
| 86 | 85 | struct amdgpu_ctx *ctx; |
| 87 | 86 | int r; |
| 88 | 87 | |
| 89 | − if (!filp) | |
| 88 | + if (!f.file) | |
| 90 | 89 | return -EINVAL; |
| 91 | 90 | |
| 92 | − r = amdgpu_file_to_fpriv(filp, &fpriv); | |
| 91 | + r = amdgpu_file_to_fpriv(f.file, &fpriv); | |
| 93 | 92 | if (r) { |
| 94 | − fput(filp); | |
| 93 | + fdput(f); | |
| 95 | 94 | return r; |
| 96 | 95 | } |
| 97 | 96 | |
| 98 | 97 | ctx = amdgpu_ctx_get(fpriv, ctx_id); |
| 99 | 98 | |
| 100 | 99 | if (!ctx) { |
| 101 | − fput(filp); | |
| 100 | + fdput(f); | |
| 102 | 101 | return -EINVAL; |
| 103 | 102 | } |
| 104 | 103 | |
| 105 | 104 | amdgpu_ctx_priority_override(ctx, priority); |
| 106 | 105 | amdgpu_ctx_put(ctx); |
| 107 | − fput(filp); | |
| 106 | + fdput(f); | |
| 108 | 107 | |
| 109 | 108 | return 0; |
| 110 | 109 | } |
| @@ -388,20 +388,19 @@ static int drm_syncobj_fd_to_handle(struct drm_file *file_private, · 387 unmodified lines | ||
| 388 | 388 | int fd, u32 *handle) |
| 389 | 389 | { |
| 390 | 390 | struct drm_syncobj *syncobj; |
| 391 | − struct file *file; | |
| 391 | + struct fd f = fdget(fd); | |
| 392 | 392 | int ret; |
| 393 | 393 | |
| 394 | − file = fget(fd); | |
| 395 | − if (!file) | |
| 394 | + if (!f.file) | |
| 396 | 395 | return -EINVAL; |
| 397 | 396 | |
| 398 | − if (file->f_op != &drm_syncobj_file_fops) { | |
| 399 | − fput(file); | |
| 397 | + if (f.file->f_op != &drm_syncobj_file_fops) { | |
| 398 | + fdput(f); | |
| 400 | 399 | return -EINVAL; |
| 401 | 400 | } |
| 402 | 401 | |
| 403 | 402 | /* take a reference to put in the idr */ |
| 404 | − syncobj = file->private_data; | |
| 403 | + syncobj = f.file->private_data; | |
| 405 | 404 | drm_syncobj_get(syncobj); |
| 406 | 405 | |
| 407 | 406 | idr_preload(GFP_KERNEL); |
| @@ -416,7 +415,7 @@ static int drm_syncobj_fd_to_handle(struct drm_file *file_private, · 8 unmodified lines | ||
| 416 | 415 | } else |
| 417 | 416 | drm_syncobj_put(syncobj); |
| 418 | 417 | |
| 419 | − fput(file); | |
| 418 | + fdput(f); | |
| 420 | 419 | return ret; |
| 421 | 420 | } |
| 422 | 421 | |
| @@ -4354,7 +4354,7 @@ static bool discard_backing_storage(struct drm_i915_gem_object *obj) · 4353 unmodified lines | ||
| 4354 | 4354 | * acquiring such a reference whilst we are in the middle of |
| 4355 | 4355 | * freeing the object. |
| 4356 | 4356 | */ |
| 4357 | − return atomic_long_read(&obj->base.filp->f_count) == 1; | |
| 4357 | + return file_count(obj->base.filp) == 1; | |
| 4358 | 4358 | } |
| 4359 | 4359 | |
| 4360 | 4360 | static void __i915_gem_free_objects(struct drm_i915_private *i915, |
| @@ -246,38 +246,38 @@ static const struct file_operations request_fops = { · 245 unmodified lines | ||
| 246 | 246 | struct media_request * |
| 247 | 247 | media_request_get_by_fd(struct media_device *mdev, int request_fd) |
| 248 | 248 | { |
| 249 | − struct file *filp; | |
| 249 | + struct fd f; | |
| 250 | 250 | struct media_request *req; |
| 251 | 251 | |
| 252 | 252 | if (!mdev || !mdev->ops || |
| 253 | 253 | !mdev->ops->req_validate || !mdev->ops->req_queue) |
| 254 | 254 | return ERR_PTR(-EACCES); |
| 255 | 255 | |
| 256 | − filp = fget(request_fd); | |
| 257 | − if (!filp) | |
| 256 | + f = fdget(request_fd); | |
| 257 | + if (!f.file) | |
| 258 | 258 | goto err_no_req_fd; |
| 259 | 259 | |
| 260 | − if (filp->f_op != &request_fops) | |
| 260 | + if (f.file->f_op != &request_fops) | |
| 261 | 261 | goto err_fput; |
| 262 | − req = filp->private_data; | |
| 262 | + req = f.file->private_data; | |
| 263 | 263 | if (req->mdev != mdev) |
| 264 | 264 | goto err_fput; |
| 265 | 265 | |
| 266 | 266 | /* |
| 267 | 267 | * Note: as long as someone has an open filehandle of the request, |
| 268 | − * the request can never be released. The fget() above ensures that | |
| 268 | + * the request can never be released. The fdget() above ensures that | |
| 269 | 269 | * even if userspace closes the request filehandle, the release() |
| 270 | 270 | * fop won't be called, so the media_request_get() always succeeds |
| 271 | 271 | * and there is no race condition where the request was released |
| 272 | 272 | * before media_request_get() is called. |
| 273 | 273 | */ |
| 274 | 274 | media_request_get(req); |
| 275 | − fput(filp); | |
| 275 | + fdput(f); | |
| 276 | 276 | |
| 277 | 277 | return req; |
| 278 | 278 | |
| 279 | 279 | err_fput: |
| 280 | − fput(filp); | |
| 280 | + fdput(f); | |
| 281 | 281 | |
| 282 | 282 | err_no_req_fd: |
| 283 | 283 | dev_dbg(mdev->dev, "cannot find request_fd %d\n", request_fd); |
| @@ -975,7 +975,6 @@ static inline struct file *get_file(struct file *f) · 974 unmodified lines | ||
| 975 | 975 | #define get_file_rcu_many(x, cnt) \ |
| 976 | 976 | atomic_long_add_unless(&(x)->f_count, (cnt), 0) |
| 977 | 977 | #define get_file_rcu(x) get_file_rcu_many((x), 1) |
| 978 | −#define fput_atomic(x) atomic_long_add_unless(&(x)->f_count, -1, 1) | |
| 979 | 978 | #define file_count(x) atomic_long_read(&(x)->f_count) |
| 980 | 979 | |
| 981 | 980 | #define MAX_NON_LFS ((1UL<<31) - 1) |