gic__create_its_frame() closes the device fd if the address attribute is unavailable, but returns without closing it if setting the address or initialising the ITS fails. Route all errors after device creation through the same close path. Reviewed-by: Vladimir Murzin Tested-by: Vladimir Murzin Signed-off-by: Sascha Bischoff --- arm64/gic.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/arm64/gic.c b/arm64/gic.c index debb0381..f8371f50 100644 --- a/arm64/gic.c +++ b/arm64/gic.c @@ -124,17 +124,22 @@ static int gic__create_its_frame(struct kvm *kvm, u64 its_frame_addr) } err = ioctl(its_device.fd, KVM_HAS_DEVICE_ATTR, &its_attr); - if (err) { - close(its_device.fd); - its_device.fd = -1; - return err; - } + if (err) + goto out_close; err = ioctl(its_device.fd, KVM_SET_DEVICE_ATTR, &its_attr); if (err) - return err; + goto out_close; - return ioctl(its_device.fd, KVM_SET_DEVICE_ATTR, &its_init_attr); + err = ioctl(its_device.fd, KVM_SET_DEVICE_ATTR, &its_init_attr); + if (err) + goto out_close; + + return 0; + +out_close: + close(its_device.fd); + return err; } static int gic__create_msi_frame(struct kvm *kvm, enum irqchip_type type, -- 2.34.1