]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
riscv: kvm: add null pointer check for vector datap
authorYufeng Wang <wangyufeng@kylinos.cn>
Tue, 17 Mar 2026 11:47:59 +0000 (19:47 +0800)
committerAnup Patel <anup@brainfault.org>
Mon, 30 Mar 2026 06:40:21 +0000 (12:10 +0530)
Add WARN_ON check before accessing cntx->vector.datap in
kvm_riscv_vcpu_vreg_addr() to detect potential null pointer
dereferences early, consistent with the pattern used in
kvm_riscv_vcpu_vector_reset().

This helps catch initialization issues where vector context
allocation may have failed.

Signed-off-by: Yufeng Wang <wangyufeng@kylinos.cn>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20260317114759.53165-1-r4o5m6e8o@163.com
Signed-off-by: Anup Patel <anup@brainfault.org>
arch/riscv/kvm/vcpu_vector.c

index 5b6ad82d47beb73af71554b66ff14b8f1b49bc6e..f3f5fb665cf687eeec5ccfdf75aa6e6d8da09451 100644 (file)
@@ -130,6 +130,7 @@ static int kvm_riscv_vcpu_vreg_addr(struct kvm_vcpu *vcpu,
        } else if (reg_num <= KVM_REG_RISCV_VECTOR_REG(31)) {
                if (reg_size != vlenb)
                        return -EINVAL;
+               WARN_ON(!cntx->vector.datap);
                *reg_addr = cntx->vector.datap +
                            (reg_num - KVM_REG_RISCV_VECTOR_REG(0)) * vlenb;
        } else {