From: Karel Zak Date: Tue, 4 Aug 2015 11:21:42 +0000 (+0200) Subject: libmount: cleanup assert() usage X-Git-Tag: v2.27-rc2~48 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cba392b661d3fcf92d50d0df7c8783e18bb992da;p=thirdparty%2Futil-linux.git libmount: cleanup assert() usage Signed-off-by: Karel Zak --- diff --git a/libmount/src/context.c b/libmount/src/context.c index ec04191fcc..5ab0b794e4 100644 --- a/libmount/src/context.c +++ b/libmount/src/context.c @@ -259,7 +259,6 @@ const char *mnt_context_get_writable_tabpath(struct libmnt_context *cxt) static int set_flag(struct libmnt_context *cxt, int flag, int enable) { - assert(cxt); if (!cxt) return -EINVAL; if (enable) { @@ -1391,7 +1390,6 @@ int mnt_context_get_mflags(struct libmnt_context *cxt, unsigned long *flags) */ int mnt_context_set_user_mflags(struct libmnt_context *cxt, unsigned long flags) { - assert(cxt); if (!cxt) return -EINVAL; cxt->user_mountflags = flags; @@ -1464,9 +1462,6 @@ int mnt_context_prepare_srcpath(struct libmnt_context *cxt) assert(cxt->fs); assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED)); - if (!cxt || !cxt->fs) - return -EINVAL; - DBG(CXT, ul_debugobj(cxt, "preparing source path")); src = mnt_fs_get_source(cxt->fs); @@ -1582,9 +1577,6 @@ int mnt_context_prepare_target(struct libmnt_context *cxt) assert(cxt->fs); assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED)); - if (!cxt || !cxt->fs) - return -EINVAL; - DBG(CXT, ul_debugobj(cxt, "preparing target path")); tgt = mnt_fs_get_target(cxt->fs); @@ -1667,9 +1659,6 @@ int mnt_context_guess_fstype(struct libmnt_context *cxt) DBG(CXT, ul_debugobj(cxt, "preparing fstype")); - if (!cxt || !cxt->fs) - return -EINVAL; - if ((cxt->mountflags & (MS_BIND | MS_MOVE)) || mnt_context_propagation_only(cxt)) goto none; @@ -1921,9 +1910,6 @@ static int apply_table(struct libmnt_context *cxt, struct libmnt_table *tb, assert(cxt); assert(cxt->fs); - if (!cxt->fs) - return -EINVAL; - src = mnt_fs_get_source(cxt->fs); tgt = mnt_fs_get_target(cxt->fs); diff --git a/libmount/src/context_loopdev.c b/libmount/src/context_loopdev.c index 68b8dabc94..787114228c 100644 --- a/libmount/src/context_loopdev.c +++ b/libmount/src/context_loopdev.c @@ -147,9 +147,6 @@ int mnt_context_setup_loopdev(struct libmnt_context *cxt) assert(cxt->fs); assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED)); - if (!cxt) - return -EINVAL; - backing_file = mnt_fs_get_srcpath(cxt->fs); if (!backing_file) return -EINVAL; @@ -317,9 +314,6 @@ int mnt_context_delete_loopdev(struct libmnt_context *cxt) assert(cxt); assert(cxt->fs); - if (!cxt) - return -EINVAL; - src = mnt_fs_get_srcpath(cxt->fs); if (!src) return -EINVAL; @@ -343,9 +337,6 @@ int mnt_context_clear_loopdev(struct libmnt_context *cxt) { assert(cxt); - if (!cxt) - return -EINVAL; - if (mnt_context_get_status(cxt) == 0 && (cxt->flags & MNT_FL_LOOPDEV_READY)) { /* diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c index 210f0f1690..63cba216b3 100644 --- a/libmount/src/context_mount.c +++ b/libmount/src/context_mount.c @@ -159,11 +159,8 @@ static int fix_optstr(struct libmnt_context *cxt) }; #endif assert(cxt); - assert(cxt->fs); assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED)); - if (!cxt) - return -EINVAL; if (!cxt->fs || (cxt->flags & MNT_FL_MOUNTOPTS_FIXED)) return 0; @@ -390,11 +387,8 @@ static int evaluate_permissions(struct libmnt_context *cxt) unsigned long u_flags = 0; assert(cxt); - assert(cxt->fs); assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED)); - if (!cxt) - return -EINVAL; if (!cxt->fs) return 0; @@ -816,7 +810,6 @@ static int do_mount_by_pattern(struct libmnt_context *cxt, const char *pattern) assert(cxt); assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED)); - /* * Use the pattern as list of the filesystems */ @@ -861,11 +854,6 @@ int mnt_context_prepare_mount(struct libmnt_context *cxt) { int rc = -EINVAL; - assert(cxt); - assert(cxt->fs); - assert(cxt->helper_exec_status == 1); - assert(cxt->syscall_status == 1); - if (!cxt || !cxt->fs || mnt_fs_is_swaparea(cxt->fs)) return -EINVAL; if (!mnt_fs_get_source(cxt->fs) && !mnt_fs_get_target(cxt->fs)) @@ -873,6 +861,9 @@ int mnt_context_prepare_mount(struct libmnt_context *cxt) if (cxt->flags & MNT_FL_PREPARED) return 0; + assert(cxt->helper_exec_status == 1); + assert(cxt->syscall_status == 1); + cxt->action = MNT_ACT_MOUNT; DBG(CXT, ul_debugobj(cxt, "mount: preparing")); diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c index 134c92b6e6..c4e9ebbee7 100644 --- a/libmount/src/context_umount.c +++ b/libmount/src/context_umount.c @@ -368,9 +368,6 @@ static int evaluate_permissions(struct libmnt_context *cxt) assert(cxt->fs); assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED)); - if (!cxt || !cxt->fs) - return -EINVAL; - if (!mnt_context_is_restricted(cxt)) return 0; /* superuser mount */ @@ -749,11 +746,6 @@ int mnt_context_prepare_umount(struct libmnt_context *cxt) { int rc; - assert(cxt); - assert(cxt->fs); - assert(cxt->helper_exec_status == 1); - assert(cxt->syscall_status == 1); - if (!cxt || !cxt->fs || mnt_fs_is_swaparea(cxt->fs)) return -EINVAL; if (!mnt_context_get_source(cxt) && !mnt_context_get_target(cxt)) @@ -761,6 +753,9 @@ int mnt_context_prepare_umount(struct libmnt_context *cxt) if (cxt->flags & MNT_FL_PREPARED) return 0; + assert(cxt->helper_exec_status == 1); + assert(cxt->syscall_status == 1); + free(cxt->helper); /* be paranoid */ cxt->helper = NULL; cxt->action = MNT_ACT_UMOUNT; diff --git a/libmount/src/monitor.c b/libmount/src/monitor.c index c33e7d3c61..18142da5c8 100644 --- a/libmount/src/monitor.c +++ b/libmount/src/monitor.c @@ -168,9 +168,6 @@ static int monitor_next_entry(struct libmnt_monitor *mn, assert(itr); assert(me); - if (!mn || !itr || !me) - return -EINVAL; - *me = NULL; if (!itr->head) @@ -277,9 +274,6 @@ static int userspace_monitor_get_fd(struct libmnt_monitor *mn, { int rc; - assert(mn); - assert(me); - if (!me || me->enable == 0) /* not-initialized or disabled */ return -EINVAL; if (me->fd >= 0) @@ -457,9 +451,6 @@ static int kernel_monitor_get_fd(struct libmnt_monitor *mn, { int rc; - assert(mn); - assert(me); - if (!me || me->enable == 0) /* not-initialized or disabled */ return -EINVAL; if (me->fd >= 0) diff --git a/libmount/src/tab.c b/libmount/src/tab.c index 09896ccb61..d616547c89 100644 --- a/libmount/src/tab.c +++ b/libmount/src/tab.c @@ -1148,8 +1148,6 @@ struct libmnt_fs *mnt_table_find_devno(struct libmnt_table *tb, struct libmnt_fs *fs = NULL; struct libmnt_iter itr; - assert(tb); - if (!tb) return NULL; if (direction != MNT_ITER_FORWARD && direction != MNT_ITER_BACKWARD)