From patchwork Tue Feb 20 13:26:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 10230059 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DAFFE60594 for ; Tue, 20 Feb 2018 13:28:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C9F7F28505 for ; Tue, 20 Feb 2018 13:28:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BEE362850D; Tue, 20 Feb 2018 13:28:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1DD9928508 for ; Tue, 20 Feb 2018 13:28:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 21795C0587E3; Tue, 20 Feb 2018 13:28:09 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5D9A55C1A1; Tue, 20 Feb 2018 13:28:08 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 25E1018033F0; Tue, 20 Feb 2018 13:28:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w1KDRske020663 for ; Tue, 20 Feb 2018 08:27:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9F9265D967; Tue, 20 Feb 2018 13:27:54 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 97B235D962; Tue, 20 Feb 2018 13:27:54 +0000 (UTC) Received: from smtp.nue.novell.com (smtp.nue.novell.com [195.135.221.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 311F97854B; Tue, 20 Feb 2018 13:27:52 +0000 (UTC) Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Tue, 20 Feb 2018 14:27:50 +0100 Received: from apollon.suse.de.de (nwb-a10-snat.microfocus.com [10.120.13.201]) by emea4-mta.ukb.novell.com with ESMTP (TLS encrypted); Tue, 20 Feb 2018 13:27:18 +0000 From: Martin Wilck To: Christophe Varoqui , Hannes Reinecke Date: Tue, 20 Feb 2018 14:26:46 +0100 Message-Id: <20180220132658.22295-9-mwilck@suse.com> In-Reply-To: <20180220132658.22295-1-mwilck@suse.com> References: <20180220132658.22295-1-mwilck@suse.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 20 Feb 2018 13:27:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 20 Feb 2018 13:27:53 +0000 (UTC) for IP:'195.135.221.5' DOMAIN:'smtp.nue.novell.com' HELO:'smtp.nue.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 195.135.221.5 smtp.nue.novell.com 195.135.221.5 smtp.nue.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [RFC PATCH 08/20] libmultipath: fix compiler warnings for -Wcast-qual X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 20 Feb 2018 13:28:09 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP Fix the warnings that were caused by adding the -Wcast-qual compiler flag in the previous patch. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- kpartx/devmapper.c | 3 ++- libmpathcmd/mpath_cmd.c | 2 +- libmultipath/checkers/rbd.c | 4 ++-- libmultipath/devmapper.c | 3 ++- libmultipath/discovery.c | 12 ++++++------ libmultipath/list.h | 4 ++-- libmultipath/memory.h | 8 +++++++- libmultipath/structs.c | 2 +- libmultipath/structs.h | 2 +- libmultipath/uevent.c | 6 +++--- libmultipath/util.c | 6 +++--- multipathd/main.c | 10 +++++----- 12 files changed, 35 insertions(+), 27 deletions(-) diff --git a/kpartx/devmapper.c b/kpartx/devmapper.c index 4469fa848de8..eb9dac639175 100644 --- a/kpartx/devmapper.c +++ b/kpartx/devmapper.c @@ -11,6 +11,7 @@ #include #include "devmapper.h" +#define FREE_CONST(p) do { free((void*)(long)p); p = NULL; } while(0) #define _UUID_PREFIX "part" #define UUID_PREFIX _UUID_PREFIX "%d-" #define _UUID_PREFIX_LEN (sizeof(_UUID_PREFIX) - 1) @@ -695,7 +696,7 @@ int dm_find_part(const char *parent, const char *delim, int part, } else *part_uuid = uuid; out: - free((void*)tmp); + FREE_CONST(tmp); return r; } diff --git a/libmpathcmd/mpath_cmd.c b/libmpathcmd/mpath_cmd.c index af618cff917c..29d148ce8aff 100644 --- a/libmpathcmd/mpath_cmd.c +++ b/libmpathcmd/mpath_cmd.c @@ -64,7 +64,7 @@ static size_t write_all(int fd, const void *buf, size_t len) } if (!n) return total; - buf = n + (char *)buf; + buf = n + (const char *)buf; len -= n; total += n; } diff --git a/libmultipath/checkers/rbd.c b/libmultipath/checkers/rbd.c index 2c1800976e40..b1d99b4c81f6 100644 --- a/libmultipath/checkers/rbd.c +++ b/libmultipath/checkers/rbd.c @@ -288,7 +288,7 @@ void libcheck_free(struct checker * c) static int rbd_is_blacklisted(struct rbd_checker_context *ct, char *msg) { char *addr_tok, *start, *save; - char *cmd[2]; + const char *cmd[2]; char *blklist, *stat; size_t blklist_len, stat_len; int ret; @@ -436,7 +436,7 @@ static int sysfs_write_rbd_remove(const char *buf, int buf_len) static int rbd_rm_blacklist(struct rbd_checker_context *ct) { - char *cmd[2]; + const char *cmd[2]; char *stat, *cmd_str; size_t stat_len; int ret; diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index f61838cbe369..607aea8dc1fc 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -27,6 +27,7 @@ #include #include +#define FREE_CONST(p) do { free((void*)(unsigned long)p); p = NULL; } while(0) #define MAX_WAIT 5 #define LOOPS_PER_SEC 5 @@ -1426,7 +1427,7 @@ void dm_reassign_deps(char *table, const char *dep, const char *newdep) n += strlen(newdep); p += strlen(dep); strcat(n, p); - free(newtable); + FREE_CONST(newtable); } int dm_reassign_table(const char *name, char *old, char *new) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index 98bddee52c8f..645224c1029c 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -121,7 +121,7 @@ path_discover (vector pathvec, struct config * conf, if (!devname) return PATHINFO_FAILED; - pp = find_path_by_dev(pathvec, (char *)devname); + pp = find_path_by_dev(pathvec, devname); if (!pp) { char devt[BLK_DEV_SIZE]; dev_t devnum = udev_device_get_devnum(udevice); @@ -905,12 +905,12 @@ static int parse_vpd_pg83(const unsigned char *in, size_t in_len, char *out, size_t out_len) { - unsigned char *d; - unsigned char *vpd = NULL; + const unsigned char *d; + const unsigned char *vpd = NULL; int len = -ENODATA, vpd_type, vpd_len, prio = -1, i, naa_prio; - d = (unsigned char *)in + 4; - while (d < (unsigned char *)in + in_len) { + d = in + 4; + while (d < in + in_len) { /* Select 'association: LUN' */ if ((d[1] & 0x30) != 0) { d += d[3] + 4; @@ -1027,7 +1027,7 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len, out[len] = '\0'; } } else if (vpd_type == 0x1) { - unsigned char *p; + const unsigned char *p; int p_len; out[0] = '1'; diff --git a/libmultipath/list.h b/libmultipath/list.h index 2b1dcf396695..c9110ac9de7e 100644 --- a/libmultipath/list.h +++ b/libmultipath/list.h @@ -18,8 +18,8 @@ * @member: the name of the member within the struct. * */ -#define container_of(ptr, type, member) ({ \ - const typeof( ((type *)0)->member ) *__mptr = (ptr); \ +#define container_of(ptr, type, member) ({ \ + typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) /* diff --git a/libmultipath/memory.h b/libmultipath/memory.h index 927619b58a62..63f59d80584c 100644 --- a/libmultipath/memory.h +++ b/libmultipath/memory.h @@ -43,6 +43,7 @@ int debug; (__FILE__), (char *)(__FUNCTION__), (__LINE__)) ) #define STRDUP(n) ( dbg_strdup((n), \ (__FILE__), (char *)(__FUNCTION__), (__LINE__)) ) +#define FREE_CONST(p) do { FREE((void*)(unsigned long)p); } while(0) /* Memory debug prototypes defs */ extern void *dbg_malloc(unsigned long, char *, char *, int); @@ -54,7 +55,12 @@ extern void dbg_free_final(char *); #else #define MALLOC(n) (calloc(1,(n))) -#define FREE(p) do { free((void*)p); p = NULL; } while(0) +#define FREE(p) do { free(p); p = NULL; } while(0) +/* + * Double cast to avoid warnings with -Wcast-qual + * use this for valid free() operations on const pointers + */ +#define FREE_CONST(p) do { free((void*)(unsigned long)p); p = NULL; } while(0) #define REALLOC(p,n) (realloc((p),(n))) #define STRDUP(n) (strdup(n)) diff --git a/libmultipath/structs.c b/libmultipath/structs.c index 1ade1a6705ad..4db08451824d 100644 --- a/libmultipath/structs.c +++ b/libmultipath/structs.c @@ -418,7 +418,7 @@ find_mp_by_str (vector mpvec, char * str) } struct path * -find_path_by_dev (vector pathvec, char * dev) +find_path_by_dev (vector pathvec, const char * dev) { int i; struct path * pp; diff --git a/libmultipath/structs.h b/libmultipath/structs.h index 71b37cc20674..bccc845a1222 100644 --- a/libmultipath/structs.h +++ b/libmultipath/structs.h @@ -387,7 +387,7 @@ struct multipath * find_mp_by_str (vector mp, char * wwid); struct multipath * find_mp_by_minor (vector mp, int minor); struct path * find_path_by_devt (vector pathvec, const char * devt); -struct path * find_path_by_dev (vector pathvec, char * dev); +struct path * find_path_by_dev (vector pathvec, const char * dev); struct path * first_path (struct multipath * mpp); int pathcountgr (struct pathgroup *, int); diff --git a/libmultipath/uevent.c b/libmultipath/uevent.c index 8f4129ca7fd0..685ef3362c6d 100644 --- a/libmultipath/uevent.c +++ b/libmultipath/uevent.c @@ -157,7 +157,7 @@ static int uevent_get_env_positive_int(const struct uevent *uev, void uevent_get_wwid(struct uevent *uev) { - char *uid_attribute; + const char *uid_attribute; const char *val; struct config * conf; @@ -167,8 +167,8 @@ uevent_get_wwid(struct uevent *uev) val = uevent_get_env_var(uev, uid_attribute); if (val) - uev->wwid = (char*)val; - free(uid_attribute); + uev->wwid = val; + FREE_CONST(uid_attribute); } bool diff --git a/libmultipath/util.c b/libmultipath/util.c index 0b43d29d1236..d3dd3eb524d0 100644 --- a/libmultipath/util.c +++ b/libmultipath/util.c @@ -32,7 +32,7 @@ strchop(char *str) int basenamecpy (const char * str1, char * str2, int str2len) { - char *p; + const char *p; if (!str1 || !strlen(str1)) return 0; @@ -43,7 +43,7 @@ basenamecpy (const char * str1, char * str2, int str2len) if (!str2) return 0; - p = (char *)str1 + (strlen(str1) - 1); + p = str1 + (strlen(str1) - 1); while (*--p != '/' && p != str1) continue; @@ -454,7 +454,7 @@ int safe_write(int fd, const void *buf, size_t count) return -errno; } count -= r; - buf = (char *)buf + r; + buf = (const char *)buf + r; } return 0; } diff --git a/multipathd/main.c b/multipathd/main.c index a8a0c302e8fe..b900bb3ec2e3 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -408,7 +408,7 @@ uev_add_map (struct uevent * uev, struct vectors * vecs) pthread_testcancel(); rc = ev_add_map(uev->kernel, alias, vecs); lock_cleanup_pop(vecs->lock); - FREE(alias); + FREE_CONST(alias); return rc; } @@ -532,7 +532,7 @@ uev_remove_map (struct uevent * uev, struct vectors * vecs) remove_map_and_stop_waiter(mpp, vecs, 1); out: lock_cleanup_pop(vecs->lock); - FREE(alias); + FREE_CONST(alias); return 0; } @@ -1028,11 +1028,11 @@ uev_pathfail_check(struct uevent *uev, struct vectors *vecs) pp->dev); out_lock: lock_cleanup_pop(vecs->lock); - FREE(devt); - FREE(action); + FREE_CONST(devt); + FREE_CONST(action); return r; out: - FREE(action); + FREE_CONST(action); return 1; }