@@ -112,6 +112,7 @@ RDMA_AddOptCFlag(CMAKE_C_FLAGS HAVE_C_WARNINGS
"-Wall -Wextra -Wno-sign-compare -Wno-unused-parameter")
RDMA_AddOptCFlag(CMAKE_C_FLAGS HAVE_C_WMISSING_PROTOTYPES "-Wmissing-prototypes")
RDMA_AddOptCFlag(CMAKE_C_FLAGS HAVE_C_WMISSING_DECLARATIONS "-Wmissing-declarations")
+RDMA_AddOptCFlag(CMAKE_C_FLAGS HAVE_C_WWRITE_STRINGS "-Wwrite-strings")
# At some point around 5.4 gcc fixed missing-field-initializers to ignore this
# common idiom we use extensively. Since this is a useful warning for
@@ -61,7 +61,7 @@ struct acm_address {
struct acm_provider {
size_t size;
uint32_t version;
- char *name;
+ const char *name;
int (*open_device)(const struct acm_device *device,
void **dev_context);
void (*close_device)(void *dev_context);
@@ -113,7 +113,7 @@ acm_alloc_sa_mad(const struct acm_endpoint *endpoint, void *context,
extern void acm_free_sa_mad(struct acm_sa_mad *mad);
extern int acm_send_sa_mad(struct acm_sa_mad *mad);
-extern char * acm_get_opts_file(void);
+extern const char *acm_get_opts_file(void);
extern void acm_increment_counter(int type);
#endif /* ACM_PROV_H */
@@ -2868,7 +2868,7 @@ static void acmp_set_options(void)
FILE *f;
char s[120];
char opt[32], value[256];
- char *opts_file = acm_get_opts_file();
+ const char *opts_file = acm_get_opts_file();
if (!(f = fopen(opts_file, "r")))
return;
@@ -221,9 +221,9 @@ static struct sa_data {
/*
* Service options - may be set through ibacm_opts.cfg file.
*/
-static char *acme = IBACM_BIN_PATH "/ib_acme -A";
-static char *opts_file = ACM_CONF_DIR "/" ACM_OPTS_FILE;
-static char *addr_file = ACM_CONF_DIR "/" ACM_ADDR_FILE;
+static const char *acme = IBACM_BIN_PATH "/ib_acme -A";
+static const char *opts_file = ACM_CONF_DIR "/" ACM_OPTS_FILE;
+static const char *addr_file = ACM_CONF_DIR "/" ACM_ADDR_FILE;
static char log_file[128] = IBACM_LOG_FILE;
static int log_level = 0;
static char lock_file[128] = IBACM_PID_FILE;
@@ -292,7 +292,7 @@ int ib_any_gid(union ibv_gid *gid)
return ((gid->global.subnet_prefix | gid->global.interface_id) == 0);
}
-char * acm_get_opts_file(void)
+const char *acm_get_opts_file(void)
{
return opts_file;
}
@@ -53,6 +53,6 @@ typedef void (*acm_if_iter_cb)(char *ifname, union ibv_gid *gid, uint16_t pkey,
char *ip_str, void *ctx);
int acm_if_iter_sys(acm_if_iter_cb cb, void *ctx);
-char **parse(char *args, int *count);
+char **parse(const char *args, int *count);
#endif /* ACM_IF_H */
@@ -44,13 +44,13 @@
#include "libacm.h"
#include "acm_util.h"
-static char *dest_dir = ACM_CONF_DIR;
-static char *addr_file = ACM_ADDR_FILE;
-static char *opts_file = ACM_OPTS_FILE;
+static const char *dest_dir = ACM_CONF_DIR;
+static const char *addr_file = ACM_ADDR_FILE;
+static const char *opts_file = ACM_OPTS_FILE;
static char *dest_addr;
static char *src_addr;
-static char *svc_arg = "localhost";
+static const char *svc_arg = "localhost";
static char *dest_arg;
static char *src_arg;
static char addr_type = 'u';
@@ -70,7 +70,7 @@ static char *expand(char *basename, char *args, int *str_cnt, int *str_size)
return str_buf;
}
-char **parse(char *args, int *count)
+char **parse(const char *args, int *count)
{
char **ptrs = NULL;
char *str_buf, *cpy, *token, *next;
@@ -225,7 +225,7 @@ int send_iwpm_nlmsg(int, struct nl_msg *, int);
struct nl_msg *create_iwpm_nlmsg(__u16, int);
-void print_iwpm_sockaddr(struct sockaddr_storage *, char *, __u32);
+void print_iwpm_sockaddr(struct sockaddr_storage *, const char *, __u32);
__be16 get_sockaddr_port(struct sockaddr_storage *sockaddr);
@@ -39,7 +39,7 @@
#endif
/* iwpm config params */
-static char * iwpm_param_names[IWPM_PARAM_NUM] =
+static const char * iwpm_param_names[IWPM_PARAM_NUM] =
{ "nl_sock_rbuf_size" };
static int iwpm_param_vals[IWPM_PARAM_NUM] =
{ 0 };
@@ -609,8 +609,9 @@ int is_wcard_ipaddr(struct sockaddr_storage *search_addr)
* print_iwpm_sockaddr - Print socket address (IP address and Port)
* @sockaddr: socket address to print
* @msg: message to print
- */
-void print_iwpm_sockaddr(struct sockaddr_storage *sockaddr, char *msg, __u32 dbg_flag)
+ */
+void print_iwpm_sockaddr(struct sockaddr_storage *sockaddr, const char *msg,
+ __u32 dbg_flag)
{
struct sockaddr_in6 *sockaddr_v6;
struct sockaddr_in *sockaddr_v4;
@@ -42,11 +42,11 @@
#include "ibverbs.h"
-static char *sysfs_path;
+static const char *sysfs_path;
const char *ibv_get_sysfs_path(void)
{
- char *env = NULL;
+ const char *env = NULL;
if (sysfs_path)
return sysfs_path;
@@ -60,12 +60,13 @@ const char *ibv_get_sysfs_path(void)
if (env) {
int len;
+ char *dup;
- sysfs_path = strndup(env, IBV_SYSFS_PATH_MAX);
- len = strlen(sysfs_path);
- while (len > 0 && sysfs_path[len - 1] == '/') {
+ sysfs_path = dup = strndup(env, IBV_SYSFS_PATH_MAX);
+ len = strlen(dup);
+ while (len > 0 && dup[len - 1] == '/') {
--len;
- sysfs_path[len] = '\0';
+ dup[len] = '\0';
}
} else
sysfs_path = "/sys";
@@ -75,7 +75,7 @@ static struct cmatest test;
static int connections = 1;
static int message_size = 100;
static int message_count = 10;
-static char *port = "7471";
+static const char *port = "7471";
static uint8_t set_tos = 0;
static uint8_t tos;
static uint8_t migrate = 0;
@@ -48,7 +48,7 @@
static struct rdma_addrinfo hints, *rai;
static struct rdma_event_channel *channel;
-static char *port = "7471";
+static const char *port = "7471";
static char *dst_addr;
static char *src_addr;
static int timeout = 2000;
@@ -66,7 +66,7 @@ enum step {
STEP_CNT
};
-static char *step_str[] = {
+static const char *step_str[] = {
"create id",
"bind addr",
"resolve addr",
@@ -47,7 +47,7 @@
int use_rs = 1;
-int get_rdma_addr(char *src, char *dst, char *port,
+int get_rdma_addr(const char *src, const char *dst, const char *port,
struct rdma_addrinfo *hints, struct rdma_addrinfo **rai)
{
struct rdma_addrinfo rai_hints, *res;
@@ -78,7 +78,7 @@ enum rs_optimization {
opt_bandwidth
};
-int get_rdma_addr(char *src, char *dst, char *port,
+int get_rdma_addr(const char *src, const char *dst, const char *port,
struct rdma_addrinfo *hints, struct rdma_addrinfo **rai);
void size_str(char *str, size_t ssize, long long size);
@@ -52,7 +52,7 @@ union rsocket_address {
struct sockaddr_storage storage;
};
-static char *port = "7427";
+static const char *port = "7427";
static char *dst_addr;
static char *dst_file;
static char *src_file;
@@ -36,8 +36,8 @@
#include <rdma/rdma_cma.h>
#include <rdma/rdma_verbs.h>
-static char *server = "127.0.0.1";
-static char *port = "7471";
+static const char *server = "127.0.0.1";
+static const char *port = "7471";
static struct rdma_cm_id *id;
static struct ibv_mr *mr, *send_mr;
@@ -36,7 +36,7 @@
#include <rdma/rdma_cma.h>
#include <rdma/rdma_verbs.h>
-static char *port = "7471";
+static const char *port = "7471";
static struct rdma_cm_id *listen_id, *id;
static struct ibv_mr *mr, *send_mr;
@@ -37,7 +37,7 @@
#include <rdma/rdma_cma.h>
#include <rdma/rdma_verbs.h>
-static char *server = "127.0.0.1";
+static const char *server = "127.0.0.1";
static char port[6] = "7471";
static struct rdma_cm_id *id;
@@ -38,7 +38,7 @@
#include <rdma/rdma_cma.h>
#include <rdma/rdma_verbs.h>
-static char *port = "7471";
+static const char *port = "7471";
static struct rdma_cm_id *listen_id, *id;
static struct ibv_mr *mr;
@@ -88,7 +88,7 @@ static int transfer_size = 1000;
static int transfer_count = 1000;
static int buffer_size, inline_size = 64;
static char test_name[10] = "custom";
-static char *port = "7471";
+static const char *port = "7471";
static char *dst_addr;
static char *src_addr;
static struct timeval start, end;
@@ -1138,7 +1138,7 @@ static int get_addr(char *dst, struct sockaddr *addr)
return ret;
}
-static void usage(char *name)
+static void usage(const char *name)
{
printf("%s -s [-vVd] [-S size] [-C count] [-a addr] [-p port]\n",
basename(name));
@@ -90,7 +90,7 @@ static int transfer_size = 1000;
static int transfer_count = 1000;
static int buffer_size, inline_size = 64;
static char test_name[10] = "custom";
-static char *port = "7471";
+static const char *port = "7471";
static int keepalive;
static char *dst_addr;
static char *src_addr;
@@ -72,7 +72,7 @@ static struct cmatest test;
static int connections = 1;
static int message_size = 100;
static int message_count = 10;
-static char *port = "7174";
+static const char *port = "7174";
static uint8_t set_tos = 0;
static uint8_t tos;
static char *dst_addr;
@@ -93,7 +93,7 @@ static int transfer_size = 1000;
static int transfer_count = 1000;
static int buffer_size;
static char test_name[10] = "custom";
-static char *port = "7174";
+static const char *port = "7174";
static char *dst_addr;
static char *src_addr;
static union socket_addr addr;
@@ -82,7 +82,7 @@ enum log_dest { log_to_syslog, log_to_stderr };
static int get_lid(struct umad_resources *umad_res, ib_gid_t *gid, uint16_t *lid);
static const int node_table_response_size = 1 << 18;
-static char *sysfs_path = "/sys";
+static const char *sysfs_path = "/sys";
static enum log_dest s_log_dest = log_to_syslog;
static int wakeup_pipe[2] = { -1, -1 };
@@ -152,7 +152,7 @@ static int check_process_uniqueness(struct config_t *conf)
}
static int srpd_sys_read_string(const char *dir_name, const char *file_name,
- char *str, int max_len)
+ char *str, int max_len)
{
char path[256], *s;
int fd, r;
@@ -177,7 +177,8 @@ static int srpd_sys_read_string(const char *dir_name, const char *file_name,
return 0;
}
-static int srpd_sys_read_gid(char *dir_name, char *file_name, uint8_t *gid)
+static int srpd_sys_read_gid(const char *dir_name, const char *file_name,
+ uint8_t *gid)
{
char buf[64], *str, *s;
uint16_t *ugid = (uint16_t *)gid;
@@ -195,7 +196,8 @@ static int srpd_sys_read_gid(char *dir_name, char *file_name, uint8_t *gid)
return 0;
}
-static int srpd_sys_read_uint64(char *dir_name, char *file_name, uint64_t *u)
+static int srpd_sys_read_uint64(const char *dir_name, const char *file_name,
+ uint64_t *u)
{
char buf[32];
int r;
@@ -234,7 +236,7 @@ static void usage(const char *argv0)
}
static int
-check_equal_uint64(char *dir_name, char *attr, uint64_t val)
+check_equal_uint64(char *dir_name, const char *attr, uint64_t val)
{
uint64_t attr_value;
@@ -245,7 +247,7 @@ check_equal_uint64(char *dir_name, char *attr, uint64_t val)
}
static int
-check_equal_uint16(char *dir_name, char *attr, uint16_t val)
+check_equal_uint16(char *dir_name, const char *attr, uint16_t val)
{
uint64_t attr_value;
@@ -309,7 +311,8 @@ void pr_err(const char *fmt, ...)
}
}
-static int check_not_equal_str(char *dir_name, char *attr, char *value)
+static int check_not_equal_str(const char *dir_name, const char *attr,
+ const char *value)
{
const int MAX_ATTR_STRING_LENGTH=64;
@@ -329,7 +332,8 @@ static int check_not_equal_str(char *dir_name, char *attr, char *value)
return 0;
}
-static int check_not_equal_int(char *dir_name, char *attr, int value)
+static int check_not_equal_int(const char *dir_name, const char *attr,
+ int value)
{
const int MAX_ATTR_STRING_LENGTH=64;
@@ -654,12 +658,13 @@ static void initialize_sysfs(void)
env = getenv("SYSFS_PATH");
if (env) {
int len;
+ char *dup;
- sysfs_path = strndup(env, 256);
- len = strlen(sysfs_path);
- while (len > 0 && sysfs_path[len - 1] == '/') {
+ sysfs_path = dup = strndup(env, 256);
+ len = strlen(dup);
+ while (len > 0 && dup[len - 1] == '/') {
--len;
- sysfs_path[len] = '\0';
+ dup[len] = '\0';
}
}
}
@@ -324,7 +324,7 @@ struct config_t {
int timeout;
int recalc_time;
int print_initiator_ext;
- char *rules_file;
+ const char *rules_file;
struct rule *rules;
int retry_timeout;
int tl_retry_count;
The is useful to detect possible writing to read only memory. The compiler places strings in .rodata so they are unwritable and are technically const. Add consts as necessary, no casts were added so this should be safe. Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com> --- CMakeLists.txt | 1 + ibacm/include/infiniband/acm_prov.h | 4 ++-- ibacm/prov/acmp/src/acmp.c | 2 +- ibacm/src/acm.c | 8 ++++---- ibacm/src/acm_util.h | 2 +- ibacm/src/acme.c | 8 ++++---- ibacm/src/parse.c | 2 +- iwpmd/iwarp_pm.h | 2 +- iwpmd/iwarp_pm_common.c | 7 ++++--- libibverbs/sysfs.c | 13 +++++++------ librdmacm/examples/cmatose.c | 2 +- librdmacm/examples/cmtime.c | 4 ++-- librdmacm/examples/common.c | 2 +- librdmacm/examples/common.h | 2 +- librdmacm/examples/rcopy.c | 2 +- librdmacm/examples/rdma_client.c | 4 ++-- librdmacm/examples/rdma_server.c | 2 +- librdmacm/examples/rdma_xclient.c | 2 +- librdmacm/examples/rdma_xserver.c | 2 +- librdmacm/examples/riostream.c | 2 +- librdmacm/examples/rping.c | 2 +- librdmacm/examples/rstream.c | 2 +- librdmacm/examples/udaddy.c | 2 +- librdmacm/examples/udpong.c | 2 +- srp_daemon/srp_daemon.c | 29 +++++++++++++++++------------ srp_daemon/srp_daemon.h | 2 +- 26 files changed, 60 insertions(+), 52 deletions(-)