[PATCH v2 5/7] libnuma: numa_parse_cpustring and similar should take a const char* parameter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Input string is handled like it was a const and it doesn't actually modify the
string that it is parsing. It raises warning with following C++ reproducer:

using namespace std;

int main (int argc, char **argv)
{
  bitmask *pbm = numa_allocate_cpumask();
  pbm = numa_bitmask_clearall(pbm);

  if ((pbm = numa_parse_cpustring("2-5,8,10")) != NULL) {
    cout << " cpumask bitmask 2-5,8,10            = ";
    for (int n=0;n<numa_num_configured_cpus();++n) {
      cout << numa_bitmask_isbitset(pbm, n);
    }
    cout << endl;
  }
}

Signed-off-by: Petr Holasek <pholasek@xxxxxxxxxx>
---
 affinity.c | 17 +++++++++--------
 affinity.h |  2 +-
 libnuma.c  | 14 +++++++-------
 numa.3     |  8 ++++----
 numa.h     |  8 ++++----
 5 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/affinity.c b/affinity.c
index 2c0cabc..a226b59 100644
--- a/affinity.c
+++ b/affinity.c
@@ -49,14 +49,14 @@
 #include "affinity.h"
 #include "rtnetlink.h"
 
-static int badchar(char *s)
+static int badchar(const char *s)
 {
 	if (strpbrk(s, "/."))
 		return 1;
 	return 0;
 }
 
-static int node_parse_failure(int ret, char *cls, char *dev)
+static int node_parse_failure(int ret, char *cls, const char *dev)
 {
 	if (!cls)
 		cls = "";
@@ -72,7 +72,8 @@ static int node_parse_failure(int ret, char *cls, char *dev)
 }
 
 /* Generic sysfs class lookup */
