From patchwork Sun Dec 10 04:54:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rosen Penev X-Patchwork-Id: 846644 X-Patchwork-Delegate: blogic@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="kq/8TWXN"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ZCBf1Bow"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yvYgj0J5qz9s83 for ; Sun, 10 Dec 2017 15:55:45 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:Message-Id: Date:To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=+8VQzU7e8OCQ6m1QmMeJ20Yk+gHaU6HsB6GUb9wmat0=; b=kq/8TWXNlnQFG8 gVBx8aIDE6gxpA/RpcUnNNxLX16+iMzvqGggKOUr6LWYsXXnQ5aGILXL7SaVhfYN3wTAVcGay/a5H sjYs3ZiM7ZthPw4+r2h41vuyMw+CrutsSCJaXAfGtokEu4DJ8CumzS+xiwmRg4hx+7vee4VdykZZf I/B3o27hbfVZOUcxLONfsQS2oN++LefmOuiHOFKARP1ADe4BMRSyHCFKcmRXPHUJ8ZoAFSxzDCXN4 1vR0nzCwe3zEvZ0gHsRkIeph968dz6/40l7e5eQ401+iiZu19jJhwFfhtg/Bgjxhv7qkApbRSTVSD Hs4dtOBmCik7sgJe+Riw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eNteC-0005ZP-80; Sun, 10 Dec 2017 04:55:28 +0000 Received: from mail-pg0-x233.google.com ([2607:f8b0:400e:c05::233]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eNtdo-0004DI-VJ for lede-dev@lists.infradead.org; Sun, 10 Dec 2017 04:55:06 +0000 Received: by mail-pg0-x233.google.com with SMTP id f12so8929906pgo.5 for ; Sat, 09 Dec 2017 20:54:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=eMYCW2bf87FMLeLbu4576SqscrNvzbLQ36VMAO6xkNs=; b=ZCBf1Bow6LYdUsGdISxxk9h4U7AA2+5pzqouLFGsT89p3WkbxLmFJAqSwm2CxANUn6 bj8ovsvo4iO4NOnJ0QPtvYTt7uB4rZzQ/a0XAPj+BI//+XSUzm4z7VDK9gxJn1+apYYx fdj27IOrX0WVhS8PrwRTETadYsY1pE8LdWIFWkP6ri363YPsdiEqgHO822wQArgesCLy dNzIyZulu0W9B7pvztA2HlM+xiIwUhr0C4tRy+83Uz0hjOf66xvybF1zKwzvedfqh+YT zegzd4FOrWipUzTHz10aKYwjHQndgWsSbgu19Zc55yb5J0mnhNSnIThELwo+iqa2/RGU Oz0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=eMYCW2bf87FMLeLbu4576SqscrNvzbLQ36VMAO6xkNs=; b=i3Y5Ra6f7FkOxI9ScJwW32Ak4D5LAO3J8TpZffk/o8CYvvWlZRUjuG5A0pvu9hvKTV RAodpLlmpxbML1lUyLGelDbcjP4+VDjMOwYMuN/GKfTH+HQLg2iXY6yMbN4geMYderJQ YzIPyzFfQaVqRVZKkIiTfpgFADdcmzRQZTRTMrP7RsQyCoqiVMULxXcBw9QzmgsBKRJN h4X8MCBaOydZoQ/FKjyAdCeMXnt7ZsDPBCIz6hg/OVzP6t6EI2PiX+RGWV1kGiJ6zoHe 8gPjXoGDMUHLeyn+5TXWBZVGtOypEDYmCXeyqosKrRaWua0MZn/cjkz7Lks2nMSMieUG L1lg== X-Gm-Message-State: AJaThX6k4kNa4M5Li1bZvm8zhEov45O3ZSskCF083k9fQ/YKskfxXkKX XO8LOkTevgeOffu2U3CUNulirO83 X-Google-Smtp-Source: AGs4zMYGp5qaU5b+Y8p1VyQXm9xqH6POLKKGlkare5Y8/Dfn+gzA5Fjpx/O2HCOvxnBfcmJdq+b8sQ== X-Received: by 10.99.108.7 with SMTP id h7mr33996103pgc.343.1512881682840; Sat, 09 Dec 2017 20:54:42 -0800 (PST) Received: from DESKTOP-CEH0M93.lan ([2001:470:1f05:c3e:f96c:4275:29d7:6090]) by smtp.gmail.com with ESMTPSA id l15sm10534350pgr.56.2017.12.09.20.54.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 09 Dec 2017 20:54:41 -0800 (PST) From: Rosen Penev To: lede-dev@lists.infradead.org Date: Sat, 9 Dec 2017 20:54:41 -0800 Message-Id: <1512881682-28288-1-git-send-email-rosenp@gmail.com> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171209_205505_073381_63EBB730 X-CRM114-Status: GOOD ( 10.07 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2607:f8b0:400e:c05:0:0:0:233 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (rosenp[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain Subject: [LEDE-DEV] [PATCH 1/2] fstools: Replace strerror(errno) with %m format. X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rosen Penev MIME-Version: 1.0 Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Saves 1472 bytes under glibc. No other difference. Signed-off-by: Rosen Penev --- block.c | 32 ++++++++++++++++---------------- jffs2reset.c | 2 +- libfstools/find.c | 2 +- libfstools/mount.c | 7 +++---- libfstools/mtd.c | 4 ++-- libfstools/overlay.c | 20 ++++++++++---------- snapshot.c | 2 +- 7 files changed, 34 insertions(+), 35 deletions(-) diff --git a/block.c b/block.c index d7a9c5f..ab130b9 100644 --- a/block.c +++ b/block.c @@ -1052,8 +1052,8 @@ static int mount_device(struct probe_info *pr, int type) err = handle_mount(pr->dev, target, pr->type, m); if (err) - ULOG_ERR("mounting %s (%s) as %s failed (%d) - %s\n", - pr->dev, pr->type, target, errno, strerror(errno)); + ULOG_ERR("mounting %s (%s) as %s failed (%d) - %m\n", + pr->dev, pr->type, target, errno); else handle_swapfiles(true); return err; @@ -1071,8 +1071,8 @@ static int mount_device(struct probe_info *pr, int type) err = handle_mount(pr->dev, target, pr->type, NULL); if (err) - ULOG_ERR("mounting %s (%s) as %s failed (%d) - %s\n", - pr->dev, pr->type, target, errno, strerror(errno)); + ULOG_ERR("mounting %s (%s) as %s failed (%d) - %m\n", + pr->dev, pr->type, target, errno); else handle_swapfiles(true); return err; @@ -1104,8 +1104,8 @@ static int umount_device(struct probe_info *pr) err = umount2(mp, MNT_DETACH); if (err) - ULOG_ERR("unmounting %s (%s) failed (%d) - %s\n", - pr->dev, mp, errno, strerror(errno)); + ULOG_ERR("unmounting %s (%s) failed (%d) - %m\n", + pr->dev, mp, errno); else ULOG_INFO("unmounted %s (%s)\n", pr->dev, mp); @@ -1134,8 +1134,8 @@ static int mount_action(char *action, char *device, int type) err = umount2(mount_point, MNT_DETACH); if (err) - ULOG_ERR("umount of %s failed (%d) - %s\n", - mount_point, errno, strerror(errno)); + ULOG_ERR("umount of %s failed (%d) - %m\n", + mount_point, errno); free(mount_point); return 0; @@ -1360,8 +1360,8 @@ static int check_extroot(char *path) if (stat(tag, &s)) { fp = fopen(tag, "w+"); if (!fp) { - ULOG_ERR("extroot: failed to write UUID to %s: %d (%s)\n", - tag, errno, strerror(errno)); + ULOG_ERR("extroot: failed to write UUID to %s: %d (%m)\n", + tag, errno); /* return 0 to continue boot regardless of error */ return 0; } @@ -1372,14 +1372,14 @@ static int check_extroot(char *path) fp = fopen(tag, "r"); if (!fp) { - ULOG_ERR("extroot: failed to read UUID from %s: %d (%s)\n", - tag, errno, strerror(errno)); + ULOG_ERR("extroot: failed to read UUID from %s: %d (%m)\n", + tag, errno); return -1; } if (!fgets(uuid, sizeof(uuid), fp)) - ULOG_ERR("extroot: failed to read UUID from %s: %d (%s)\n", - tag, errno, strerror(errno)); + ULOG_ERR("extroot: failed to read UUID from %s: %d (%m)\n", + tag, errno); fclose(fp); if (*uuid && !strcasecmp(uuid, pr->uuid)) @@ -1457,8 +1457,8 @@ static int mount_extroot(char *cfg) (m->options) ? (m->options) : ("")); if (err) { - ULOG_ERR("extroot: mounting %s (%s) on %s failed: %d (%s)\n", - pr->dev, pr->type, path, errno, strerror(errno)); + ULOG_ERR("extroot: mounting %s (%s) on %s failed: %d (%m)\n", + pr->dev, pr->type, path, errno); } else if (m->overlay) { err = check_extroot(path); if (err) diff --git a/jffs2reset.c b/jffs2reset.c index 9a31fdd..dbe0498 100644 --- a/jffs2reset.c +++ b/jffs2reset.c @@ -83,7 +83,7 @@ static int jffs2_mark(struct volume *v) close(fd); if (sz != 4) { - ULOG_ERR("writing %s failed: %s\n", v->blk, strerror(errno)); + ULOG_ERR("writing %s failed: %m\n", v->blk); return -1; } diff --git a/libfstools/find.c b/libfstools/find.c index fcc47a7..b383f57 100644 --- a/libfstools/find.c +++ b/libfstools/find.c @@ -223,7 +223,7 @@ find_filesystem(char *fs) int ret = -1; if (!fp) { - ULOG_ERR("opening /proc/filesystems failed: %s\n", strerror(errno)); + ULOG_ERR("opening /proc/filesystems failed: %m\n"); goto out; } diff --git a/libfstools/mount.c b/libfstools/mount.c index 551f4e7..4dc6e3a 100644 --- a/libfstools/mount.c +++ b/libfstools/mount.c @@ -54,7 +54,7 @@ mount_move(char *oldroot, char *newroot, char *dir) ret = mount(olddir, newdir, NULL, MS_NOATIME | MS_MOVE, NULL); /* if (ret) - ULOG_ERR("failed %s %s: %s\n", olddir, newdir, strerror(errno));*/ + ULOG_ERR("failed %s %s: %m\n", olddir, newdir);*/ return ret; } @@ -73,7 +73,7 @@ pivot(char *new, char *old) ret = pivot_root(new, pivotdir); if (ret < 0) { - ULOG_ERR("pivot_root failed %s %s: %s\n", new, pivotdir, strerror(errno)); + ULOG_ERR("pivot_root failed %s %s: %m\n", new, pivotdir); return -1; } @@ -136,8 +136,7 @@ fopivot(char *rw_root, char *ro_root) /* Mainlined overlayfs has been renamed to "overlay", try that first */ if (mount(overlay, "/mnt", "overlay", MS_NOATIME, mount_options)) { if (mount(overlay, "/mnt", "overlayfs", MS_NOATIME, mount_options)) { - ULOG_ERR("mount failed: %s, options %s\n", - strerror(errno), mount_options); + ULOG_ERR("mount failed: %s, options %m\n", mount_options); return -1; } } diff --git a/libfstools/mtd.c b/libfstools/mtd.c index 2603a15..77c71ee 100644 --- a/libfstools/mtd.c +++ b/libfstools/mtd.c @@ -198,7 +198,7 @@ static int mtd_volume_identify(struct volume *v) sz = read(p->fd, &deadc0de, sizeof(deadc0de)); if (sz != sizeof(deadc0de)) { - ULOG_ERR("reading %s failed: %s\n", v->name, strerror(errno)); + ULOG_ERR("reading %s failed: %m\n", v->name); return -1; } @@ -275,7 +275,7 @@ static int mtd_volume_init(struct volume *v) ret = ioctl(p->fd, MEMGETINFO, &mtdinfo); if (ret) { - ULOG_ERR("ioctl(%d, MEMGETINFO) failed: %s\n", p->fd, strerror(errno)); + ULOG_ERR("ioctl(%d, MEMGETINFO) failed: %m\n", p->fd); } else { struct erase_info_user mtdlock; diff --git a/libfstools/overlay.c b/libfstools/overlay.c index 5a49da2..7ada5ff 100644 --- a/libfstools/overlay.c +++ b/libfstools/overlay.c @@ -102,12 +102,12 @@ static int overlay_mount(struct volume *v, char *fs) { if (mkdir("/tmp/overlay", 0755)) { - ULOG_ERR("failed to mkdir /tmp/overlay: %s\n", strerror(errno)); + ULOG_ERR("failed to mkdir /tmp/overlay: %m\n"); return -1; } if (mount(v->blk, "/tmp/overlay", fs, MS_NOATIME, NULL)) { - ULOG_ERR("failed to mount -t %s %s /tmp/overlay: %s\n", fs, v->blk, strerror(errno)); + ULOG_ERR("failed to mount -t %s %s /tmp/overlay: %m\n", fs, v->blk); return -1; } @@ -129,27 +129,27 @@ switch2jffs(struct volume *v) ret = mount(v->blk, "/rom/overlay", "jffs2", MS_NOATIME, NULL); unlink("/tmp/.switch_jffs2"); if (ret) { - ULOG_ERR("failed - mount -t jffs2 %s /rom/overlay: %s\n", v->blk, strerror(errno)); + ULOG_ERR("failed - mount -t jffs2 %s /rom/overlay: %m\n", v->blk); return -1; } if (mount("none", "/", NULL, MS_NOATIME | MS_REMOUNT, 0)) { - ULOG_ERR("failed - mount -o remount,ro none: %s\n", strerror(errno)); + ULOG_ERR("failed - mount -o remount,ro none: %m\n"); return -1; } if (system("cp -a /tmp/root/* /rom/overlay")) { - ULOG_ERR("failed - cp -a /tmp/root/* /rom/overlay: %s\n", strerror(errno)); + ULOG_ERR("failed - cp -a /tmp/root/* /rom/overlay: %m\n"); return -1; } if (pivot("/rom", "/mnt")) { - ULOG_ERR("failed - pivot /rom /mnt: %s\n", strerror(errno)); + ULOG_ERR("failed - pivot /rom /mnt: %m\n"); return -1; } if (mount_move("/mnt", "/tmp/root", "")) { - ULOG_ERR("failed - mount -o move /mnt /tmp/root %s\n", strerror(errno)); + ULOG_ERR("failed - mount -o move /mnt /tmp/root %m\n"); return -1; } @@ -267,13 +267,13 @@ static int overlay_mount_fs(struct volume *v) char *fstype = overlay_fs_name(volume_identify(v)); if (mkdir("/tmp/overlay", 0755)) { - ULOG_ERR("failed to mkdir /tmp/overlay: %s\n", strerror(errno)); + ULOG_ERR("failed to mkdir /tmp/overlay: %m\n"); return -1; } if (mount(v->blk, "/tmp/overlay", fstype, MS_NOATIME, NULL)) { - ULOG_ERR("failed to mount -t %s %s /tmp/overlay: %s\n", - fstype, v->blk, strerror(errno)); + ULOG_ERR("failed to mount -t %s %s /tmp/overlay: %m\n", + fstype, v->blk); return -1; } diff --git a/snapshot.c b/snapshot.c index bb44cd3..df555e2 100644 --- a/snapshot.c +++ b/snapshot.c @@ -136,7 +136,7 @@ snapshot_mark(int argc, char **argv) close(fd); if (sz != 1) { - ULOG_ERR("writing %s failed: %s\n", v->blk, strerror(errno)); + ULOG_ERR("writing %s failed: %m\n", v->blk); return -1; } From patchwork Sun Dec 10 04:54:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rosen Penev X-Patchwork-Id: 846645 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="o2yZWK03"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="j9CuKsdc"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yvYgj5jxwz9sNc for ; Sun, 10 Dec 2017 15:55:45 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Ev4YO3vqC2I7obEQpoCFTaROZJECqeOLpOLiokkSjZ8=; b=o2yZWK0364kUnA dwAOn/gGhbTO8sKmORKT+xNFZseBEqOSRz6Ydcj7tfi5t7BO1I29KW0NhmE4LxGqukQFS9a7M8/1L cOjzoVNY+SXr/3gap7BF2aLonm5xrg5M5fBmGKIZy3vZoWg14QcbkRLPMsnP3dD9L400ma0aufKW9 jl15gCg0OX5gn4LBxoPZ32fgTYLndFZfVhfu/yBYKRHyLCfP31PTYGg/gDI7YUBJ0s+YF4bccgU4w js0t45yxMAyPh0tqfGWidDuSbuucChegc9BaZSkttfO4Qo1TOdPlicBApQSw7I7kMz6zhQYOaVjX4 0H5Q6U8m+FWfNGFJUVvw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eNteM-0005v5-2s; Sun, 10 Dec 2017 04:55:38 +0000 Received: from mail-pl0-x243.google.com ([2607:f8b0:400e:c01::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eNtdr-0004DN-6x for lede-dev@lists.infradead.org; Sun, 10 Dec 2017 04:55:09 +0000 Received: by mail-pl0-x243.google.com with SMTP id b96so2668132pli.2 for ; Sat, 09 Dec 2017 20:54:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=EHWqDtkX26jx3OhQ78QKIGcB5s9wNKnKqSq6TLEACLU=; b=j9CuKsdcyCtph1RXXp/a7N3BHOyYZjJeMNI8ClVGRURcktSCaX+AnIpC6HdQJ7iSIu YGdJUt/TASJeCSrYTmQE0Z6quzKptBUrlAL/7ZmXo5nGYbLpwoROmOyworNAyZtSkYcG 8PDJlxjjEfRQfUwkh8gYivie0s6uHBwv4LdvlP2SEdlQiWcGalgjHHqHjum70PbF7nrY aZyWEIAqZLrmHbXWSAPFSfvxmIyGMDzg5CoSy3qq032CwtZiGZTSn1bMMwAM4Z00EjSk 5wEP4183xSHESi9VaBn+zq/FS6Lo8o+/+lOwVpNkrs5UKz8jHclCYZ2o4sgFOvt2R4BD Futg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=EHWqDtkX26jx3OhQ78QKIGcB5s9wNKnKqSq6TLEACLU=; b=bPQw9rR+LB+THt6yD67OfMXoIIgyf4wkUly4qFUddD/u/mrtI8vP6rGPfFJQ5lTlD/ pJex43C89Y7omvAZlC1L0hjyl+Kf2iAWcmvmASledJyuHE1MVFlNQT3YIUxo8idXGtUG +aVlTwKMC+ADEP6RmRJLGiuV1SHCao4k42ZZNi1kvJxPcsy1AuPncDfVtJdSYoI6OjSb Sd+iuIdbbq7+H7fiQV/5g2gWZ3v/Ix3C1d9U5vhGY68DyL+mttn3Lt5VwCntKOKylmET fHiG2EROau6OrP7PtElVAA57UHEZjSRrJm4JVhOpzj4cUFEBUHeWysQXhC/ECv1jnk7r qdMQ== X-Gm-Message-State: AKGB3mJ4pj+kFheO8vgUdsOORf4jxGqLYXzyeFFaeIaNqOpHSKMQ442m W13UaBCbDatLXoewlh3LY+VqpC+V X-Google-Smtp-Source: AGs4zMZ0pLOi/+fch32jjSmRBF/0u2FqHmj4azPjLX/tHYQirdgb6/pfkjm5kL8285wyMpqRarMMsg== X-Received: by 10.159.254.24 with SMTP id r24mr24894338pls.333.1512881685979; Sat, 09 Dec 2017 20:54:45 -0800 (PST) Received: from DESKTOP-CEH0M93.lan ([2001:470:1f05:c3e:f96c:4275:29d7:6090]) by smtp.gmail.com with ESMTPSA id l15sm10534350pgr.56.2017.12.09.20.54.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 09 Dec 2017 20:54:45 -0800 (PST) From: Rosen Penev To: lede-dev@lists.infradead.org Date: Sat, 9 Dec 2017 20:54:42 -0800 Message-Id: <1512881682-28288-2-git-send-email-rosenp@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1512881682-28288-1-git-send-email-rosenp@gmail.com> References: <1512881682-28288-1-git-send-email-rosenp@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171209_205507_292447_65F038D5 X-CRM114-Status: GOOD ( 12.19 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2607:f8b0:400e:c01:0:0:0:243 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (rosenp[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain Subject: [LEDE-DEV] [PATCH 2/2] fstools: Fix some errors detected by cppcheck X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rosen Penev MIME-Version: 1.0 Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Mainly plugging memory leaks. Size reduction as well. The calloc change accounts for 272 bytes on this machine for some reason... Signed-off-by: Rosen Penev --- block.c | 6 +++--- blockd.c | 3 +++ libfstools/overlay.c | 2 +- libfstools/rootdisk.c | 7 ++++--- libfstools/snapshot.c | 11 +++++++---- libfstools/ubi.c | 13 +++++++------ libubi/libubi.c | 4 ++-- libubi/ubiutils-common.c | 2 +- 8 files changed, 28 insertions(+), 20 deletions(-) diff --git a/block.c b/block.c index ab130b9..6117701 100644 --- a/block.c +++ b/block.c @@ -316,8 +316,7 @@ static int swap_add(struct uci_section *s) if (!tb[SWAP_UUID] && !tb[SWAP_LABEL] && !tb[SWAP_DEVICE]) return -1; - m = malloc(sizeof(struct mount)); - memset(m, 0, sizeof(struct mount)); + m = calloc(1, sizeof(struct mount)); m->type = TYPE_SWAP; m->uuid = blobmsg_get_strdup(tb[SWAP_UUID]); m->label = blobmsg_get_strdup(tb[SWAP_LABEL]); @@ -1084,7 +1083,7 @@ static int mount_device(struct probe_info *pr, int type) static int umount_device(struct probe_info *pr) { struct mount *m; - char *device = basename(pr->dev); + char *device; char *mp; int err; @@ -1098,6 +1097,7 @@ static int umount_device(struct probe_info *pr) if (!mp) return -1; + device = basename(pr->dev); m = find_block(pr->uuid, pr->label, device, NULL); if (m && m->extroot) return -1; diff --git a/blockd.c b/blockd.c index 3af5390..f7a4dec 100644 --- a/blockd.c +++ b/blockd.c @@ -115,6 +115,9 @@ device_free(struct device *device) char *target = NULL; char *path = NULL, _path[64], *mp; + if (!device) + return; + blobmsg_parse(mount_policy, __MOUNT_MAX, data, blob_data(device->msg), blob_len(device->msg)); diff --git a/libfstools/overlay.c b/libfstools/overlay.c index 7ada5ff..d7a55e6 100644 --- a/libfstools/overlay.c +++ b/libfstools/overlay.c @@ -284,7 +284,7 @@ enum fs_state fs_state_get(const char *dir) { char *path; char valstr[16]; - uint32_t val; + int val; ssize_t len; path = alloca(strlen(dir) + 1 + sizeof("/.fs_state")); diff --git a/libfstools/rootdisk.c b/libfstools/rootdisk.c index dd00c1b..2bb16d4 100644 --- a/libfstools/rootdisk.c +++ b/libfstools/rootdisk.c @@ -171,8 +171,10 @@ static int rootdisk_volume_identify(struct volume *v) fseeko(f, p->offset + 0x400, SEEK_SET); n = fread(&magic, sizeof(magic), 1, f); - if (n != 1) + if (n != 1) { + fclose(f); return -1; + } if (magic == cpu_to_le32(0xF2F52010)) ret = FS_F2FS; @@ -180,13 +182,12 @@ static int rootdisk_volume_identify(struct volume *v) magic = 0; fseeko(f, p->offset + 0x438, SEEK_SET); n = fread(&magic, sizeof(magic), 1, f); + fclose(f); if (n != 1) return -1; if ((le32_to_cpu(magic) & 0xffff) == 0xef53) ret = FS_EXT4; - fclose(f); - return ret; } diff --git a/libfstools/snapshot.c b/libfstools/snapshot.c index 4870cf7..58bed96 100644 --- a/libfstools/snapshot.c +++ b/libfstools/snapshot.c @@ -203,16 +203,19 @@ snapshot_read_file(struct volume *v, int block, char *file, uint32_t type) if (hdr.length < len) len = hdr.length; - if (volume_read(v, buffer, offset, len)) + if (volume_read(v, buffer, offset, len)) { + close(out); return -1; - if (write(out, buffer, len) != len) + } + + int w = write(out, buffer, len); + close(out); + if (w != len) return -1; offset += len; hdr.length -= len; } - close(out); - if (verify_file_hash(file, hdr.md5)) { ULOG_ERR("md5 verification failed\n"); unlink(file); diff --git a/libfstools/ubi.c b/libfstools/ubi.c index f9d6e0a..678b8bf 100644 --- a/libfstools/ubi.c +++ b/libfstools/ubi.c @@ -60,6 +60,7 @@ static char FILE *f; char fname[BUFLEN]; char buf[BUFLEN]; + char *s; int i; snprintf(fname, sizeof(fname), "%s/%s", dirname, filename); @@ -68,10 +69,10 @@ static char if (!f) return NULL; - if (fgets(buf, sizeof(buf), f) == NULL) - return NULL; - + s = fgets(buf, sizeof(buf), f); fclose(f); + if (s == NULL) + return NULL; /* make sure the string is \0 terminated */ buf[sizeof(buf) - 1] = '\0'; @@ -84,17 +85,17 @@ static char return strdup(buf); } -static unsigned int +static bool test_open(char *filename) { FILE *f; f = fopen(filename, "r"); if (!f) - return 0; + return false; fclose(f); - return 1; + return true; } static int ubi_volume_init(struct volume *v) diff --git a/libubi/libubi.c b/libubi/libubi.c index 3328ac8..3082a10 100644 --- a/libubi/libubi.c +++ b/libubi/libubi.c @@ -427,6 +427,7 @@ static int vol_node2nums(struct libubi *lib, const char *node, int *dev_num, return -1; } + close(fd); *dev_num = i; *vol_id = minor - 1; errno = 0; @@ -1021,9 +1022,8 @@ int ubi_mkvol(libubi_t desc, const char *node, struct ubi_mkvol_request *req) struct ubi_mkvol_req r; size_t n; - memset(&r, 0, sizeof(struct ubi_mkvol_req)); - desc = desc; + memset(&r, 0, sizeof(struct ubi_mkvol_req)); r.vol_id = req->vol_id; r.alignment = req->alignment; r.bytes = req->bytes; diff --git a/libubi/ubiutils-common.c b/libubi/ubiutils-common.c index 2271927..8ea2815 100644 --- a/libubi/ubiutils-common.c +++ b/libubi/ubiutils-common.c @@ -119,7 +119,7 @@ void ubiutils_print_bytes(long long bytes, int bracket) printf("%s%.1f GiB", p, (double)bytes / (1024 * 1024 * 1024)); else if (bytes > 1024 * 1024) printf("%s%.1f MiB", p, (double)bytes / (1024 * 1024)); - else if (bytes > 1024 && bytes != 0) + else if (bytes > 1024) printf("%s%.1f KiB", p, (double)bytes / 1024); else return;