linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/swap_slots.c: Remove unnecessary NULL pointer check
@ 2021-01-09  8:09 Miaohe Lin
  2021-01-09 17:40 ` Matthew Wilcox
  0 siblings, 1 reply; 3+ messages in thread
From: Miaohe Lin @ 2021-01-09  8:09 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel, linmiaohe

The cache->slots and cache->slots_ret is already checked before we try to
drain it. And kvfree can handle the NULL pointer itself. So remove the
NULL pointer check here.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 mm/swap_slots.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/mm/swap_slots.c b/mm/swap_slots.c
index 0357fbe70645..4cf99ce033d0 100644
--- a/mm/swap_slots.c
+++ b/mm/swap_slots.c
@@ -178,7 +178,7 @@ static void drain_slots_cache_cpu(unsigned int cpu, unsigned int type,
 		swapcache_free_entries(cache->slots + cache->cur, cache->nr);
 		cache->cur = 0;
 		cache->nr = 0;
-		if (free_slots && cache->slots) {
+		if (free_slots) {
 			kvfree(cache->slots);
 			cache->slots = NULL;
 		}
@@ -188,13 +188,12 @@ static void drain_slots_cache_cpu(unsigned int cpu, unsigned int type,
 		spin_lock_irq(&cache->free_lock);
 		swapcache_free_entries(cache->slots_ret, cache->n_ret);
 		cache->n_ret = 0;
-		if (free_slots && cache->slots_ret) {
+		if (free_slots) {
 			slots = cache->slots_ret;
 			cache->slots_ret = NULL;
 		}
 		spin_unlock_irq(&cache->free_lock);
-		if (slots)
-			kvfree(slots);
+		kvfree(slots);
 	}
 }
 
-- 
2.19.1



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

* Re: [PATCH] mm/swap_slots.c: Remove unnecessary NULL pointer check
  2021-01-09  8:09 [PATCH] mm/swap_slots.c: Remove unnecessary NULL pointer check Miaohe Lin
@ 2021-01-09 17:40 ` Matthew Wilcox
  2021-01-14  2:34   ` Miaohe Lin
  0 siblings, 1 reply; 3+ messages in thread
From: Matthew Wilcox @ 2021-01-09 17:40 UTC (permalink / raw)
  To: Miaohe Lin; +Cc: akpm, linux-mm, linux-kernel

On Sat, Jan 09, 2021 at 03:09:43AM -0500, Miaohe Lin wrote:
> The cache->slots and cache->slots_ret is already checked before we try to
> drain it. And kvfree can handle the NULL pointer itself. So remove the
> NULL pointer check here.

> @@ -178,7 +178,7 @@ static void drain_slots_cache_cpu(unsigned int cpu, unsigned int type,
>  		swapcache_free_entries(cache->slots + cache->cur, cache->nr);
>  		cache->cur = 0;
>  		cache->nr = 0;
> -		if (free_slots && cache->slots) {
> +		if (free_slots) {

Prove that swapcache_free_entries() doesn't change cache->slots.

> @@ -188,13 +188,12 @@ static void drain_slots_cache_cpu(unsigned int cpu, unsigned int type,
>  		spin_lock_irq(&cache->free_lock);
>  		swapcache_free_entries(cache->slots_ret, cache->n_ret);
>  		cache->n_ret = 0;
> -		if (free_slots && cache->slots_ret) {
> +		if (free_slots) {

... or ->slots_ret

> -		if (slots)
> -			kvfree(slots);
> +		kvfree(slots);

This is fine.


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

* Re: [PATCH] mm/swap_slots.c: Remove unnecessary NULL pointer check
  2021-01-09 17:40 ` Matthew Wilcox
@ 2021-01-14  2:34   ` Miaohe Lin
  0 siblings, 0 replies; 3+ messages in thread
From: Miaohe Lin @ 2021-01-14  2:34 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: akpm, linux-mm, linux-kernel

Hi:
On 2021/1/10 1:40, Matthew Wilcox wrote:
> On Sat, Jan 09, 2021 at 03:09:43AM -0500, Miaohe Lin wrote:
>> The cache->slots and cache->slots_ret is already checked before we try to
>> drain it. And kvfree can handle the NULL pointer itself. So remove the
>> NULL pointer check here.
> 
>> @@ -178,7 +178,7 @@ static void drain_slots_cache_cpu(unsigned int cpu, unsigned int type,
>>  		swapcache_free_entries(cache->slots + cache->cur, cache->nr);
>>  		cache->cur = 0;
>>  		cache->nr = 0;
>> -		if (free_slots && cache->slots) {
>> +		if (free_slots) {
> 
> Prove that swapcache_free_entries() doesn't change cache->slots.
> 

Yeh... I see. I thought swap_slots_cache_mutex could totally guard against this.

>> @@ -188,13 +188,12 @@ static void drain_slots_cache_cpu(unsigned int cpu, unsigned int type,
>>  		spin_lock_irq(&cache->free_lock);
>>  		swapcache_free_entries(cache->slots_ret, cache->n_ret);
>>  		cache->n_ret = 0;
>> -		if (free_slots && cache->slots_ret) {
>> +		if (free_slots) {
> 
> ... or ->slots_ret
> 
>> -		if (slots)
>> -			kvfree(slots);
>> +		kvfree(slots);
> 
> This is fine.
> .
> 

Many thanks for your review and reply!


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

end of thread, other threads:[~2021-01-14  2:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-09  8:09 [PATCH] mm/swap_slots.c: Remove unnecessary NULL pointer check Miaohe Lin
2021-01-09 17:40 ` Matthew Wilcox
2021-01-14  2:34   ` Miaohe Lin

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).