kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] vfio: powerpc/spapr: Deletion of an unnecessary check
       [not found]                                 ` <5317A59D.4@users.sourceforge.net>
@ 2015-06-28 16:18                                   ` SF Markus Elfring
  2015-06-28 16:22                                     ` [PATCH 1/2] vfio: powerpc/spapr: Delete an unnecessary check before the function call "kfree" SF Markus Elfring
  2015-06-28 16:24                                     ` [PATCH 2/2] vfio: powerpc/spapr: One function call less in tce_iommu_attach_group() after kzalloc() failure SF Markus Elfring
  2015-11-15  9:45                                   ` [PATCH] KVM-async_pf: Delete an unnecessary check before the function call "kmem_cache_destroy" SF Markus Elfring
  1 sibling, 2 replies; 10+ messages in thread
From: SF Markus Elfring @ 2015-06-28 16:18 UTC (permalink / raw)
  To: Alex Williamson, kvm
  Cc: LKML, kernel-janitors, Alexey Kardashevskiy, Julia Lawall,
	Michael Ellerman

From: Markus Elfring <elfring@users.sourceforge.net>

Another update suggestion was taken into account after a patch was applied
from static source code analysis.

Markus Elfring (2):
  Delete an unnecessary check before the function call "kfree"
  One function call less in tce_iommu_attach_group() after kzalloc() failure

 drivers/vfio/vfio_iommu_spapr_tce.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

-- 
2.4.4


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

* [PATCH 1/2] vfio: powerpc/spapr: Delete an unnecessary check before the function call "kfree"
  2015-06-28 16:18                                   ` [PATCH 0/2] vfio: powerpc/spapr: Deletion of an unnecessary check SF Markus Elfring
@ 2015-06-28 16:22                                     ` SF Markus Elfring
  2015-06-28 16:24                                     ` [PATCH 2/2] vfio: powerpc/spapr: One function call less in tce_iommu_attach_group() after kzalloc() failure SF Markus Elfring
  1 sibling, 0 replies; 10+ messages in thread
From: SF Markus Elfring @ 2015-06-28 16:22 UTC (permalink / raw)
  To: Alex Williamson, kvm
  Cc: LKML, kernel-janitors, Alexey Kardashevskiy, Julia Lawall,
	Michael Ellerman

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 28 Jun 2015 17:43:48 +0200

The kfree() 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/vfio/vfio_iommu_spapr_tce.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c b/drivers/vfio/vfio_iommu_spapr_tce.c
index 0582b72..50ddfac 100644
--- a/drivers/vfio/vfio_iommu_spapr_tce.c
+++ b/drivers/vfio/vfio_iommu_spapr_tce.c
@@ -1215,7 +1215,7 @@ static int tce_iommu_attach_group(void *iommu_data,
 	}
 
 unlock_exit:
-	if (ret && tcegrp)
+	if (ret)
 		kfree(tcegrp);
 
 	mutex_unlock(&container->lock);
-- 
2.4.4

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

* [PATCH 2/2] vfio: powerpc/spapr: One function call less in tce_iommu_attach_group() after kzalloc() failure
  2015-06-28 16:18                                   ` [PATCH 0/2] vfio: powerpc/spapr: Deletion of an unnecessary check SF Markus Elfring
  2015-06-28 16:22                                     ` [PATCH 1/2] vfio: powerpc/spapr: Delete an unnecessary check before the function call "kfree" SF Markus Elfring
@ 2015-06-28 16:24                                     ` SF Markus Elfring
  2015-06-28 23:41                                       ` Alexey Kardashevskiy
  1 sibling, 1 reply; 10+ messages in thread
From: SF Markus Elfring @ 2015-06-28 16:24 UTC (permalink / raw)
  To: Alex Williamson, kvm
  Cc: LKML, kernel-janitors, Alexey Kardashevskiy, Julia Lawall,
	Michael Ellerman

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 28 Jun 2015 17:58:42 +0200

The kfree() function was called even if a previous memory allocation
try failed.

