Skip to contentSkip to conversation

tools/libxc: Drop copy-in in xc_physinfo()

PATCH In review Andrew Cooper 3 participants 3 messages Dec 23, 2021 – Jan 5, 2022

lore
Share & tools
lore
#0 lore raw

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
index 3820394413a9..265f15ec2da3 100644
@@ -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
index a77aa856fdd6..667ae6409be7 100644
@@ -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
index e49689aa2da9..8bab2e66a7fe 100644
@@ -135,7 +135,7 @@ xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags)
 {
 #define DOMAIN_CHUNK_SIZE 256
 	xenstat_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
index d0191d498484..4f8cde690a7c 100644
@@ -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
index 1ed34334c824..7591de7c609f 100644
@@ -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
index a8903ebf4625..864e30d50cc3 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw

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 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
index 3820394413a9..265f15ec2da3 100644
@@ -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
index a77aa856fdd6..667ae6409be7 100644
@@ -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
index e49689aa2da9..8bab2e66a7fe 100644
@@ -135,7 +135,7 @@ xenstat_node *xenstat_get_node(xenstat_handle * handle,
 unsigned int flags)
 {
 #define DOMAIN_CHUNK_SIZE 256
 	xenstat_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 -0
 	unsigned int i;
tools/misc/xenpm.c +1 -1
index d0191d498484..4f8cde690a7c 100644
@@ -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
index 1ed34334c824..7591de7c609f 100644
@@ -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 -2
index a8903ebf4625..864e30d50cc3 100644
@@ -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

Acked-by on v1 1/1
#2 lore raw
In reply to Andrew Cooper
Quoted 9 lines · Andrew Cooper

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.

Thanks,

Signature · 1 line
Anthony PERARD