From: "Jan Beulich" Subject: [PATCH] x86: make x86_mcinfo_reserve() clear its result buffer Date: Wed, 27 Feb 2013 10:46:06 +0000 Message-ID: <512DF1FE02000078000C16A8@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part093978FE.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part093978FE.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline ... 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). Suggested-by: Ian Campbell Signed-off-by: Jan Beulich --- a/xen/arch/x86/cpu/mcheck/amd_f10.c +++ b/xen/arch/x86/cpu/mcheck/amd_f10.c @@ -62,14 +62,13 @@ amd_f10_handler(struct mc_info *mi, uint if (!(status & MCi_STATUS_MISCV)) return NULL; =20 - mc_ext =3D x86_mcinfo_reserve(mi, sizeof(struct mcinfo_extended)); + mc_ext =3D x86_mcinfo_reserve(mi, sizeof(*mc_ext)); if (!mc_ext) { mi->flags |=3D MCINFO_FLAGS_UNCOMPLETE; return NULL; } =20 - memset(mc_ext, 0, sizeof(*mc_ext)); mc_ext->common.type =3D MC_TYPE_EXTENDED; mc_ext->common.size =3D sizeof(*mc_ext); mc_ext->mc_msrs =3D 3; --- a/xen/arch/x86/cpu/mcheck/mcaction.c +++ b/xen/arch/x86/cpu/mcheck/mcaction.c @@ -13,14 +13,12 @@ mci_action_add_pageoffline(int bank, str if (!mi) return NULL; =20 - rec =3D x86_mcinfo_reserve(mi, sizeof(struct mcinfo_recovery)); + rec =3D x86_mcinfo_reserve(mi, sizeof(*rec)); if (!rec) { mi->flags |=3D MCINFO_FLAGS_UNCOMPLETE; return NULL; } =20 - memset(rec, 0, sizeof(struct mcinfo_recovery)); - rec->common.type =3D MC_TYPE_RECOVERY; rec->common.size =3D sizeof(*rec); rec->mc_bank =3D bank; --- a/xen/arch/x86/cpu/mcheck/mce.c +++ b/xen/arch/x86/cpu/mcheck/mce.c @@ -200,14 +200,13 @@ static void mca_init_bank(enum mca_sourc if (!mi) return; =20 - mib =3D x86_mcinfo_reserve(mi, sizeof(struct mcinfo_bank)); + mib =3D x86_mcinfo_reserve(mi, sizeof(*mib)); if (!mib) { mi->flags |=3D MCINFO_FLAGS_UNCOMPLETE; return; } =20 - memset(mib, 0, sizeof (struct mcinfo_bank)); mib->mc_status =3D mca_rdmsr(MSR_IA32_MCx_STATUS(bank)); =20 mib->common.type =3D MC_TYPE_BANK; @@ -247,7 +246,6 @@ static int mca_init_global(uint32_t flag struct domain *d; =20 /* Set global information */ - memset(mig, 0, sizeof (struct mcinfo_global)); mig->common.type =3D MC_TYPE_GLOBAL; mig->common.size =3D sizeof (struct mcinfo_global); status =3D mca_rdmsr(MSR_IA32_MCG_STATUS); @@ -349,7 +347,7 @@ mcheck_mca_logout(enum mca_source who, s if ( (mctc =3D mctelem_reserve(which)) !=3D NULL ) { mci =3D mctelem_dataptr(mctc); mcinfo_clear(mci); - mig =3D x86_mcinfo_reserve(mci, sizeof(struct mcinfo_globa= l)); + mig =3D 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=20 /* there's enough space. add entry. */ x86_mcinfo_nentries(mi)++; =20 - return mic_index; + return memset(mic_index, 0, size); } =20 void *x86_mcinfo_add(struct mc_info *mi, void *mcinfo) --- a/xen/arch/x86/cpu/mcheck/mce_intel.c +++ b/xen/arch/x86/cpu/mcheck/mce_intel.c @@ -192,7 +192,7 @@ intel_get_extended_msrs(struct mcinfo_gl !(mig->mc_gstatus & MCG_STATUS_EIPV)) return NULL; =20 - mc_ext =3D x86_mcinfo_reserve(mi, sizeof(struct mcinfo_extended)); + mc_ext =3D x86_mcinfo_reserve(mi, sizeof(*mc_ext)); if (!mc_ext) { mi->flags |=3D MCINFO_FLAGS_UNCOMPLETE; @@ -200,7 +200,6 @@ intel_get_extended_msrs(struct mcinfo_gl } =20 /* this function will called when CAP(9).MCG_EXT_P =3D 1 */ - memset(mc_ext, 0, sizeof(*mc_ext)); mc_ext->common.type =3D MC_TYPE_EXTENDED; mc_ext->common.size =3D sizeof(struct mcinfo_extended); =20 --=__Part093978FE.0__= Content-Type: text/plain; name="x86-mcinfo-reserve-clear.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-mcinfo-reserve-clear.patch" x86: make x86_mcinfo_reserve() clear its result buffer=0A=0A... instead of = all but one of its callers.=0A=0AAlso adjust the corresponding sizeof() = expressions to specify the=0Apointed-to type of the result variable rather = than the literal type=0A(so that a type change of the variable will imply = the size to get=0Aadjusted too).=0A=0ASuggested-by: Ian Campbell =0ASigned-off-by: Jan Beulich =0A=0A--- = a/xen/arch/x86/cpu/mcheck/amd_f10.c=0A+++ b/xen/arch/x86/cpu/mcheck/amd_f10= .c=0A@@ -62,14 +62,13 @@ amd_f10_handler(struct mc_info *mi, uint=0A if = (!(status & MCi_STATUS_MISCV))=0A return NULL;=0A =0A- = mc_ext =3D x86_mcinfo_reserve(mi, sizeof(struct mcinfo_extended));=0A+ = mc_ext =3D x86_mcinfo_reserve(mi, sizeof(*mc_ext));=0A if (!mc_ext)=0A = {=0A mi->flags |=3D MCINFO_FLAGS_UNCOMPLETE;=0A = return NULL;=0A }=0A =0A- memset(mc_ext, 0, sizeof(*mc_ext));= =0A mc_ext->common.type =3D MC_TYPE_EXTENDED;=0A mc_ext->common.size= =3D sizeof(*mc_ext);=0A mc_ext->mc_msrs =3D 3;=0A--- a/xen/arch/x86= /cpu/mcheck/mcaction.c=0A+++ b/xen/arch/x86/cpu/mcheck/mcaction.c=0A@@ = -13,14 +13,12 @@ mci_action_add_pageoffline(int bank, str=0A if = (!mi)=0A return NULL;=0A =0A- rec =3D x86_mcinfo_reserve(mi, = sizeof(struct mcinfo_recovery));=0A+ rec =3D x86_mcinfo_reserve(mi, = sizeof(*rec));=0A if (!rec) {=0A mi->flags |=3D MCINFO_FLAGS_UN= COMPLETE;=0A return NULL;=0A }=0A =0A- memset(rec, 0, = sizeof(struct mcinfo_recovery));=0A-=0A rec->common.type =3D MC_TYPE_RE= COVERY;=0A rec->common.size =3D sizeof(*rec);=0A rec->mc_bank =3D = bank;=0A--- a/xen/arch/x86/cpu/mcheck/mce.c=0A+++ b/xen/arch/x86/cpu/mcheck= /mce.c=0A@@ -200,14 +200,13 @@ static void mca_init_bank(enum mca_sourc=0A = if (!mi)=0A return;=0A =0A- mib =3D x86_mcinfo_reserve(mi, = sizeof(struct mcinfo_bank));=0A+ mib =3D x86_mcinfo_reserve(mi, = sizeof(*mib));=0A if (!mib)=0A {=0A mi->flags |=3D = MCINFO_FLAGS_UNCOMPLETE;=0A return;=0A }=0A =0A- memset(mib,= 0, sizeof (struct mcinfo_bank));=0A mib->mc_status =3D mca_rdmsr(MSR_I= A32_MCx_STATUS(bank));=0A =0A mib->common.type =3D MC_TYPE_BANK;=0A@@ = -247,7 +246,6 @@ static int mca_init_global(uint32_t flag=0A struct = domain *d;=0A =0A /* Set global information */=0A- memset(mig, 0, = sizeof (struct mcinfo_global));=0A mig->common.type =3D MC_TYPE_GLOBAL;= =0A mig->common.size =3D sizeof (struct mcinfo_global);=0A status = =3D mca_rdmsr(MSR_IA32_MCG_STATUS);=0A@@ -349,7 +347,7 @@ mcheck_mca_logout= (enum mca_source who, s=0A if ( (mctc =3D mctelem_reserve(which= )) !=3D NULL ) {=0A mci =3D mctelem_dataptr(mctc);=0A = mcinfo_clear(mci);=0A- mig =3D x86_mcinfo_reserve= (mci, sizeof(struct mcinfo_global));=0A+ mig =3D x86_mcinfo_= reserve(mci, sizeof(*mig));=0A /* mc_info should at least = hold up the global information */=0A ASSERT(mig);=0A = mca_init_global(mc_flags, mig);=0A@@ -820,7 +818,7 @@ void = *x86_mcinfo_reserve(struct mc_info =0A /* there's enough space. add = entry. */=0A x86_mcinfo_nentries(mi)++;=0A =0A- return mic_index;=0A= + return memset(mic_index, 0, size);=0A }=0A =0A void *x86_mcinfo_add(st= ruct mc_info *mi, void *mcinfo)=0A--- a/xen/arch/x86/cpu/mcheck/mce_intel.c= =0A+++ b/xen/arch/x86/cpu/mcheck/mce_intel.c=0A@@ -192,7 +192,7 @@ = intel_get_extended_msrs(struct mcinfo_gl=0A !(mig->mc_gstatus = & MCG_STATUS_EIPV))=0A return NULL;=0A =0A- mc_ext =3D = x86_mcinfo_reserve(mi, sizeof(struct mcinfo_extended));=0A+ mc_ext =3D = x86_mcinfo_reserve(mi, sizeof(*mc_ext));=0A if (!mc_ext)=0A {=0A = mi->flags |=3D MCINFO_FLAGS_UNCOMPLETE;=0A@@ -200,7 +200,6 @@ = intel_get_extended_msrs(struct mcinfo_gl=0A }=0A =0A /* this = function will called when CAP(9).MCG_EXT_P =3D 1 */=0A- memset(mc_ext, = 0, sizeof(*mc_ext));=0A mc_ext->common.type =3D MC_TYPE_EXTENDED;=0A = mc_ext->common.size =3D sizeof(struct mcinfo_extended);=0A =0A --=__Part093978FE.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part093978FE.0__=--