Skip to contentSkip to conversation

x86: make x86_mcinfo_reserve() clear its result buffer

PATCH New Jan Beulich 1 participant 1 message Feb 27, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: make x86_mcinfo_reserve() clear its result buffer

... instead of all but one of its callers.

Also adjust the corresponding sizeof() expressions to specify the pointed-to type of the result variable rather than the literal type (so that a type change of the variable will imply the size to get adjusted too).

xen/arch/x86/cpu/mcheck/amd_f10.c +1 -2
@@ -62,14 +62,13 @@ amd_f10_handler(struct mc_info *mi, uint
 	if (!(status & MCi_STATUS_MISCV))
 		return NULL;
 
-	mc_ext = x86_mcinfo_reserve(mi, sizeof(struct mcinfo_extended));
+	mc_ext = x86_mcinfo_reserve(mi, sizeof(*mc_ext));
 	if (!mc_ext)
 	{
 		mi->flags |= MCINFO_FLAGS_UNCOMPLETE;
 		return NULL;
 	}
 
-	memset(mc_ext, 0, sizeof(*mc_ext));
 	mc_ext->common.type = MC_TYPE_EXTENDED;
 	mc_ext->common.size = sizeof(*mc_ext);
 	mc_ext->mc_msrs = 3;
xen/arch/x86/cpu/mcheck/mcaction.c +1 -3
@@ -13,14 +13,12 @@ mci_action_add_pageoffline(int bank, str
     if (!mi)
         return NULL;
 
-    rec = x86_mcinfo_reserve(mi, sizeof(struct mcinfo_recovery));
+    rec = x86_mcinfo_reserve(mi, sizeof(*rec));
     if (!rec) {
         mi->flags |= MCINFO_FLAGS_UNCOMPLETE;
         return NULL;
     }
 
-    memset(rec, 0, sizeof(struct mcinfo_recovery));
-
     rec->common.type = MC_TYPE_RECOVERY;
     rec->common.size = sizeof(*rec);
     rec->mc_bank = bank;
xen/arch/x86/cpu/mcheck/mce.c +3 -5
@@ -200,14 +200,13 @@ static void mca_init_bank(enum mca_sourc
     if (!mi)
         return;
 
-    mib = x86_mcinfo_reserve(mi, sizeof(struct mcinfo_bank));
+    mib = x86_mcinfo_reserve(mi, sizeof(*mib));
     if (!mib)
     {
         mi->flags |= MCINFO_FLAGS_UNCOMPLETE;
         return;
     }
 
-    memset(mib, 0, sizeof (struct mcinfo_bank));
     mib->mc_status = mca_rdmsr(MSR_IA32_MCx_STATUS(bank));
 
     mib->common.type = MC_TYPE_BANK;
@@ -247,7 +246,6 @@ static int mca_init_global(uint32_t flag
     struct domain *d;
 
     /* Set global information */
-    memset(mig, 0, sizeof (struct mcinfo_global));
     mig->common.type = MC_TYPE_GLOBAL;
     mig->common.size = sizeof (struct mcinfo_global);
     status = mca_rdmsr(MSR_IA32_MCG_STATUS);
@@ -349,7 +347,7 @@ mcheck_mca_logout(enum mca_source who, s
             if ( (mctc = mctelem_reserve(which)) != NULL ) {
                 mci = mctelem_dataptr(mctc);
                 mcinfo_clear(mci);
-                mig = x86_mcinfo_reserve(mci, sizeof(struct mcinfo_global));
+                mig = x86_mcinfo_reserve(mci, sizeof(*mig));
                 /* mc_info should at least hold up the global information */
                 ASSERT(mig);
                 mca_init_global(mc_flags, mig);
@@ -820,7 +818,7 @@ void *x86_mcinfo_reserve(struct mc_info 
     /* there's enough space. add entry. */
     x86_mcinfo_nentries(mi)++;
 
-    return mic_index;
+    return memset(mic_index, 0, size);
 }
 
 void *x86_mcinfo_add(struct mc_info *mi, void *mcinfo)
xen/arch/x86/cpu/mcheck/mce_intel.c +1 -2
@@ -192,7 +192,7 @@ intel_get_extended_msrs(struct mcinfo_gl
             !(mig->mc_gstatus & MCG_STATUS_EIPV))
         return NULL;
 
-    mc_ext = x86_mcinfo_reserve(mi, sizeof(struct mcinfo_extended));
+    mc_ext = x86_mcinfo_reserve(mi, sizeof(*mc_ext));
     if (!mc_ext)
     {
         mi->flags |= MCINFO_FLAGS_UNCOMPLETE;
@@ -200,7 +200,6 @@ intel_get_extended_msrs(struct mcinfo_gl
     }
 
     /* this function will called when CAP(9).MCG_EXT_P = 1 */
-    memset(mc_ext, 0, sizeof(*mc_ext));
     mc_ext->common.type = MC_TYPE_EXTENDED;
     mc_ext->common.size = sizeof(struct mcinfo_extended);
 

x86: make x86_mcinfo_reserve() clear its result buffer

... instead of all but one of its callers.

Also adjust the corresponding sizeof() expressions to specify the pointed-to type of the result variable rather than the literal type (so that a type change of the variable will imply the size to get adjusted too).

xen/arch/x86/cpu/mcheck/amd_f10.c +1 -2
@@ -62,14 +62,13 @@ amd_f10_handler(struct mc_info *mi, uint
 	if (!(status & MCi_STATUS_MISCV))
 		return NULL;
 
-	mc_ext = x86_mcinfo_reserve(mi, sizeof(struct mcinfo_extended));
+	mc_ext = x86_mcinfo_reserve(mi, sizeof(*mc_ext));
 	if (!mc_ext)
 	{
 		mi->flags |= MCINFO_FLAGS_UNCOMPLETE;
 		return NULL;
 	}
 
-	memset(mc_ext, 0, sizeof(*mc_ext));
 	mc_ext->common.type = MC_TYPE_EXTENDED;
 	mc_ext->common.size = sizeof(*mc_ext);
 	mc_ext->mc_msrs = 3;
xen/arch/x86/cpu/mcheck/mcaction.c +1 -3
@@ -13,14 +13,12 @@ mci_action_add_pageoffline(int bank, str
     if (!mi)
         return NULL;
 
-    rec = x86_mcinfo_reserve(mi, sizeof(struct mcinfo_recovery));
+    rec = x86_mcinfo_reserve(mi, sizeof(*rec));
     if (!rec) {
         mi->flags |= MCINFO_FLAGS_UNCOMPLETE;
         return NULL;
     }
 
-    memset(rec, 0, sizeof(struct mcinfo_recovery));
-
     rec->common.type = MC_TYPE_RECOVERY;
     rec->common.size = sizeof(*rec);
     rec->mc_bank = bank;
xen/arch/x86/cpu/mcheck/mce.c +3 -5
@@ -200,14 +200,13 @@ static void mca_init_bank(enum mca_sourc
     if (!mi)
         return;
 
-    mib = x86_mcinfo_reserve(mi, sizeof(struct mcinfo_bank));
+    mib = x86_mcinfo_reserve(mi, sizeof(*mib));
     if (!mib)
     {
         mi->flags |= MCINFO_FLAGS_UNCOMPLETE;
         return;
     }
 
-    memset(mib, 0, sizeof (struct mcinfo_bank));
     mib->mc_status = mca_rdmsr(MSR_IA32_MCx_STATUS(bank));
 
     mib->common.type = MC_TYPE_BANK;
@@ -247,7 +246,6 @@ static int mca_init_global(uint32_t flag
     struct domain *d;
 
     /* Set global information */
-    memset(mig, 0, sizeof (struct mcinfo_global));
     mig->common.type = MC_TYPE_GLOBAL;
     mig->common.size = sizeof (struct mcinfo_global);
     status = mca_rdmsr(MSR_IA32_MCG_STATUS);
@@ -349,7 +347,7 @@ mcheck_mca_logout(enum mca_source who, s
             if ( (mctc = mctelem_reserve(which)) != NULL ) {
                 mci = mctelem_dataptr(mctc);
                 mcinfo_clear(mci);
-                mig = x86_mcinfo_reserve(mci, sizeof(struct mcinfo_global));
+                mig = x86_mcinfo_reserve(mci, sizeof(*mig));
                 /* mc_info should at least hold up the global information */
                 ASSERT(mig);
                 mca_init_global(mc_flags, mig);
@@ -820,7 +818,7 @@ void *x86_mcinfo_reserve(struct mc_info 
     /* there's enough space. add entry. */
     x86_mcinfo_nentries(mi)++;
 
-    return mic_index;
+    return memset(mic_index, 0, size);
 }
 
 void *x86_mcinfo_add(struct mc_info *mi, void *mcinfo)
xen/arch/x86/cpu/mcheck/mce_intel.c +1 -2
@@ -192,7 +192,7 @@ intel_get_extended_msrs(struct mcinfo_gl
             !(mig->mc_gstatus & MCG_STATUS_EIPV))
         return NULL;
 
-    mc_ext = x86_mcinfo_reserve(mi, sizeof(struct mcinfo_extended));
+    mc_ext = x86_mcinfo_reserve(mi, sizeof(*mc_ext));
     if (!mc_ext)
     {
         mi->flags |= MCINFO_FLAGS_UNCOMPLETE;
@@ -200,7 +200,6 @@ intel_get_extended_msrs(struct mcinfo_gl
     }
 
     /* this function will called when CAP(9).MCG_EXT_P = 1 */
-    memset(mc_ext, 0, sizeof(*mc_ext));
     mc_ext->common.type = MC_TYPE_EXTENDED;
     mc_ext->common.size = sizeof(struct mcinfo_extended);
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel