From patchwork Mon Jul 15 13:00:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 2827486 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3009FC0AB2 for ; Mon, 15 Jul 2013 13:07:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EC8782015F for ; Mon, 15 Jul 2013 13:06:58 +0000 (UTC) Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by mail.kernel.org (Postfix) with ESMTP id 9BD812015C for ; Mon, 15 Jul 2013 13:06:57 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r6FD24EV015528; Mon, 15 Jul 2013 09:02:04 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r6FD0iAc029328 for ; Mon, 15 Jul 2013 09:00:44 -0400 Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.20]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r6FD0eKv006050 for ; Mon, 15 Jul 2013 09:00:44 -0400 Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r6FD0dqQ013062 for ; Mon, 15 Jul 2013 09:00:39 -0400 Received: from relay1.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 899DEA51FE; Mon, 15 Jul 2013 15:00:36 +0200 (CEST) From: Hannes Reinecke To: Christophe Varoqui Date: Mon, 15 Jul 2013 15:00:26 +0200 Message-Id: <1373893230-26077-26-git-send-email-hare@suse.de> In-Reply-To: <1373893230-26077-1-git-send-email-hare@suse.de> References: <1373893230-26077-1-git-send-email-hare@suse.de> X-RedHat-Spam-Score: -7.69 (BAYES_00, DCC_REPUT_00_12, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, URIBL_BLOCKED) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-Scanned-By: MIMEDefang 2.68 on 10.5.110.20 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com Subject: [dm-devel] [PATCH 25/29] multipathd: valgrind fixes X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development 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-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP valgrind complained about uninitialized memory. As usual, valgrind was right, although the memory never was actually referenced. Signed-off-by: Hannes Reinecke --- libmultipath/discovery.c | 27 +++++++++++++++++---------- libmultipath/sysfs.c | 6 ++++-- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index 092930a..c59dbc2 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -321,7 +321,7 @@ static void sysfs_set_rport_tmo(struct multipath *mpp, struct path *pp) { struct udev_device *rport_dev = NULL; - char value[11]; + char value[16]; char rport_id[32]; unsigned long long tmo = 0; int ret; @@ -349,7 +349,7 @@ sysfs_set_rport_tmo(struct multipath *mpp, struct path *pp) * then set fast_io_fail, and _then_ set dev_loss_tmo * to the correct value. */ - value[0] = '\0'; + memset(value, 0, 16); if (mpp->fast_io_fail != MP_FAST_IO_FAIL_UNSET && mpp->fast_io_fail != MP_FAST_IO_FAIL_ZERO && mpp->fast_io_fail != MP_FAST_IO_FAIL_OFF) { @@ -367,17 +367,18 @@ sysfs_set_rport_tmo(struct multipath *mpp, struct path *pp) goto out; } if (mpp->fast_io_fail >= tmo) { - snprintf(value, 11, "%u", mpp->fast_io_fail); + snprintf(value, 16, "%u", mpp->fast_io_fail); } } else if (mpp->dev_loss > 600) { condlog(3, "%s: limiting dev_loss_tmo to 600, since " "fast_io_fail is not set", rport_id); - snprintf(value, 11, "%u", 600); + snprintf(value, 16, "%u", 600); } else { - snprintf(value, 11, "%u", mpp->dev_loss); + snprintf(value, 16, "%u", mpp->dev_loss); } if (strlen(value)) { - ret = sysfs_attr_set_value(rport_dev, "dev_loss_tmo", value, 11); + ret = sysfs_attr_set_value(rport_dev, "dev_loss_tmo", + value, strlen(value)); if (ret <= 0) { if (ret == -EBUSY) condlog(3, "%s: rport blocked", rport_id); @@ -393,9 +394,9 @@ sysfs_set_rport_tmo(struct multipath *mpp, struct path *pp) else if (mpp->fast_io_fail == MP_FAST_IO_FAIL_ZERO) sprintf(value, "0"); else - snprintf(value, 11, "%u", mpp->fast_io_fail); + snprintf(value, 16, "%u", mpp->fast_io_fail); ret = sysfs_attr_set_value(rport_dev, "fast_io_fail_tmo", - value, 11); + value, strlen(value)); if (ret <= 0) { if (ret == -EBUSY) condlog(3, "%s: rport blocked", rport_id); @@ -405,9 +406,9 @@ sysfs_set_rport_tmo(struct multipath *mpp, struct path *pp) } } if (tmo > 0) { - snprintf(value, 11, "%u", mpp->dev_loss); + snprintf(value, 16, "%u", mpp->dev_loss); ret = sysfs_attr_set_value(rport_dev, "dev_loss_tmo", - value, 11); + value, strlen(value)); if (ret <= 0) { if (ret == -EBUSY) condlog(3, "%s: rport blocked", rport_id); @@ -809,6 +810,9 @@ cciss_sysfs_pathinfo (struct path * pp) static int common_sysfs_pathinfo (struct path * pp) { + if (!pp) + return 1; + if (!pp->udev) { condlog(4, "%s: udev not initialised", pp->dev); return 1; @@ -1059,6 +1063,9 @@ pathinfo (struct path *pp, vector hwtable, int mask) { int path_state; + if (!pp) + return 1; + condlog(3, "%s: mask = 0x%x", pp->dev, mask); /* diff --git a/libmultipath/sysfs.c b/libmultipath/sysfs.c index 0670e0a..8ba27d4 100644 --- a/libmultipath/sysfs.c +++ b/libmultipath/sysfs.c @@ -102,7 +102,7 @@ ssize_t sysfs_attr_set_value(struct udev_device *dev, const char *attr_name, int fd; ssize_t size = -1; - if (!dev || !attr_name || !value) + if (!dev || !attr_name || !value || !value_len) return 0; snprintf(devpath, PATH_SIZE, "%s/%s", udev_device_get_syspath(dev), @@ -152,9 +152,10 @@ sysfs_get_size (struct path *pp, unsigned long long * size) char attr[255]; int r; - if (!pp->udev) + if (!pp->udev || !size) return 1; + attr[0] = '\0'; if (sysfs_attr_get_value(pp->udev, "size", attr, 255) == 0) { condlog(3, "%s: No size attribute in sysfs", pp->dev); return 1; @@ -164,6 +165,7 @@ sysfs_get_size (struct path *pp, unsigned long long * size) if (r != 1) { condlog(3, "%s: Cannot parse size attribute", pp->dev); + *size = 0; return 1; }