Linux Device Mapper development
 help / color / mirror / Atom feed
* [PATCH 1/1] dm: Deletion of unnecessary checks before two function calls
       [not found]                                 ` <5317A59D.4@users.sourceforge.net>
@ 2014-11-19 20:55                                   ` SF Markus Elfring
  0 siblings, 0 replies; 7+ messages in thread
From: SF Markus Elfring @ 2014-11-19 20:55 UTC (permalink / raw)
  To: Alasdair Kergon, Mike Snitzer, Neil Brown, dm-devel, linux-raid
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 19 Nov 2014 21:48:10 +0100

The functions dm_table_destroy() and vfree() perform also input
parameter validation. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/md/dm-ioctl.c           |  3 +--
 drivers/md/dm-snap-persistent.c | 12 ++++--------
 2 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
index 5152142..0b925a4 100644
--- a/drivers/md/dm-ioctl.c
+++ b/drivers/md/dm-ioctl.c
@@ -1050,8 +1050,7 @@ static int do_resume(struct dm_ioctl *param)
 	 * Since dm_swap_table synchronizes RCU, nobody should be in
 	 * read-side critical section already.
 	 */
-	if (old_map)
-		dm_table_destroy(old_map);
+	dm_table_destroy(old_map);
 
 	if (!r)
 		__dev_status(md, param);
diff --git a/drivers/md/dm-snap-persistent.c b/drivers/md/dm-snap-persistent.c
index d6e8817..4b29bac 100644
--- a/drivers/md/dm-snap-persistent.c
+++ b/drivers/md/dm-snap-persistent.c
@@ -200,16 +200,13 @@ err_area:
 
 static void free_area(struct pstore *ps)
 {
-	if (ps->area)
-		vfree(ps->area);
+	vfree(ps->area);
 	ps->area = NULL;
 
-	if (ps->zero_area)
-		vfree(ps->zero_area);
+	vfree(ps->zero_area);
 	ps->zero_area = NULL;
 
-	if (ps->header_area)
-		vfree(ps->header_area);
+	vfree(ps->header_area);
 	ps->header_area = NULL;
 }
 
@@ -605,8 +602,7 @@ static void persistent_dtr(struct dm_exception_store *store)
 	free_area(ps);
 
 	/* Allocated in persistent_read_metadata */
-	if (ps->callbacks)
-		vfree(ps->callbacks);
+	vfree(ps->callbacks);
 
 	kfree(ps);
 }
