Skip to content

Commit 8538cb2

Browse files
Steven PriceMarc Zyngier
authored andcommitted
KVM: Allow kvm_device_ops to be const
Currently a kvm_device_ops structure cannot be const without triggering compiler warnings. However the structure doesn't need to be written to and, by marking it const, it can be read-only in memory. Add some more const keywords to allow this. Reviewed-by: Andrew Jones <[email protected]> Signed-off-by: Steven Price <[email protected]> Signed-off-by: Marc Zyngier <[email protected]>
1 parent 8564d63 commit 8538cb2

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

include/linux/kvm_host.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,7 @@ extern unsigned int halt_poll_ns_grow_start;
12621262
extern unsigned int halt_poll_ns_shrink;
12631263

12641264
struct kvm_device {
1265-
struct kvm_device_ops *ops;
1265+
const struct kvm_device_ops *ops;
12661266
struct kvm *kvm;
12671267
void *private;
12681268
struct list_head vm_node;
@@ -1315,7 +1315,7 @@ struct kvm_device_ops {
13151315
void kvm_device_get(struct kvm_device *dev);
13161316
void kvm_device_put(struct kvm_device *dev);
13171317
struct kvm_device *kvm_device_from_filp(struct file *filp);
1318-
int kvm_register_device_ops(struct kvm_device_ops *ops, u32 type);
1318+
int kvm_register_device_ops(const struct kvm_device_ops *ops, u32 type);
13191319
void kvm_unregister_device_ops(u32 type);
13201320

13211321
extern struct kvm_device_ops kvm_mpic_ops;

virt/kvm/kvm_main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3046,14 +3046,14 @@ struct kvm_device *kvm_device_from_filp(struct file *filp)
30463046
return filp->private_data;
30473047
}
30483048

3049-
static struct kvm_device_ops *kvm_device_ops_table[KVM_DEV_TYPE_MAX] = {
3049+
static const struct kvm_device_ops *kvm_device_ops_table[KVM_DEV_TYPE_MAX] = {
30503050
#ifdef CONFIG_KVM_MPIC
30513051
[KVM_DEV_TYPE_FSL_MPIC_20] = &kvm_mpic_ops,
30523052
[KVM_DEV_TYPE_FSL_MPIC_42] = &kvm_mpic_ops,
30533053
#endif
30543054
};
30553055

3056-
int kvm_register_device_ops(struct kvm_device_ops *ops, u32 type)
3056+
int kvm_register_device_ops(const struct kvm_device_ops *ops, u32 type)
30573057
{
30583058
if (type >= ARRAY_SIZE(kvm_device_ops_table))
30593059
return -ENOSPC;
@@ -3074,7 +3074,7 @@ void kvm_unregister_device_ops(u32 type)
30743074
static int kvm_ioctl_create_device(struct kvm *kvm,
30753075
struct kvm_create_device *cd)
30763076
{
3077-
struct kvm_device_ops *ops = NULL;
3077+
const struct kvm_device_ops *ops = NULL;
30783078
struct kvm_device *dev;
30793079
bool test = cd->flags & KVM_CREATE_DEVICE_TEST;
30803080
int type;

0 commit comments

Comments
 (0)