This implementation detail could be improved by the introduction
of another jump label.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/vfio/vfio_iommu_spapr_tce.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c b/drivers/vfio/vfio_iommu_spapr_tce.c
index 50ddfac..2523075 100644
--- a/drivers/vfio/vfio_iommu_spapr_tce.c
+++ b/drivers/vfio/vfio_iommu_spapr_tce.c
@@ -1200,7 +1200,7 @@ static int tce_iommu_attach_group(void *iommu_data,
 	tcegrp = kzalloc(sizeof(*tcegrp), GFP_KERNEL);
 	if (!tcegrp) {
 		ret = -ENOMEM;
-		goto unlock_exit;
+		goto unlock_container;
 	}
 
 	if (!table_group->ops || !table_group->ops->take_ownership ||
@@ -1217,7 +1217,7 @@ static int tce_iommu_attach_group(void *iommu_data,
 unlock_exit:
 	if (ret)
 		kfree(tcegrp);
-
+unlock_container:
 	mutex_unlock(&container->lock);
 
 	return ret;
-- 
2.4.4

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

* Re: [PATCH 2/2] vfio: powerpc/spapr: One function call less in tce_iommu_attach_group() after kzalloc() failure
  2015-06-28 16:24                                     ` [PATCH 2/2] vfio: powerpc/spapr: One function call less in tce_iommu_attach_group() after kzalloc() failure SF Markus Elfring
@ 2015-06-28 23:41                                       ` Alexey Kardashevskiy
  2015-06-29  6:02                                         ` SF Markus Elfring
  0 siblings, 1 reply; 10+ messages in thread
From: Alexey Kardashevskiy @ 2015-06-28 23:41 UTC (permalink / raw)
  To: SF Markus Elfring, Alex Williamson, kvm
  Cc: LKML, kernel-janitors, Julia Lawall, Michael Ellerman

On 06/29/2015 02:24 AM, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sun, 28 Jun 2015 17:58:42 +0200
>
> The kfree() function was called even if a previous memory allocation
> try failed.

tcegrp will be NULL and kfree() can handle this just fine (is not it the 
whole point of this patchset - remove the check and just call kfree() even 
if the pointer is NULL?). And if you wanted another label, than the 
existing one should have been renamed to "free_exit" or "free_unlock_exit" 
and new one would be "unlock_exit".



> This implementation detail could be improved by the introduction
> of another jump label.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>   drivers/vfio/vfio_iommu_spapr_tce.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c b/drivers/vfio/vfio_iommu_spapr_tce.c
> index 50ddfac..2523075 100644
> --- a/drivers/vfio/vfio_iommu_spapr_tce.c
> +++ b/drivers/vfio/vfio_iommu_spapr_tce.c
> @@ -1200,7 +1200,7 @@ static int tce_iommu_attach_group(void *iommu_data,
>   	tcegrp = kzalloc(sizeof(*tcegrp), GFP_KERNEL);
>   	if (!tcegrp) {
>   		ret = -ENOMEM;
> -		goto unlock_exit;
> +		goto unlock_container;
>   	}
>
>   	if (!table_group->ops || !table_group->ops->take_ownership ||
> @@ -1217,7 +1217,7 @@ static int tce_iommu_attach_group(void *iommu_data,
>   unlock_exit:
>   	if (ret)
>   		kfree(tcegrp);
> -
> +unlock_container:
>   	mutex_unlock(&container->lock);
>
>   	return ret;
>


-- 
Alexey

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

* Re: vfio: powerpc/spapr: One function call less in tce_iommu_attach_group() after kzalloc() failure
  2015-06-28 23:41                                       ` Alexey Kardashevskiy
@ 2015-06-29  6:02                                         ` SF Markus Elfring
  2015-06-30  0:31                                           ` Alexey Kardashevskiy
  0 siblings, 1 reply; 10+ messages in thread
From: SF Markus Elfring @ 2015-06-29  6:02 UTC (permalink / raw)
  To: Alexey Kardashevskiy, Alex Williamson, kvm
  Cc: LKML, kernel-janitors, Julia Lawall, Michael Ellerman

> tcegrp will be NULL and kfree() can handle this just fine

The affected function did not show this API knowledge, did it?


> (is not it the whole point of this patchset
> - remove the check and just call kfree() even if the pointer is NULL?).

Partly, yes.


> And if you wanted another label,

I suggest this to improve corresponding exception handling.


> than the existing one should have been renamed to "free_exit" or "free_unlock_exit"
> and new one would be "unlock_exit".

I chose a smaller change at this place.

I am not familiar enough with other called functions there at the moment.
Are the remaining goto statements also update candidates?

Regards,
Markus

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

* Re: vfio: powerpc/spapr: One function call less in tce_iommu_attach_group() after kzalloc() failure
  2015-06-29  6:02                                         ` SF Markus Elfring
@ 2015-06-30  0:31                                           ` Alexey Kardashevskiy
  2015-06-30  6:08                                             ` SF Markus Elfring
  0 siblings, 1 reply; 10+ messages in thread
From: Alexey Kardashevskiy @ 2015-06-30  0:31 UTC (permalink / raw)
  To: SF Markus Elfring, Alex Williamson, kvm
  Cc: LKML, kernel-janitors, Julia Lawall, Michael Ellerman

On 06/29/2015 04:02 PM, SF Markus Elfring wrote:
>> tcegrp will be NULL and kfree() can handle this just fine
>
> The affected function did not show this API knowledge, did it?


but you fixed this in 1/2 :)

>
>
>> (is not it the whole point of this patchset
>> - remove the check and just call kfree() even if the pointer is NULL?).
>
> Partly, yes.
>
>
>> And if you wanted another label,
>
> I suggest this to improve corresponding exception handling.
>
>
>> than the existing one should have been renamed to "free_exit" or "free_unlock_exit"
>> and new one would be "unlock_exit".
>
> I chose a smaller change at this place.


I'd just drop this patch.


> I am not familiar enough with other called functions there at the moment.
> Are the remaining goto statements also update candidates?




-- 
Alexey

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

* Re: vfio: powerpc/spapr: One function call less in tce_iommu_attach_group() after kzalloc() failure
  2015-06-30  0:31                                           ` Alexey Kardashevskiy
@ 2015-06-30  6:08                                             ` SF Markus Elfring
  2015-06-30 10:36                                               ` Alexey Kardashevskiy
  0 siblings, 1 reply; 10+ messages in thread
From: SF Markus Elfring @ 2015-06-30  6:08 UTC (permalink / raw)
  To: Alexey Kardashevskiy, Alex Williamson, kvm
  Cc: LKML, kernel-janitors, Julia Lawall, Michael Ellerman

>>> than the existing one should have been renamed to "free_exit" or "free_unlock_exit"
>>> and new one would be "unlock_exit".
>>
>> I chose a smaller change at this place.
> 
> I'd just drop this patch.

How do you think about to improve the affected jump labels
a bit more there?

Regards,
Markus

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

* Re: vfio: powerpc/spapr: One function call less in tce_iommu_attach_group() after kzalloc() failure
  2015-06-30  6:08                                             ` SF Markus Elfring
@ 2015-06-30 10:36                                               ` Alexey Kardashevskiy
  0 siblings, 0 replies; 10+ messages in thread
From: Alexey Kardashevskiy @ 2015-06-30 10:36 UTC (permalink / raw)
  To: SF Markus Elfring, Alex Williamson, kvm
  Cc: LKML, kernel-janitors, Julia Lawall, Michael Ellerman

On 06/30/2015 04:08 PM, SF Markus Elfring wrote:
>>>> than the existing one should have been renamed to "free_exit" or "free_unlock_exit"
>>>> and new one would be "unlock_exit".
>>>
>>> I chose a smaller change at this place.
>>
>> I'd just drop this patch.
>
> How do you think about to improve the affected jump labels
> a bit more there?

This branch is very unlikely to work ever so I cannot think of any 
improvement here.



-- 
Alexey

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

* [PATCH] KVM-async_pf: Delete an unnecessary check before the function call "kmem_cache_destroy"
       [not found]                                 ` <5317A59D.4@users.sourceforge.net>
  2015-06-28 16:18                                   ` [PATCH 0/2] vfio: powerpc/spapr: Deletion of an unnecessary check SF Markus Elfring
@ 2015-11-15  9:45                                   ` SF Markus Elfring
  2015-11-18 11:04                                     ` Paolo Bonzini
  1 sibling, 1 reply; 10+ messages in thread
From: SF Markus Elfring @ 2015-11-15  9:45 UTC (permalink / raw)
  To: Gleb Natapov, Paolo Bonzini; +Cc: kvm, LKML, kernel-janitors, Julia Lawall

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 15 Nov 2015 10:40:36 +0100

The kmem_cache_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>
---
 virt/kvm/async_pf.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/virt/kvm/async_pf.c b/virt/kvm/async_pf.c
index 77d42be..3531599 100644
--- a/virt/kvm/async_pf.c
+++ b/virt/kvm/async_pf.c
@@ -57,8 +57,7 @@ int kvm_async_pf_init(void)
 
 void kvm_async_pf_deinit(void)
 {
-	if (async_pf_cache)
-		kmem_cache_destroy(async_pf_cache);
+	kmem_cache_destroy(async_pf_cache);
 	async_pf_cache = NULL;
 }
 
-- 
2.6.2


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

* Re: [PATCH] KVM-async_pf: Delete an unnecessary check before the function call "kmem_cache_destroy"
  2015-11-15  9:45                                   ` [PATCH] KVM-async_pf: Delete an unnecessary check before the function call "kmem_cache_destroy" SF Markus Elfring
@ 2015-11-18 11:04                                     ` Paolo Bonzini
  0 siblings, 0 replies; 10+ messages in thread
From: Paolo Bonzini @ 2015-11-18 11:04 UTC (permalink / raw)
  To: SF Markus Elfring, Gleb Natapov; +Cc: kvm, LKML, kernel-janitors, Julia Lawall



On 15/11/2015 10:45, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sun, 15 Nov 2015 10:40:36 +0100
> 
> The kmem_cache_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>
> ---
>  virt/kvm/async_pf.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/virt/kvm/async_pf.c b/virt/kvm/async_pf.c
> index 77d42be..3531599 100644
> --- a/virt/kvm/async_pf.c
> +++ b/virt/kvm/async_pf.c
> @@ -57,8 +57,7 @@ int kvm_async_pf_init(void)
>  
>  void kvm_async_pf_deinit(void)
>  {
> -	if (async_pf_cache)
> -		kmem_cache_destroy(async_pf_cache);
> +	kmem_cache_destroy(async_pf_cache);
>  	async_pf_cache = NULL;
>  }
>  
> 

Applied to kvm/queue, thanks.

Paolo

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

end of thread, other threads:[~2015-11-18 11:04 UTC | newest]

Thread overview: 10+ 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>
2015-06-28 16:18                                   ` [PATCH 0/2] vfio: powerpc/spapr: Deletion of an unnecessary check SF Markus Elfring
2015-06-28 16:22                                     ` [PATCH 1/2] vfio: powerpc/spapr: Delete an unnecessary check before the function call "kfree" SF Markus Elfring
2015-06-28 16:24                                     ` [PATCH 2/2] vfio: powerpc/spapr: One function call less in tce_iommu_attach_group() after kzalloc() failure SF Markus Elfring
2015-06-28 23:41                                       ` Alexey Kardashevskiy
2015-06-29  6:02                                         ` SF Markus Elfring
2015-06-30  0:31                                           ` Alexey Kardashevskiy
2015-06-30  6:08                                             ` SF Markus Elfring
2015-06-30 10:36                                               ` Alexey Kardashevskiy
2015-11-15  9:45                                   ` [PATCH] KVM-async_pf: Delete an unnecessary check before the function call "kmem_cache_destroy" SF Markus Elfring
2015-11-18 11:04                                     ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).