Skip to content

Commit 4df4b7c

Browse files
author
Claudio Imbrenda
committed
KVM: s390: Fix leaking kvm_s390_mmu_cache in case of errors
Fix a memory leak that can happen if gmap_ucas_map_one() or kvm_s390_mmu_cache_topup() return error values. Also fix a similar issue in gmap_set_limit(). Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Fixes: a2c17f9 ("KVM: s390: New gmap code") Reported-by: Jiaxin Fan <jiaxin.fan@ibm.com> Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
1 parent d0f2eb4 commit 4df4b7c

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

arch/s390/kvm/gmap.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ struct gmap *gmap_new_child(struct gmap *parent, gfn_t limit)
125125

126126
int gmap_set_limit(struct gmap *gmap, gfn_t limit)
127127
{
128-
struct kvm_s390_mmu_cache *mc;
128+
struct kvm_s390_mmu_cache *mc __free(kvm_s390_mmu_cache) = NULL;
129129
int rc, type;
130130

131131
type = gmap_limit_to_type(limit);
@@ -142,7 +142,6 @@ int gmap_set_limit(struct gmap *gmap, gfn_t limit)
142142
rc = dat_set_asce_limit(mc, &gmap->asce, type);
143143
} while (rc == -ENOMEM);
144144

145-
kvm_s390_free_mmu_cache(mc);
146145
return 0;
147146
}
148147

@@ -822,8 +821,8 @@ int gmap_ucas_translate(struct kvm_s390_mmu_cache *mc, struct gmap *gmap, gpa_t
822821

823822
int gmap_ucas_map(struct gmap *gmap, gfn_t p_gfn, gfn_t c_gfn, unsigned long count)
824823
{
825-
struct kvm_s390_mmu_cache *mc;
826-
int rc;
824+
struct kvm_s390_mmu_cache *mc __free(kvm_s390_mmu_cache) = NULL;
825+
int rc = 0;
827826

828827
mc = kvm_s390_new_mmu_cache();
829828
if (!mc)

0 commit comments

Comments
 (0)