-- 
2.1.3

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 1/3] dm snapshot: Deletion of unnecessary checks before the function call "vfree"
       [not found]                                 ` <54CF93BB.40206@users.sourceforge.net>
@ 2015-02-02 15:17                                   ` SF Markus Elfring
  2015-02-02 15:23                                   ` [PATCH 3/3] dm ioctl: Delete an unnecessary check before the function call "dm_table_destroy" SF Markus Elfring
  1 sibling, 0 replies; 7+ messages in thread
From: SF Markus Elfring @ 2015-02-02 15:17 UTC (permalink / raw)
  To: Alasdair Kergon, Mike Snitzer, Neil Brown, dm-devel, linux-raid
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 2 Feb 2015 14:38:29 +0100

The vfree() function performs also input parameter validation.
Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/md/dm-snap-persistent.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/md/dm-snap-persistent.c b/drivers/md/dm-snap-persistent.c
index d6e8817..808b841 100644
--- a/drivers/md/dm-snap-persistent.c
+++ b/drivers/md/dm-snap-persistent.c
@@ -200,16 +200,11 @@ err_area:
 
 static void free_area(struct pstore *ps)
 {
-	if (ps->area)
-		vfree(ps->area);
+	vfree(ps->area);
 	ps->area = NULL;
-
-	if (ps->zero_area)
-		vfree(ps->zero_area);
+	vfree(ps->zero_area);
 	ps->zero_area = NULL;
-
-	if (ps->header_area)
-		vfree(ps->header_area);
+	vfree(ps->header_area);
 	ps->header_area = NULL;
 }
 
@@ -605,8 +600,7 @@ static void persistent_dtr(struct dm_exception_store *store)
 	free_area(ps);
 
 	/* Allocated in persistent_read_metadata */
-	if (ps->callbacks)
-		vfree(ps->callbacks);
+	vfree(ps->callbacks);
 
 	kfree(ps);
 }
-- 
2.2.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] dm ioctl: Delete an unnecessary check before the function call "dm_table_destroy"
       [not found]                                 ` <54CF93BB.40206@users.sourceforge.net>
  2015-02-02 15:17                                   ` [PATCH 1/3] dm snapshot: Deletion of unnecessary checks before the function call "vfree" SF Markus Elfring
@ 2015-02-02 15:23                                   ` SF Markus Elfring
  2015-02-06 21:12                                     ` Mike Snitzer
  1 sibling, 1 reply; 7+ messages in thread
From: SF Markus Elfring @ 2015-02-02 15:23 UTC (permalink / raw)
  To: Alasdair Kergon, Mike Snitzer, Neil Brown, dm-devel, linux-raid
  Cc: LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 2 Feb 2015 15:30:37 +0100

The dm_table_destroy() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/md/dm-ioctl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
index 73f791b..4fac6cf 100644
--- a/drivers/md/dm-ioctl.c
+++ b/drivers/md/dm-ioctl.c
@@ -1053,8 +1053,7 @@ static int do_resume(struct dm_ioctl *param)
 	 * Since dm_swap_table synchronizes RCU, nobody should be in
 	 * read-side critical section already.
 	 */
-	if (old_map)
-		dm_table_destroy(old_map);
+	dm_table_destroy(old_map);
 
 	if (!r)
 		__dev_status(md, param);
-- 
2.2.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] dm ioctl: Delete an unnecessary check before the function call "dm_table_destroy"
  2015-02-02 15:23                                   ` [PATCH 3/3] dm ioctl: Delete an unnecessary check before the function call "dm_table_destroy" SF Markus Elfring
@ 2015-02-06 21:12                                     ` Mike Snitzer
  2015-02-08  9:55                                       ` SF Markus Elfring
  0 siblings, 1 reply; 7+ messages in thread
From: Mike Snitzer @ 2015-02-06 21:12 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: Alasdair Kergon, Neil Brown, dm-devel, linux-raid, Julia Lawall,
	kernel-janitors, LKML

On Mon, Feb 02 2015 at 10:23am -0500,
SF Markus Elfring <elfring@users.sourceforge.net> wrote:

> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Mon, 2 Feb 2015 15:30:37 +0100
> 
> The dm_table_destroy() function tests whether its argument is NULL and then
> returns immediately. Thus the test around the call is not needed.
> 
> This issue was detected by using the Coccinelle software.

Your proposed patch (while technically correct) hurts code clarity.

Nack.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] dm ioctl: Delete an unnecessary check before the function call "dm_table_destroy"
  2015-02-06 21:12                                     ` Mike Snitzer
@ 2015-02-08  9:55                                       ` SF Markus Elfring
  2015-02-08 14:02                                         ` Mike Snitzer
  0 siblings, 1 reply; 7+ messages in thread
From: SF Markus Elfring @ 2015-02-08  9:55 UTC (permalink / raw)
  To: Mike Snitzer
  Cc: Alasdair Kergon, Neil Brown, dm-devel, linux-raid, Julia Lawall,
	kernel-janitors, LKML

> Your proposed patch (while technically correct) hurts code clarity.

How many source code readability and understanding challenges does each
additional condition check cause?

Can the affected place become also a bit more efficient?

Regards,
Markus

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] dm ioctl: Delete an unnecessary check before the function call "dm_table_destroy"
  2015-02-08  9:55                                       ` SF Markus Elfring
@ 2015-02-08 14:02                                         ` Mike Snitzer
  2015-02-08 15:52                                           ` SF Markus Elfring
  0 siblings, 1 reply; 7+ messages in thread
From: Mike Snitzer @ 2015-02-08 14:02 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: Alasdair Kergon, Neil Brown, device-mapper development,
	linux-raid@vger.kernel.org, Julia Lawall, kernel-janitors, LKML

On Sun, Feb 8, 2015 at 4:55 AM, SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
>> Your proposed patch (while technically correct) hurts code clarity.
>
> How many source code readability and understanding challenges does each
> additional condition check cause?

