Commit 1da91ea8 authored by Al Viro's avatar Al Viro
Browse files

introduce fd_file(), convert all accessors to it.



	For any changes of struct fd representation we need to
turn existing accesses to fields into calls of wrappers.
Accesses to struct fd::flags are very few (3 in linux/file.h,
1 in net/socket.c, 3 in fs/overlayfs/file.c and 3 more in
explicit initializers).
	Those can be dealt with in the commit converting to
new layout; accesses to struct fd::file are too many for that.
	This commit converts (almost) all of f.file to
fd_file(f).  It's not entirely mechanical ('file' is used as
a member name more than just in struct fd) and it does not
even attempt to distinguish the uses in pointer context from
those in boolean context; the latter will be eventually turned
into a separate helper (fd_empty()).

	NOTE: mass conversion to fd_empty(), tempting as it
might be, is a bad idea; better do that piecewise in commit
that convert from fdget...() to CLASS(...).

[conflicts in fs/fhandle.c, kernel/bpf/syscall.c, mm/memcontrol.c
caught by git; fs/stat.c one got caught by git grep]
[fs/xattr.c conflict]

Reviewed-by: default avatarChristian Brauner <brauner@kernel.org>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 8400291e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -160,10 +160,10 @@ SYSCALL_DEFINE4(osf_getdirentries, unsigned int, fd,
		.count = count
	};

	if (!arg.file)
	if (!fd_file(arg))
		return -EBADF;

	error = iterate_dir(arg.file, &buf.ctx);
	error = iterate_dir(fd_file(arg), &buf.ctx);
	if (error >= 0)
		error = buf.error;
	if (count != buf.count)
+5 −5
Original line number Diff line number Diff line
@@ -239,19 +239,19 @@ asmlinkage long sys_oabi_fcntl64(unsigned int fd, unsigned int cmd,
	struct flock64 flock;
	long err = -EBADF;

	if (!f.file)
	if (!fd_file(f))
		goto out;

	switch (cmd) {
	case F_GETLK64:
	case F_OFD_GETLK:
		err = security_file_fcntl(f.file, cmd, arg);
		err = security_file_fcntl(fd_file(f), cmd, arg);
		if (err)
			break;
		err = get_oabi_flock(&flock, argp);
		if (err)
			break;
		err = fcntl_getlk64(f.file, cmd, &flock);
		err = fcntl_getlk64(fd_file(f), cmd, &flock);
		if (!err)
		       err = put_oabi_flock(&flock, argp);
		break;
@@ -259,13 +259,13 @@ asmlinkage long sys_oabi_fcntl64(unsigned int fd, unsigned int cmd,
	case F_SETLKW64:
	case F_OFD_SETLK:
	case F_OFD_SETLKW:
		err = security_file_fcntl(f.file, cmd, arg);
		err = security_file_fcntl(fd_file(f), cmd, arg);
		if (err)
			break;
		err = get_oabi_flock(&flock, argp);
		if (err)
			break;
		err = fcntl_setlk64(fd, f.file, cmd, &flock);
		err = fcntl_setlk64(fd, fd_file(f), cmd, &flock);
		break;
	default:
		err = sys_fcntl64(fd, cmd, arg);
+2 −2
Original line number Diff line number Diff line
@@ -118,12 +118,12 @@ long kvm_spapr_tce_attach_iommu_group(struct kvm *kvm, int tablefd,
	struct fd f;

	f = fdget(tablefd);
	if (!f.file)
	if (!fd_file(f))
		return -EBADF;

	rcu_read_lock();
	list_for_each_entry_rcu(stt, &kvm->arch.spapr_tce_tables, list) {
		if (stt == f.file->private_data) {
		if (stt == fd_file(f)->private_data) {
			found = true;
			break;
		}
+6 −6
Original line number Diff line number Diff line
@@ -1938,11 +1938,11 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,

		r = -EBADF;
		f = fdget(cap->args[0]);
		if (!f.file)
		if (!fd_file(f))
			break;

		r = -EPERM;
		dev = kvm_device_from_filp(f.file);
		dev = kvm_device_from_filp(fd_file(f));
		if (dev)
			r = kvmppc_mpic_connect_vcpu(dev, vcpu, cap->args[1]);

@@ -1957,11 +1957,11 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,

		r = -EBADF;
		f = fdget(cap->args[0]);
		if (!f.file)
		if (!fd_file(f))
			break;

		r = -EPERM;
		dev = kvm_device_from_filp(f.file);
		dev = kvm_device_from_filp(fd_file(f));
		if (dev) {
			if (xics_on_xive())
				r = kvmppc_xive_connect_vcpu(dev, vcpu, cap->args[1]);
@@ -1980,7 +1980,7 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,

		r = -EBADF;
		f = fdget(cap->args[0]);
		if (!f.file)
		if (!fd_file(f))
			break;

		r = -ENXIO;
@@ -1990,7 +1990,7 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
		}

		r = -EPERM;
		dev = kvm_device_from_filp(f.file);
		dev = kvm_device_from_filp(fd_file(f));
		if (dev)
			r = kvmppc_xive_native_connect_vcpu(dev, vcpu,
							    cap->args[1]);
+4 −4
Original line number Diff line number Diff line
@@ -66,8 +66,8 @@ SYSCALL_DEFINE4(spu_create, const char __user *, name, unsigned int, flags,
	if (flags & SPU_CREATE_AFFINITY_SPU) {
		struct fd neighbor = fdget(neighbor_fd);
		ret = -EBADF;
		if (neighbor.file) {
			ret = calls->create_thread(name, flags, mode, neighbor.file);
		if (fd_file(neighbor)) {
			ret = calls->create_thread(name, flags, mode, fd_file(neighbor));
			fdput(neighbor);
		}
	} else
@@ -89,8 +89,8 @@ SYSCALL_DEFINE3(spu_run,int, fd, __u32 __user *, unpc, __u32 __user *, ustatus)

	ret = -EBADF;
	arg = fdget(fd);
	if (arg.file) {
		ret = calls->spu_run(arg.file, unpc, ustatus);
	if (fd_file(arg)) {
		ret = calls->spu_run(fd_file(arg), unpc, ustatus);
		fdput(arg);
	}

Loading