tools/libxc: Drop copy-in in xc_physinfo()
PATCH 1/1 tools/libxc: Drop copy-in in xc_physinfo()
The first thing XEN_SYSCTL_physinfo does is zero op->u.physinfo.
Do not copy-in. It's pointless, and most callers don't initialise their xc_physinfo_t buffer to begin with. Remove the pointless zeroing from the remaining callers.
Spotted by Coverity.
---
CC: Anthony PERARD <[email protected]>
CC: Juergen Gross <[email protected]>
--- tools/libs/ctrl/xc_misc.c | 2 -- tools/libs/light/libxl.c | 2 +- tools/libs/stat/xenstat.c | 2 +- tools/misc/xenpm.c | 2 +- tools/xenmon/xenbaked.c | 2 +- tools/xentrace/xentrace.c | 2 +- 6 files changed, 5 insertions(+), 7 deletions(-)
tools/libs/ctrl/xc_misc.c +0 -2
@@ -195,8 +195,6 @@ int xc_physinfo(xc_interface *xch, sysctl.cmd = XEN_SYSCTL_physinfo; -memcpy (&sysctl.u.physinfo, put_info,sizeof (*put_info)); -if ( (ret =do_sysctl (xch, &sysctl)) !=0 )return ret;
tools/libs/light/libxl.c +1 -1
@@ -351,7 +351,7 @@ const char *libxl_defbool_to_string(libxl_defbool b)/******************************************************************************/ int libxl_get_physinfo (libxl_ctx *ctx,libxl_physinfo *physinfo) { -xc_physinfo_t xcphysinfo = {0 }; +xc_physinfo_t xcphysinfo;int rc;long l;GC_INIT (ctx);
tools/libs/stat/xenstat.c +1 -1
@@ -135,7 +135,7 @@ xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags) {#define DOMAIN_CHUNK_SIZE 256xenstat_node *node; -xc_physinfo_t physinfo = {0 }; +xc_physinfo_t physinfo;xc_domaininfo_t domaininfo[DOMAIN_CHUNK_SIZE ];int new_domains;unsigned int i;
tools/misc/xenpm.c +1 -1
@@ -1244,7 +1244,7 @@ struct {int main (int argc,char *argv[]) {int i, ret =0 ; -xc_physinfo_t physinfo = {0 }; +xc_physinfo_t physinfo;int nr_matches =0 ;int matches_main_options[ARRAY_SIZE (main_options)];
tools/xenmon/xenbaked.c +1 -1
@@ -436,7 +436,7 @@ static struct t_struct *map_tbufs(unsigned long tbufs_mfn, unsigned int num,*/ static unsigned int get_num_cpus (void ) { -xc_physinfo_t physinfo = {0 }; +xc_physinfo_t physinfo;xc_interface *xc_handle =xc_interface_open (0 ,0 ,0 );int ret;
tools/xentrace/xentrace.c +1 -1
@@ -589,7 +589,7 @@ static void set_evt_mask(uint32_t mask)*/ static unsigned int get_num_cpus (void ) { -xc_physinfo_t physinfo = {0 }; +xc_physinfo_t physinfo;int ret; ret =xc_physinfo (xc_handle, &physinfo);
Signature · 1 line
2.11.0
Hi Andrew,
Quoted 113 lines
-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Andrew Cooper
Sent: 2021年12月24日 0:23
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Anthony PERARD <[email protected]>; Juergen Gross <[email protected]>
Subject: [PATCH]tools/libxc: Drop copy-in inxc_physinfo()The first thing
XEN_SYSCTL_physinfodoes is zeroop->u.physinfo.Do not copy-in. It's pointless, and most callers don't initialise their
xc_physinfo_tbuffer to begin with. Remove the pointless zeroing from the remaining callers.Spotted by Coverity.
Signed-off-by Andrew Cooper <[email protected]>---
CC: Anthony PERARD <[email protected]>
CC: Juergen Gross <[email protected]>--- tools/libs/ctrl/xc_misc.c | 2 -- tools/libs/light/libxl.c | 2 +- tools/libs/stat/xenstat.c | 2 +- tools/misc/xenpm.c | 2 +- tools/xenmon/xenbaked.c | 2 +- tools/xentrace/xentrace.c | 2 +- 6 files changed, 5 insertions(+), 7 deletions(-)tools/libs/ctrl/xc_misc.c +0
-2@@ -195,8 +195,6 @@ int xc_physinfo(xc_interface *xch, sysctl.cmd = XEN_SYSCTL_physinfo; -memcpy (&sysctl.u.physinfo, put_info,sizeof (*put_info)); -if ( (ret =do_sysctl (xch, &sysctl)) !=0 )return ret;tools/libs/light/libxl.c +1
-1@@ -351,7 +351,7 @@ const char *libxl_defbool_to_string(libxl_defbool b)/************************************************************************* *****/ int libxl_get_physinfo (libxl_ctx *ctx,libxl_physinfo *physinfo) { -xc_physinfo_t xcphysinfo = {0 }; +xc_physinfo_t xcphysinfo;int rc;long l; GC_INIT(ctx);tools/libs/stat/xenstat.c +1
-1@@ -135,7 +135,7 @@ xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags) {#define DOMAIN_CHUNK_SIZE 256xenstat_node *node; -xc_physinfo_t physinfo = {0 }; +xc_physinfo_t physinfo;xc_domaininfo_t domaininfo[DOMAIN_CHUNK_SIZE ];int new_domains;tools/libs/stat/xenstat.c +0
-0unsigned int i;tools/misc/xenpm.c +1
-1@@ -1244,7 +1244,7 @@ struct {int main (int argc,char *argv[]) {int i, ret =0 ; -xc_physinfo_t physinfo = {0 }; +xc_physinfo_t physinfo;int nr_matches =0 ;int matches_main_options[ARRAY_SIZE (main_options)];tools/xenmon/xenbaked.c +1
-1@@ -436,7 +436,7 @@ static struct t_struct *map_tbufs(unsigned longtbufs_mfn, unsigned int num, */ static unsigned int get_num_cpus (void ) { -xc_physinfo_t physinfo = {0 }; +xc_physinfo_t physinfo;xc_interface *xc_handle =xc_interface_open (0 ,0 ,0 );int ret;tools/xentrace/xentrace.c +1
-2@@ -589,7 +589,7 @@ static void set_evt_mask(uint32_t mask)*/ static unsigned int get_num_cpus (void ) { -xc_physinfo_t physinfo = {0 }; +xc_physinfo_t physinfo;int ret; ret =xc_physinfo (xc_handle, &physinfo); --
Quoted 2 lines
2.11.0
Quoted 9 lines · Andrew Cooper
The first thing
XEN_SYSCTL_physinfodoes is zeroop->u.physinfo.Do not copy-in. It's pointless, and most callers don't initialise their
xc_physinfo_tbuffer to begin with. Remove the pointless zeroing from the remaining callers.Spotted by Coverity.
Signed-off-by Andrew Cooper <[email protected]>
Thanks,
Signature · 1 line
Anthony PERARD