Please don't make a mountain out of a mole hill in an attempt to
defend your robotic patch (I'm quite tired of some of these static
analyzer patch submissions).

FYI, I did stage your other patch for 3.20, see:
https://git.kernel.org/cgit/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=dm-for-3.20&id=d0ce7e911c97c7c6df1081dcedfefced82a0c6bf

> Can the affected place become also a bit more efficient?

Efficiency isn't a concern in this instance (it isn't a hot IO path).
And even if it were, a branch (with current code) is more efficient vs
a a jump + branch (your proposed patch) -- in the case that no active
table exists.  Now if it likely that old_map does exist then yes your
patch is always a very slight win.

But given the duality of the calling function (deals with loading a
new map and destroying the old map if it exists) I prefer to keep the
code as is.  Sorry.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] dm ioctl: Delete an unnecessary check before the function call "dm_table_destroy"
  2015-02-08 14:02                                         ` Mike Snitzer
@ 2015-02-08 15:52                                           ` SF Markus Elfring
  0 siblings, 0 replies; 7+ messages in thread
From: SF Markus Elfring @ 2015-02-08 15:52 UTC (permalink / raw)
  To: Mike Snitzer
  Cc: Alasdair Kergon, Neil Brown, device-mapper development,
	linux-raid@vger.kernel.org, Julia Lawall, kernel-janitors, LKML

> FYI, I did stage your other patch for 3.20, see:
> https://git.kernel.org/cgit/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=dm-for-3.20&id=d0ce7e911c97c7c6df1081dcedfefced82a0c6bf

Thanks for your acceptance of the suggested clean-up around
vfree() function calls at least.
Additional source code places can also be reconsidered at other times,
can't they?

Regards,
Markus

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-02-08 15:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <5307CAA2.8060406@users.sourceforge.net>
     [not found] ` <alpine.DEB.2.02.1402212321410.2043@localhost6.localdomain6>
     [not found]   ` <530A086E.8010901@users.sourceforge.net>
     [not found]     ` <alpine.DEB.2.02.1402231635510.1985@localhost6.localdomain6>
     [not found]       ` <530A72AA.3000601@users.sourceforge.net>
     [not found]         ` <alpine.DEB.2.02.1402240658210.2090@localhost6.localdomain6>
     [not found]           ` <530B5FB6.6010207@users.sourceforge.net>
     [not found]             ` <alpine.DEB.2.10.1402241710370.2074@hadrien>
     [not found]               ` <530C5E18.1020800@users.sourceforge.net>
     [not found]                 ` <alpine.DEB.2.10.1402251014170.2080@hadrien>
     [not found]                   ` <530CD2C4.4050903@users.sourceforge.net>
     [not found]                     ` <alpine.DEB.2.10.1402251840450.7035@hadrien>
     [not found]                       ` <530CF8FF.8080600@users.sourceforge.net>
     [not found]                         ` <alpine.DEB.2.02.1402252117150.2047@localhost6.localdomain6>
     [not found]                           ` <530DD06F.4090703@users.sourceforge.net>
     [not found]                             ` <alpine.DEB.2.02.1402262129250.2221@localhost6.localdomain6>
     [not found]                               ` <5317A59D.4@users.so urceforge.net>
     [not found]                                 ` <5317A59D.4@users.sourceforge.net>
2014-11-19 20:55                                   ` [PATCH 1/1] dm: Deletion of unnecessary checks before two function calls SF Markus Elfring
     [not found]                                 ` <54CF93BB.40206@users.sourceforge.net>
2015-02-02 15:17                                   ` [PATCH 1/3] dm snapshot: Deletion of unnecessary checks before the function call "vfree" SF Markus Elfring
2015-02-02 15:23                                   ` [PATCH 3/3] dm ioctl: Delete an unnecessary check before the function call "dm_table_destroy" SF Markus Elfring
2015-02-06 21:12                                     ` Mike Snitzer
2015-02-08  9:55                                       ` SF Markus Elfring
2015-02-08 14:02                                         ` Mike Snitzer
2015-02-08 15:52                                           ` SF Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox