Skip to contentSkip to conversation

KVM: vgic: declare probe function pointer as const

PATCH New Ard Biesheuvel 2 participants 2 messages Sep 7, 2014 – Sep 8, 2014 1 message not in the archive

lore
Share & tools
lore
#1 lore raw

PATCH 6/11 KVM: vgic: declare probe function pointer as const

In reply to a message not in the archive
Quoted 15 lines

We extract the vgic probe function from the of_device_id data pointer, which is const. Kill the sparse warning by ensuring that the local function pointer is also marked as const.

---
 virt/kvm/arm/vgic.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
virt/kvm/arm/vgic.c +0 -0
index d1cfe672b9d7..efe6eee2e7eb 100644

virt/kvm/arm/vgic.c static const struct of_device_id vgic_ids[] = { · line 1564

Quoted 10 lines
virt/kvm/arm/vgic.c +2 -2
@@ -1557,8 +1557,8 @@ static const struct of_device_id vgic_ids[] = {
 int kvm_vgic_hyp_init(void)
 {
        const struct of_device_id *matched_id;
-       int (*vgic_probe)(struct device_node *,const struct vgic_ops **,
-                         const struct vgic_params **);
+       const int (*vgic_probe)(struct device_node *,const struct vgic_ops **,
+                               const struct vgic_params **);
        struct device_node *vgic_node;
        int ret;
 

Hi all,

I noticed this patch in kvmarm/next, and I think it is wrong.

Sparse complains about the fact that you are assigning the value of a pointer to const data to a pointer to non-const data, and this is not what is happening. Dereferencing a function pointer does not give you an lvalue, so a function pointer points to const data by definition, and the assignment is fine and sparse is wrong. The fact that you can squelch the warning by typing the function pointer as returning a by-value const result only emphasizes how confused sparse gets about this.

Signature · 1 line
Ard.
#2 lore raw

PATCH 6/11 KVM: vgic: declare probe function pointer as const

Quoted 19 lines · Ard Biesheuvel
Quoted 19 lines

We extract the vgic probe function from the of_device_id data pointer, which is const. Kill the sparse warning by ensuring that the local function pointer is also marked as const.

---
 virt/kvm/arm/vgic.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
virt/kvm/arm/vgic.c +0 -1
index d1cfe672b9d7..efe6eee2e7eb 100644
@@ -1557,8 +1557,8 @@ static const struct of_device_id vgic_ids[] = {
 int kvm_vgic_hyp_init(void)
 {
        const struct of_device_id *matched_id;
-       int (*vgic_probe)(struct device_node *,const struct vgic_ops **,
Quoted 8 lines

virt/kvm/arm/vgic.c static const struct of_device_id vgic_ids[] = { · line 1564

Quoted 6 lines
virt/kvm/arm/vgic.c +2 -1
-                         const struct vgic_params **);
+       const int (*vgic_probe)(struct device_node *,const struct vgic_ops **,
+                               const struct vgic_params **);
        struct device_node *vgic_node;
        int ret;
 

Hi all,

Hi Ard,

Quoted 10 lines

I noticed this patch in kvmarm/next, and I think it is wrong.

Sparse complains about the fact that you are assigning the value of a pointer to const data to a pointer to non-const data, and this is not what is happening. Dereferencing a function pointer does not give you an lvalue, so a function pointer points to const data by definition, and the assignment is fine and sparse is wrong. The fact that you can squelch the warning by typing the function pointer as returning a by-value const result only emphasizes how confused sparse gets about this.

Great, if you're fixing sparse (looks like you are) then we can drop this patch from -next.

Cheers,

Will