summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2012-04-02 17:33:34 +0200
committerKarel Zak2012-04-02 17:33:41 +0200
commit6219c25ecbaf07c4e8c44e24bcc74428b5ec7bf1 (patch)
treebbec664167f8826206d4a0e7f029e86b06027950
parentrtcwake: tiny coding style change (diff)
downloadkernel-qcow2-util-linux-6219c25ecbaf07c4e8c44e24bcc74428b5ec7bf1.tar.gz
kernel-qcow2-util-linux-6219c25ecbaf07c4e8c44e24bcc74428b5ec7bf1.tar.xz
kernel-qcow2-util-linux-6219c25ecbaf07c4e8c44e24bcc74428b5ec7bf1.zip
lib/loopdev: more robust initialization
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--include/loopdev.h2
-rw-r--r--lib/loopdev.c3
2 files changed, 4 insertions, 1 deletions
diff --git a/include/loopdev.h b/include/loopdev.h
index 4e68da81f..906bee03a 100644
--- a/include/loopdev.h
+++ b/include/loopdev.h
@@ -104,6 +104,8 @@ struct loopdev_cxt {
struct loopdev_iter iter; /* scans /sys or /dev for used/free devices */
};
+#define UL_LOOPDEVCXT_EMPTY { .fd = -1, .sysfs = UL_SYSFSCXT_EMPTY }
+
/*
* loopdev_cxt.flags
*/
diff --git a/lib/loopdev.c b/lib/loopdev.c
index f917f187c..fd3f9bae5 100644
--- a/lib/loopdev.c
+++ b/lib/loopdev.c
@@ -144,11 +144,12 @@ int loopcxt_has_device(struct loopdev_cxt *lc)
int loopcxt_init(struct loopdev_cxt *lc, int flags)
{
struct stat st;
+ struct loopdev_cxt dummy = UL_LOOPDEVCXT_EMPTY;
if (!lc)
return -EINVAL;
- memset(lc, 0, sizeof(*lc));
+ memcpy(lc, &dummy, sizeof(dummy));
lc->flags = flags;
loopcxt_set_device(lc, NULL);