linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: Add const to file_operations
@ 2022-05-30  2:08 Xiang wangx
  2022-05-31 19:47 ` Sean Christopherson
  0 siblings, 1 reply; 2+ messages in thread
From: Xiang wangx @ 2022-05-30  2:08 UTC (permalink / raw)
  To: pbonzini; +Cc: kvm, linux-kernel, Xiang wangx

Struct file_operations should normally be const.

Signed-off-by: Xiang wangx <wangxiang@cdjrlc.com>
---
 virt/kvm/kvm_main.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 3f6d450355f0..7dc2433f1b01 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -3550,7 +3550,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
 	return 0;
 }
 
-static struct file_operations kvm_vcpu_fops = {
+static const struct file_operations kvm_vcpu_fops = {
 	.release        = kvm_vcpu_release,
 	.unlocked_ioctl = kvm_vcpu_ioctl,
 	.mmap           = kvm_vcpu_mmap,
@@ -4599,7 +4599,7 @@ static long kvm_vm_compat_ioctl(struct file *filp,
 }
 #endif
 
-static struct file_operations kvm_vm_fops = {
+static const struct file_operations kvm_vm_fops = {
 	.release        = kvm_vm_release,
 	.unlocked_ioctl = kvm_vm_ioctl,
 	.llseek		= noop_llseek,
@@ -4701,7 +4701,7 @@ static long kvm_dev_ioctl(struct file *filp,
 	return r;
 }
 
-static struct file_operations kvm_chardev_ops = {
+static const struct file_operations kvm_chardev_ops = {
 	.unlocked_ioctl = kvm_dev_ioctl,
 	.llseek		= noop_llseek,
 	KVM_COMPAT(kvm_dev_ioctl),
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] KVM: Add const to file_operations
  2022-05-30  2:08 [PATCH] KVM: Add const to file_operations Xiang wangx
@ 2022-05-31 19:47 ` Sean Christopherson
  0 siblings, 0 replies; 2+ messages in thread
From: Sean Christopherson @ 2022-05-31 19:47 UTC (permalink / raw)
  To: Xiang wangx; +Cc: pbonzini, kvm, linux-kernel

On Mon, May 30, 2022, Xiang wangx wrote:
> Struct file_operations should normally be const.

Operative word being "should".  kvm_chardev_ops isn't constant because kvm_init()
modifies the "owner".  The same was true for kvm_vcpu_fops and kvm_vm_fops until
commit 70375c2d8fa3 ("Revert "KVM: set owner of cpu and vm file operations"").

So, this patch is both stale, and completely broken when applied against current
KVM as well as whatever old version of KVM it was generated with.

arch/x86/kvm/../../../virt/kvm/kvm_main.c:4873:37: error: conflicting type qualifiers for ‘kvm_chardev_ops’
 4873 | static const struct file_operations kvm_chardev_ops = {
      |                                     ^~~~~~~~~~~~~~~
arch/x86/kvm/../../../virt/kvm/kvm_main.c:120:31: note: previous declaration of ‘kvm_chardev_ops’ with type ‘struct file_operations’
  120 | static struct file_operations kvm_chardev_ops;
      |                               ^~~~~~~~~~~~~~~
arch/x86/kvm/../../../virt/kvm/kvm_main.c: In function ‘kvm_init’:
arch/x86/kvm/../../../virt/kvm/kvm_main.c:5777:31: error: assignment of member ‘owner’ in read-only object
 5777 |         kvm_chardev_ops.owner = module;
      |                               ^
  CC      arch/x86/events/intel/p6.o
make[3]: *** [scripts/Makefile.build:288: arch/x86/kvm/../../../virt/kvm/kvm_main.o] Error 1
make[2]: *** [scripts/Makefile.build:550: arch/x86/kvm] Error 2


> Signed-off-by: Xiang wangx <wangxiang@cdjrlc.com>
> ---
>  virt/kvm/kvm_main.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 3f6d450355f0..7dc2433f1b01 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -3550,7 +3550,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
>  	return 0;
>  }
>  
> -static struct file_operations kvm_vcpu_fops = {
> +static const struct file_operations kvm_vcpu_fops = {
>  	.release        = kvm_vcpu_release,
>  	.unlocked_ioctl = kvm_vcpu_ioctl,
>  	.mmap           = kvm_vcpu_mmap,
> @@ -4599,7 +4599,7 @@ static long kvm_vm_compat_ioctl(struct file *filp,
>  }
>  #endif
>  
> -static struct file_operations kvm_vm_fops = {
> +static const struct file_operations kvm_vm_fops = {
>  	.release        = kvm_vm_release,
>  	.unlocked_ioctl = kvm_vm_ioctl,
>  	.llseek		= noop_llseek,
> @@ -4701,7 +4701,7 @@ static long kvm_dev_ioctl(struct file *filp,
>  	return r;
>  }
>  
> -static struct file_operations kvm_chardev_ops = {
> +static const struct file_operations kvm_chardev_ops = {
>  	.unlocked_ioctl = kvm_dev_ioctl,
>  	.llseek		= noop_llseek,
>  	KVM_COMPAT(kvm_dev_ioctl),
> -- 
> 2.36.1
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-31 19:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-30  2:08 [PATCH] KVM: Add const to file_operations Xiang wangx
2022-05-31 19:47 ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).