Skip to content

Commit d897166

Browse files
committed
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
2 parents 4009132 + 3b85d30 commit d897166

File tree

5 files changed

+26
-29
lines changed

5 files changed

+26
-29
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,25 @@ static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev,
5353
int fd,
5454
enum drm_sched_priority priority)
5555
{
56-
struct file *filp = fget(fd);
56+
struct fd f = fdget(fd);
5757
struct amdgpu_fpriv *fpriv;
5858
struct amdgpu_ctx *ctx;
5959
uint32_t id;
6060
int r;
6161

62-
if (!filp)
62+
if (!f.file)
6363
return -EINVAL;
6464

65-
r = amdgpu_file_to_fpriv(filp, &fpriv);
65+
r = amdgpu_file_to_fpriv(f.file, &fpriv);
6666
if (r) {
67-
fput(filp);
67+
fdput(f);
6868
return r;
6969
}
7070

7171
idr_for_each_entry(&fpriv->ctx_mgr.ctx_handles, ctx, id)
7272
amdgpu_ctx_priority_override(ctx, priority);
7373

74-
fput(filp);
75-
74+
fdput(f);
7675
return 0;
7776
}
7877

@@ -81,30 +80,30 @@ static int amdgpu_sched_context_priority_override(struct amdgpu_device *adev,
8180
unsigned ctx_id,
8281
enum drm_sched_priority priority)
8382
{
84-
struct file *filp = fget(fd);
83+
struct fd f = fdget(fd);
8584
struct amdgpu_fpriv *fpriv;
8685
struct amdgpu_ctx *ctx;
8786
int r;
8887

89-
if (!filp)
88+
if (!f.file)
9089
return -EINVAL;
9190

92-
r = amdgpu_file_to_fpriv(filp, &fpriv);
91+
r = amdgpu_file_to_fpriv(f.file, &fpriv);
9392
if (r) {
94-
fput(filp);
93+
fdput(f);
9594
return r;
9695
}
9796

9897
ctx = amdgpu_ctx_get(fpriv, ctx_id);
9998

10099
if (!ctx) {
101-
fput(filp);
100+
fdput(f);
102101
return -EINVAL;
103102
}
104103

105104
amdgpu_ctx_priority_override(ctx, priority);
106105
amdgpu_ctx_put(ctx);
107-
fput(filp);
106+
fdput(f);
108107

109108
return 0;
110109
}

drivers/gpu/drm/drm_syncobj.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -388,20 +388,19 @@ static int drm_syncobj_fd_to_handle(struct drm_file *file_private,
388388
int fd, u32 *handle)
389389
{
390390
struct drm_syncobj *syncobj;
391-
struct file *file;
391+
struct fd f = fdget(fd);
392392
int ret;
393393

394-
file = fget(fd);
395-
if (!file)
394+
if (!f.file)
396395
return -EINVAL;
397396

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);
400399
return -EINVAL;
401400
}
402401

403402
/* take a reference to put in the idr */
404-
syncobj = file->private_data;
403+
syncobj = f.file->private_data;
405404
drm_syncobj_get(syncobj);
406405

407406
idr_preload(GFP_KERNEL);
@@ -416,7 +415,7 @@ static int drm_syncobj_fd_to_handle(struct drm_file *file_private,
416415
} else
417416
drm_syncobj_put(syncobj);
418417

419-
fput(file);
418+
fdput(f);
420419
return ret;
421420
}
422421

drivers/gpu/drm/i915/i915_gem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4354,7 +4354,7 @@ static bool discard_backing_storage(struct drm_i915_gem_object *obj)
43544354
* acquiring such a reference whilst we are in the middle of
43554355
* freeing the object.
43564356
*/
4357-
return atomic_long_read(&obj->base.filp->f_count) == 1;
4357+
return file_count(obj->base.filp) == 1;
43584358
}
43594359

43604360
static void __i915_gem_free_objects(struct drm_i915_private *i915,

drivers/media/media-request.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -246,38 +246,38 @@ static const struct file_operations request_fops = {
246246
struct media_request *
247247
media_request_get_by_fd(struct media_device *mdev, int request_fd)
248248
{
249-
struct file *filp;
249+
struct fd f;
250250
struct media_request *req;
251251

252252
if (!mdev || !mdev->ops ||
253253
!mdev->ops->req_validate || !mdev->ops->req_queue)
254254
return ERR_PTR(-EACCES);
255255

256-
filp = fget(request_fd);
257-
if (!filp)
256+
f = fdget(request_fd);
257+
if (!f.file)
258258
goto err_no_req_fd;
259259

260-
if (filp->f_op != &request_fops)
260+
if (f.file->f_op != &request_fops)
261261
goto err_fput;
262-
req = filp->private_data;
262+
req = f.file->private_data;
263263
if (req->mdev != mdev)
264264
goto err_fput;
265265

266266
/*
267267
* 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
269269
* even if userspace closes the request filehandle, the release()
270270
* fop won't be called, so the media_request_get() always succeeds
271271
* and there is no race condition where the request was released
272272
* before media_request_get() is called.
273273
*/
274274
media_request_get(req);
275-
fput(filp);
275+
fdput(f);
276276

277277
return req;
278278

279279
err_fput:
280-
fput(filp);
280+
fdput(f);
281281

282282
err_no_req_fd:
283283
dev_dbg(mdev->dev, "cannot find request_fd %d\n", request_fd);

include/linux/fs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,6 @@ static inline struct file *get_file(struct file *f)
975975
#define get_file_rcu_many(x, cnt) \
976976
atomic_long_add_unless(&(x)->f_count, (cnt), 0)
977977
#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)
979978
#define file_count(x) atomic_long_read(&(x)->f_count)
980979

981980
#define MAX_NON_LFS ((1UL<<31) - 1)

0 commit comments

Comments
 (0)