All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zdenek Kabelac <zkabelac@sourceware.org>
To: lvm-devel@redhat.com
Subject: main - cleanup: free already does NULL check
Date: Wed, 15 Sep 2021 13:26:29 +0000 (GMT)	[thread overview]
Message-ID: <20210915132629.DACF83858414@sourceware.org> (raw)

Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=ed59b50512f966125b972f9d2eafee3058f8063f
Commit:        ed59b50512f966125b972f9d2eafee3058f8063f
Parent:        73087c2c0fd51b1ff543580dadbf3d02dd49a35d
Author:        Zdenek Kabelac <zkabelac@redhat.com>
AuthorDate:    Wed Sep 15 14:08:12 2021 +0200
Committer:     Zdenek Kabelac <zkabelac@redhat.com>
CommitterDate: Wed Sep 15 15:24:56 2021 +0200

cleanup: free already does NULL check

Drop extra check for NULL before calling free().
Also drop zeroing data that will be free().
---
 daemons/lvmlockd/lvmlockd-core.c | 19 +++++--------------
 daemons/lvmlockd/lvmlockd-idm.c  |  8 ++++----
 2 files changed, 9 insertions(+), 18 deletions(-)

diff --git a/daemons/lvmlockd/lvmlockd-core.c b/daemons/lvmlockd/lvmlockd-core.c
index e53eebfe7..35c9b6c25 100644
--- a/daemons/lvmlockd/lvmlockd-core.c
+++ b/daemons/lvmlockd/lvmlockd-core.c
@@ -438,18 +438,11 @@ static void free_pvs_path(struct pvs *pvs)
 {
 	int i;
 
-	for (i = 0; i < pvs->num; i++) {
-		if (!pvs->path[i])
-			continue;
-
+	for (i = 0; i < pvs->num; i++)
 		free((char *)pvs->path[i]);
-		pvs->path[i] = NULL;
-	}
 
-	if (!pvs->path) {
-		free(pvs->path);
-		pvs->path = NULL;
-	}
+	free(pvs->path);
+	pvs->path = NULL;
 }
 
 static char **alloc_and_copy_pvs_path(struct pvs *dst, struct pvs *src)
@@ -563,10 +556,8 @@ static struct lock *alloc_lock(void)
 
 static void free_action(struct action *act)
 {
-	if (act->path) {
-		free(act->path);
-		act->path = NULL;
-	}
+	free(act->path);
+	act->path = NULL;
 
 	free_pvs_path(&act->pvs);
 
diff --git a/daemons/lvmlockd/lvmlockd-idm.c b/daemons/lvmlockd/lvmlockd-idm.c
index e9f50535c..e13fb62ae 100644
--- a/daemons/lvmlockd/lvmlockd-idm.c
+++ b/daemons/lvmlockd/lvmlockd-idm.c
@@ -456,8 +456,9 @@ int lm_add_lockspace_idm(struct lockspace *ls, int adopt)
 fail:
 	if (lmi && lmi->sock)
 		close(lmi->sock);
-	if (lmi)
-		free(lmi);
+
+	free(lmi);
+
 	return rv;
 }
 
@@ -506,8 +507,7 @@ int lm_rem_resource_idm(struct lockspace *ls, struct resource *r)
 {
 	struct rd_idm *rdi = (struct rd_idm *)r->lm_data;
 
-	if (rdi->vb)
-		free(rdi->vb);
+	free(rdi->vb);
 
 	memset(rdi, 0, sizeof(struct rd_idm));
 	r->lm_init = 0;



                 reply	other threads:[~2021-09-15 13:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210915132629.DACF83858414@sourceware.org \
    --to=zkabelac@sourceware.org \
    --cc=lvm-devel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.