History

Merge branch 'work.file' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

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

Linus Torvalds committed 7 years ago

Commit d8971662 parents 4009132 3b85d305 files · +26 −29Browse files

Unified · Split

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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t