-static int affinity_class(struct bitmask *mask, char *cls, char *dev)
+static int
+affinity_class(struct bitmask *mask, char *cls, const const char *dev)
 {
 	int ret;
 	while (isspace(*dev))
@@ -121,7 +122,7 @@ static int affinity_class(struct bitmask *mask, char *cls, char *dev)
 
 
 /* Turn file (or device node) into class name */
-static int affinity_file(struct bitmask *mask, char *cls, char *file)
+static int affinity_file(struct bitmask *mask, char *cls, const char *file)
 {
 	struct stat st;
 	DIR *dir;
@@ -249,7 +250,7 @@ static int iif_to_name(int iif, struct ifreq *ifr)
    This generally only attempts to handle simple cases:
    no multi-path, no bounding etc. In these cases only
    the first interface or none is chosen. */
-static int affinity_ip(struct bitmask *mask, char *cls, char *id)
+static int affinity_ip(struct bitmask *mask, char *cls, const char *id)
 {
 	struct addrinfo *ai;
 	int n;
@@ -279,7 +280,7 @@ out_ai:
 }
 
 /* Look up affinity for a PCI device */
-static int affinity_pci(struct bitmask *mask, char *cls, char *id)
+static int affinity_pci(struct bitmask *mask, char *cls, const char *id)
 {
 	unsigned seg, bus, dev, func;
 	int n, ret;
@@ -310,7 +311,7 @@ static struct handler {
 	char first;
 	char *name;
 	char *cls;
-	int (*handler)(struct bitmask *mask, char *cls, char *desc);
+	int (*handler)(struct bitmask *mask, char *cls, const char *desc);
 } handlers[] = {
 	{ 'n', "netdev:", "net",   affinity_class },
 	{ 'i', "ip:",     NULL,    affinity_ip    },
@@ -320,7 +321,7 @@ static struct handler {
 	{}
 };
 
-hidden int resolve_affinity(char *id, struct bitmask *mask)
+hidden int resolve_affinity(const char *id, struct bitmask *mask)
 {
 	struct handler *h;
 
diff --git a/affinity.h b/affinity.h
index 4863d8f..a513749 100644
--- a/affinity.h
+++ b/affinity.h
@@ -2,5 +2,5 @@ enum {
 	NO_IO_AFFINITY = -2
 };
 
-int resolve_affinity(char *id, struct bitmask *mask);
+int resolve_affinity(const char *id, struct bitmask *mask);
 
diff --git a/libnuma.c b/libnuma.c
index 0fb3b11..9c9a1de 100755
--- a/libnuma.c
+++ b/libnuma.c
@@ -1718,7 +1718,7 @@ void numa_set_strict(int flag)
  * Allow a relative node / processor specification within the allowed
  * set if "relative" is nonzero
  */
-static unsigned long get_nr(char *s, char **end, struct bitmask *bmp, int relative)
+static unsigned long get_nr(const char *s, char **end, struct bitmask *bmp, int relative)
 {
 	long i, nr;
 
@@ -1747,7 +1747,7 @@ static unsigned long get_nr(char *s, char **end, struct bitmask *bmp, int relati
  * The caller must free the returned bitmask.
  */
 static struct bitmask *
-__numa_parse_nodestring(char *s, struct bitmask *allowed_nodes_ptr)
+__numa_parse_nodestring(const char *s, struct bitmask *allowed_nodes_ptr)
 {
 	int invert = 0, relative = 0;
 	int conf_nodes = numa_num_configured_nodes();
@@ -1843,7 +1843,7 @@ err:
  * for this task.
  */
 
-struct bitmask * numa_parse_nodestring(char *s)
+struct bitmask * numa_parse_nodestring(const char *s)
 {
 	return __numa_parse_nodestring(s, numa_all_nodes_ptr);
 }
@@ -1853,7 +1853,7 @@ struct bitmask * numa_parse_nodestring(char *s)
  * available.
  */
 
-struct bitmask * numa_parse_nodestring_all(char *s)
+struct bitmask * numa_parse_nodestring_all(const char *s)
 {
 	return __numa_parse_nodestring(s, numa_possible_nodes_ptr);
 }
@@ -1871,7 +1871,7 @@ struct bitmask * numa_parse_nodestring_all(char *s)
  * The caller must free the returned bitmask.
  */
 static struct bitmask *
-__numa_parse_cpustring(char *s, struct bitmask *allowed_cpus_ptr)
+__numa_parse_cpustring(const char *s, struct bitmask *allowed_cpus_ptr)
 {
 	int invert = 0, relative=0;
 	int conf_cpus = numa_num_configured_cpus();
@@ -1956,7 +1956,7 @@ err:
  * for this task.
  */
 
-struct bitmask * numa_parse_cpustring(char *s)
+struct bitmask * numa_parse_cpustring(const char *s)
 {
 	return __numa_parse_cpustring(s, numa_all_cpus_ptr);
 }
@@ -1966,7 +1966,7 @@ struct bitmask * numa_parse_cpustring(char *s)
  * available.
  */
 
-struct bitmask * numa_parse_cpustring_all(char *s)
+struct bitmask * numa_parse_cpustring_all(const char *s)
 {
 	return __numa_parse_cpustring(s, numa_possible_cpus_ptr);
 }
diff --git a/numa.3 b/numa.3
index b302b8f..e0da131 100755
--- a/numa.3
+++ b/numa.3
@@ -50,13 +50,13 @@ numa \- NUMA policy library
 .sp
 .BI "int numa_parse_bitmap(char *" line " , struct bitmask *" mask ");
 .br
-.BI "struct bitmask *numa_parse_nodestring(char *" string );
+.BI "struct bitmask *numa_parse_nodestring(const char *" string );
 .br
-.BI "struct bitmask *numa_parse_nodestring_all(char *" string );
+.BI "struct bitmask *numa_parse_nodestring_all(const char *" string );
 .br
-.BI "struct bitmask *numa_parse_cpustring(char *" string );
+.BI "struct bitmask *numa_parse_cpustring(const char *" string );
 .br
-.BI "struct bitmask *numa_parse_cpustring_all(char *" string );
+.BI "struct bitmask *numa_parse_cpustring_all(const char *" string );
 .sp
 .BI "long numa_node_size(int " node ", long *" freep );
 .br
diff --git a/numa.h b/numa.h
index ea28774..86d3b2e 100755
--- a/numa.h
+++ b/numa.h
@@ -310,18 +310,18 @@ int numa_sched_getaffinity(pid_t, struct bitmask *);
 int numa_sched_setaffinity(pid_t, struct bitmask *);
 
 /* Convert an ascii list of nodes to a bitmask */
-struct bitmask *numa_parse_nodestring(char *);
+struct bitmask *numa_parse_nodestring(const char *);
 
 /* Convert an ascii list of nodes to a bitmask without current nodeset
  * dependency */
-struct bitmask *numa_parse_nodestring_all(char *);
+struct bitmask *numa_parse_nodestring_all(const char *);
 
 /* Convert an ascii list of cpu to a bitmask */
-struct bitmask *numa_parse_cpustring(char *);
+struct bitmask *numa_parse_cpustring(const char *);
 
 /* Convert an ascii list of cpu to a bitmask without current taskset
  * dependency */
-struct bitmask *numa_parse_cpustring_all(char *);
+struct bitmask *numa_parse_cpustring_all(const char *);
 
 /*
  * The following functions are for source code compatibility
-- 
1.7.11.4

--
To unsubscribe from this list: send the line "unsubscribe linux-numa" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]     [Devices]

  Powered by Linux