RE: [PATCH] mm: mmap: Simplify the failure return working flow

2015-08-23 Thread Chen Gang

> From: xili_gchen_5...@hotmail.com
> To: mho...@kernel.org
> CC: a...@linux-foundation.org; linux-kernel@vger.kernel.org; 
> kirill.shute...@linux.intel.com; r...@redhat.com; sasha.le...@oracle.com; 
> linux...@kvack.org
> Subject: Re: [PATCH] mm: mmap: Simplify the failure return working flow
> Date: Thu, 20 Aug 2015 16:48:21 +0800
>
> On 2015年08月20日 15:45, Michal Hocko wrote:
>> On Thu 20-08-15 09:27:42, gchen gchen wrote:
>> [...]
>>> Yes, it is really peculiar, the reason is gmail is not stable in China.
>>> I have to send mail in my hotmail address.
>>>
>>> But I still want to use my gmail as Signed-off-by, since I have already
>>> used it, and also its name is a little formal than my hotmail.
>>>
>>> Welcome any ideas, suggestions and completions for it (e.g. if it is
>>> necessary to let send mail and Signed-off-by mail be the same, I shall
>>> try).
>>
>> You can do the following in your .git/config
>>
>> [user]
>> name = YOUR_NAME_FOR_S-O-B
>> email = YOUR_GMAIL_ADDRESS
>> [sendemail]
>> from = YOUR_STABLE_SENDER_ADDRESS
>> envelopesender = YOUR_STABLE_SENDER_ADDRESS
>> smtpserver = YOUR_STABLE_SMTP
>>
>> [user] part will be used for s-o-b and Author email while the sendemail
>> will be used for git send-email to route the patch properly. If the two
>> differ it will add From: user.name  as suggested by Andrew.
>>
>

Oh, sorry, it seems, I have to send mail in hotmail website (I can send gmail
neither under client nor under website).

linux kernel mailing list does not accept QQ mail. Either at present, I can
not send hotmail from client (thunderbird client, git client), I guess the
reason is the hotmail is blocked in China (but QQ is of cause OK in China).

So ... it is a bad news to us all. :-(  Welcome any related ideas, suggestions
an completions.

Thanks.

> OK, thank your very much for your details information. :-)
>
> I shall try to use git to send/recv mails instead of current thunderbird
> client (hope I can do it next time, although I am not quite sure).
>
>
> Thanks.
> --
> Chen Gang
>
> Open, share, and attitude like air, water, and life which God blessed
>
  

RE: [PATCH] mm: mmap: Simplify the failure return working flow

2015-08-23 Thread Chen Gang

 From: xili_gchen_5...@hotmail.com
 To: mho...@kernel.org
 CC: a...@linux-foundation.org; linux-kernel@vger.kernel.org; 
 kirill.shute...@linux.intel.com; r...@redhat.com; sasha.le...@oracle.com; 
 linux...@kvack.org
 Subject: Re: [PATCH] mm: mmap: Simplify the failure return working flow
 Date: Thu, 20 Aug 2015 16:48:21 +0800

 On 2015年08月20日 15:45, Michal Hocko wrote:
 On Thu 20-08-15 09:27:42, gchen gchen wrote:
 [...]
 Yes, it is really peculiar, the reason is gmail is not stable in China.
 I have to send mail in my hotmail address.

 But I still want to use my gmail as Signed-off-by, since I have already
 used it, and also its name is a little formal than my hotmail.

 Welcome any ideas, suggestions and completions for it (e.g. if it is
 necessary to let send mail and Signed-off-by mail be the same, I shall
 try).

 You can do the following in your .git/config

 [user]
 name = YOUR_NAME_FOR_S-O-B
 email = YOUR_GMAIL_ADDRESS
 [sendemail]
 from = YOUR_STABLE_SENDER_ADDRESS
 envelopesender = YOUR_STABLE_SENDER_ADDRESS
 smtpserver = YOUR_STABLE_SMTP

 [user] part will be used for s-o-b and Author email while the sendemail
 will be used for git send-email to route the patch properly. If the two
 differ it will add From: user.name user.email as suggested by Andrew.



Oh, sorry, it seems, I have to send mail in hotmail website (I can send gmail
neither under client nor under website).

linux kernel mailing list does not accept QQ mail. Either at present, I can
not send hotmail from client (thunderbird client, git client), I guess the
reason is the hotmail is blocked in China (but QQ is of cause OK in China).

So ... it is a bad news to us all. :-(  Welcome any related ideas, suggestions
an completions.

Thanks.

 OK, thank your very much for your details information. :-)

 I shall try to use git to send/recv mails instead of current thunderbird
 client (hope I can do it next time, although I am not quite sure).


 Thanks.
 --
 Chen Gang

 Open, share, and attitude like air, water, and life which God blessed

  

Re: [PATCH] mm: mmap: Simplify the failure return working flow

2015-08-20 Thread gchen gchen
On 2015年08月20日 15:45, Michal Hocko wrote:
> On Thu 20-08-15 09:27:42, gchen gchen wrote:
> [...]
>> Yes, it is really peculiar, the reason is gmail is not stable in China.
>> I have to send mail in my hotmail address.
>>
>> But I still want to use my gmail as Signed-off-by, since I have already
>> used it, and also its name is a little formal than my hotmail.
>>
>> Welcome any ideas, suggestions and completions for it (e.g. if it is
>> necessary to let send mail and Signed-off-by mail be the same, I shall
>> try).
>
> You can do the following in your .git/config
>
> [user]
>   name = YOUR_NAME_FOR_S-O-B
>   email = YOUR_GMAIL_ADDRESS
> [sendemail]
>   from = YOUR_STABLE_SENDER_ADDRESS
>   envelopesender = YOUR_STABLE_SENDER_ADDRESS
>   smtpserver = YOUR_STABLE_SMTP
>
> [user] part will be used for s-o-b and Author email while the sendemail
> will be used for git send-email to route the patch properly. If the two
> differ it will add From: user.name  as suggested by Andrew.
>

OK, thank your very much for your details information. :-)

I shall try to use git to send/recv mails instead of current thunderbird
client (hope I can do it next time, although I am not quite sure).


Thanks.
--
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
  
N�Р骒r��yb�X�肚�v�^�)藓{.n�+�伐�{��赙zXФ�≤�}��财�z�:+v�����赙zZ+��+zf"�h���~i���z��wア�?�ㄨ��&�)撷f��^j谦y�m��@A�a囤�
0鹅h���i

Re: [PATCH] mm: mmap: Simplify the failure return working flow

2015-08-20 Thread Michal Hocko
On Thu 20-08-15 09:27:42, gchen gchen wrote:
[...]
> Yes, it is really peculiar, the reason is gmail is not stable in China.
> I have to send mail in my hotmail address.
> 
> But I still want to use my gmail as Signed-off-by, since I have already
> used it, and also its name is a little formal than my hotmail.
> 
> Welcome any ideas, suggestions and completions for it (e.g. if it is
> necessary to let send mail and Signed-off-by mail be the same, I shall
> try).

You can do the following in your .git/config

[user]
name = YOUR_NAME_FOR_S-O-B
email = YOUR_GMAIL_ADDRESS
[sendemail]
from = YOUR_STABLE_SENDER_ADDRESS
envelopesender = YOUR_STABLE_SENDER_ADDRESS
smtpserver = YOUR_STABLE_SMTP

[user] part will be used for s-o-b and Author email while the sendemail
will be used for git send-email to route the patch properly. If the two
differ it will add From: user.name  as suggested by Andrew.
-- 
Michal Hocko
SUSE Labs
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] mm: mmap: Simplify the failure return working flow

2015-08-20 Thread gchen gchen
On 2015年08月20日 15:45, Michal Hocko wrote:
 On Thu 20-08-15 09:27:42, gchen gchen wrote:
 [...]
 Yes, it is really peculiar, the reason is gmail is not stable in China.
 I have to send mail in my hotmail address.

 But I still want to use my gmail as Signed-off-by, since I have already
 used it, and also its name is a little formal than my hotmail.

 Welcome any ideas, suggestions and completions for it (e.g. if it is
 necessary to let send mail and Signed-off-by mail be the same, I shall
 try).

 You can do the following in your .git/config

 [user]
   name = YOUR_NAME_FOR_S-O-B
   email = YOUR_GMAIL_ADDRESS
 [sendemail]
   from = YOUR_STABLE_SENDER_ADDRESS
   envelopesender = YOUR_STABLE_SENDER_ADDRESS
   smtpserver = YOUR_STABLE_SMTP

 [user] part will be used for s-o-b and Author email while the sendemail
 will be used for git send-email to route the patch properly. If the two
 differ it will add From: user.name user.email as suggested by Andrew.


OK, thank your very much for your details information. :-)

I shall try to use git to send/recv mails instead of current thunderbird
client (hope I can do it next time, although I am not quite sure).


Thanks.
--
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
  
N�Р骒r��yb�X�肚�v�^�)藓{.n�+�伐�{��赙zXФ�≤�}��财�z�j:+v�����赙zZ+��+zf"�h���~i���z��wア�?�ㄨ���)撷f��^j谦y�m��@A�a囤�
0鹅h���i

Re: [PATCH] mm: mmap: Simplify the failure return working flow

2015-08-20 Thread Michal Hocko
On Thu 20-08-15 09:27:42, gchen gchen wrote:
[...]
 Yes, it is really peculiar, the reason is gmail is not stable in China.
 I have to send mail in my hotmail address.
 
 But I still want to use my gmail as Signed-off-by, since I have already
 used it, and also its name is a little formal than my hotmail.
 
 Welcome any ideas, suggestions and completions for it (e.g. if it is
 necessary to let send mail and Signed-off-by mail be the same, I shall
 try).

You can do the following in your .git/config

[user]
name = YOUR_NAME_FOR_S-O-B
email = YOUR_GMAIL_ADDRESS
[sendemail]
from = YOUR_STABLE_SENDER_ADDRESS
envelopesender = YOUR_STABLE_SENDER_ADDRESS
smtpserver = YOUR_STABLE_SMTP

[user] part will be used for s-o-b and Author email while the sendemail
will be used for git send-email to route the patch properly. If the two
differ it will add From: user.name user.email as suggested by Andrew.
-- 
Michal Hocko
SUSE Labs
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] mm: mmap: Simplify the failure return working flow

2015-08-19 Thread gchen gchen
On Tue, 18 Aug 2015 15:57:08 -0700 a...@linux-foundation.org 
wrote: On Wed, 19 Aug 2015 06:27:58 +0800 Chen Gang 
xili_gchen_5...@hotmail.com wrote: From: Chen Gang 
xili_gchen_5...@hotmail.com As sent, this patch is 
From:you@hotmail and Signed-off-by:you@gmail. This is peculiar. 
 I'm assuming that it should have been From:you@gmail and I have made 
that change to my copy of the patch. You can do this yourself 
by putting an explicit From: line at the start of the 
changelog.Yes, it is really peculiar, the reason is gmail is 
not stable in China.I have to send mail in my hotmail address.But I 
still want to use my gmail as Signed-off-by, since I have alreadyused it, 
and also its name is a little formal than my hotmail.Welcome any ideas, 
suggestions and completions for it (e.g. if it isnecessary to let send mail 
and Signed-off-by mail be the same, I shalltry).[...] 
So, --- 
a/mm/mmap.c~mm-mmap-simplify-the-failure-return-working-flow-fix +++ 
a/mm/mmap.c @@ -2952,7 +2952,7 @@ struct vm_area_struct 
*copy_vma(struct v } else { new_vma = 
kmem_cache_alloc(vm_area_cachep, GFP_KERNEL); if 
(!new_vma) -   return NULL; +   
goto out; *new_vma = *vma;  
   new_vma-vm_start = addr; new_vma-vm_end = 
addr + len; @@ -2971,10 +2971,11 @@ struct vm_area_struct 
*copy_vma(struct v } return 
new_vma; - out_free_mempol: +out_free_mempol:   
  mpol_put(vma_policy(new_vma)); - out_free_vma: 
+out_free_vma: kmem_cache_free(vm_area_cachep, 
new_vma); +out: return NULL;  
}It is OK to me, thanks.During these days (2-4 months), 
I shall try to make some patches forLinux mm: - I am learning Linux 
kernel mmu, so I can re-use part of code to user   mode (add softmmu to 
qemu linux user in my working time). Then I can   try some mm patches when 
I am reading related code. - At present, cross-building various archs 
with allmodconfig looks OK   (have no many issues), so for me, I can stop 
and start another parts   (e.g. mmu, loongson machine of mips arch, 
...).Welcome any ideas, suggestions and completions for it: - 
Assume I am not quite familiar with mmu -- in honest, I feel I am   really 
not. - Is it possible to build the related 'softmmu' as a module which 
can   be used by both kernel mode and user mode (if really it is, I 
shall   try to perform it -- I can do it in my working time). - 
...Thanks.--Chen GangOpen, share, and attitude like 
air, water, and life which God blessed  


Re: [PATCH] mm: mmap: Simplify the failure return working flow

2015-08-19 Thread gchen gchen

On Tue, 18 Aug 2015 15:57:08 -0700 a...@linux-foundation.org wrote:
>
> On Wed, 19 Aug 2015 06:27:58 +0800 Chen Gang
>  wrote:
>
>> From: Chen Gang 
>
> As sent, this patch is From:you@hotmail and Signed-off-by:you@gmail.
>
> This is peculiar.  I'm assuming that it should have been From:you@gmail and
> I have made that change to my copy of the patch.
>
> You can do this yourself by putting an explicit From: line at the start
> of the changelog.
>

Yes, it is really peculiar, the reason is gmail is not stable in China.
I have to send mail in my hotmail address.

But I still want to use my gmail as Signed-off-by, since I have already
used it, and also its name is a little formal than my hotmail.

Welcome any ideas, suggestions and completions for it (e.g. if it is
necessary to let send mail and Signed-off-by mail be the same, I shall
try).

[...]

> So,
>
> --- a/mm/mmap.c~mm-mmap-simplify-the-failure-return-working-flow-fix
> +++ a/mm/mmap.c
> @@ -2952,7 +2952,7 @@ struct vm_area_struct *copy_vma(struct v
> } else {
> new_vma = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
> if (!new_vma)
> -   return NULL;
> +   goto out;
> *new_vma = *vma;
> new_vma->vm_start = addr;
> new_vma->vm_end = addr + len;
> @@ -2971,10 +2971,11 @@ struct vm_area_struct *copy_vma(struct v
> }
> return new_vma;
>
> - out_free_mempol:
> +out_free_mempol:
> mpol_put(vma_policy(new_vma));
> - out_free_vma:
> +out_free_vma:
> kmem_cache_free(vm_area_cachep, new_vma);
> +out:
> return NULL;
>  }
>

It is OK to me, thanks.

During these days (2-4 months), I shall try to make some patches for
Linux mm:

 - I am learning Linux kernel mmu, so I can re-use part of code to user
   mode (add softmmu to qemu linux user in my working time). Then I can
   try some mm patches when I am reading related code.

 - At present, cross-building various archs with allmodconfig looks OK
   (have no many issues), so for me, I can stop and start another parts
   (e.g. mmu, loongson machine of mips arch, ...).

Welcome any ideas, suggestions and completions for it:

 - Assume I am not quite familiar with mmu -- in honest, I feel I am
   really not.

 - Is it possible to build the related 'softmmu' as a module which can
   be used by both kernel mode and user mode (if really it is, I shall
   try to perform it -- I can do it in my working time).

 - ...

Thanks.
--
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
  

Re: [PATCH] mm: mmap: Simplify the failure return working flow

2015-08-19 Thread gchen gchen
brOn Tue, 18 Aug 2015 15:57:08 -0700 a...@linux-foundation.org 
wrote:brgt;brgt; On Wed, 19 Aug 2015 06:27:58 +0800 Chen Gangbrgt; 
lt;xili_gchen_5...@hotmail.comgt; wrote:brgt;brgt;gt; From: Chen Gang 
lt;xili_gchen_5...@hotmail.comgt;brgt;brgt; As sent, this patch is 
From:you@hotmail and Signed-off-by:you@gmail.brgt;brgt; This is peculiar. 
 I'm assuming that it should have been From:you@gmail andbrgt; I have made 
that change to my copy of the patch.brgt;brgt; You can do this yourself 
by putting an explicit From: line at the startbrgt; of the 
changelog.brgt;brbrYes, it is really peculiar, the reason is gmail is 
not stable in China.brI have to send mail in my hotmail address.brbrBut I 
still want to use my gmail as Signed-off-by, since I have alreadybrused it, 
and also its name is a little formal than my hotmail.brbrWelcome any ideas, 
suggestions and completions for it (e.g. if it isbrnecessary to let send mail 
and Signed-off-by mail be the same, I shallbrtry).brbr[...]brbrgt; 
So,brgt;brgt; --- 
a/mm/mmap.c~mm-mmap-simplify-the-failure-return-working-flow-fixbrgt; +++ 
a/mm/mmap.cbrgt; @@ -2952,7 +2952,7 @@ struct vm_area_struct 
*copy_vma(struct vbrgt; } else {brgt; new_vma = 
kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);brgt; if 
(!new_vma)brgt; -   return NULL;brgt; +   
goto out;brgt; *new_vma = *vma;brgt;  
   new_vma-gt;vm_start = addr;brgt; new_vma-gt;vm_end = 
addr + len;brgt; @@ -2971,10 +2971,11 @@ struct vm_area_struct 
*copy_vma(struct vbrgt; }brgt; return 
new_vma;brgt;brgt; - out_free_mempol:brgt; +out_free_mempol:brgt;   
  mpol_put(vma_policy(new_vma));brgt; - out_free_vma:brgt; 
+out_free_vma:brgt; kmem_cache_free(vm_area_cachep, 
new_vma);brgt; +out:brgt; return NULL;brgt;  
}brgt;brbrIt is OK to me, thanks.brbrDuring these days (2-4 months), 
I shall try to make some patches forbrLinux mm:brbr - I am learning Linux 
kernel mmu, so I can re-use part of code to userbr   mode (add softmmu to 
qemu linux user in my working time). Then I canbr   try some mm patches when 
I am reading related code.brbr - At present, cross-building various archs 
with allmodconfig looks OKbr   (have no many issues), so for me, I can stop 
and start another partsbr   (e.g. mmu, loongson machine of mips arch, 
...).brbrWelcome any ideas, suggestions and completions for it:brbr - 
Assume I am not quite familiar with mmu -- in honest, I feel I ambr   really 
not.brbr - Is it possible to build the related 'softmmu' as a module which 
canbr   be used by both kernel mode and user mode (if really it is, I 
shallbr   try to perform it -- I can do it in my working time).brbr - 
...brbrThanks.br--brChen GangbrbrOpen, share, and attitude like 
air, water, and life which God blessedbr  


Re: [PATCH] mm: mmap: Simplify the failure return working flow

2015-08-19 Thread gchen gchen

On Tue, 18 Aug 2015 15:57:08 -0700 a...@linux-foundation.org wrote:

 On Wed, 19 Aug 2015 06:27:58 +0800 Chen Gang
 xili_gchen_5...@hotmail.com wrote:

 From: Chen Gang xili_gchen_5...@hotmail.com

 As sent, this patch is From:you@hotmail and Signed-off-by:you@gmail.

 This is peculiar.  I'm assuming that it should have been From:you@gmail and
 I have made that change to my copy of the patch.

 You can do this yourself by putting an explicit From: line at the start
 of the changelog.


Yes, it is really peculiar, the reason is gmail is not stable in China.
I have to send mail in my hotmail address.

But I still want to use my gmail as Signed-off-by, since I have already
used it, and also its name is a little formal than my hotmail.

Welcome any ideas, suggestions and completions for it (e.g. if it is
necessary to let send mail and Signed-off-by mail be the same, I shall
try).

[...]

 So,

 --- a/mm/mmap.c~mm-mmap-simplify-the-failure-return-working-flow-fix
 +++ a/mm/mmap.c
 @@ -2952,7 +2952,7 @@ struct vm_area_struct *copy_vma(struct v
 } else {
 new_vma = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
 if (!new_vma)
 -   return NULL;
 +   goto out;
 *new_vma = *vma;
 new_vma-vm_start = addr;
 new_vma-vm_end = addr + len;
 @@ -2971,10 +2971,11 @@ struct vm_area_struct *copy_vma(struct v
 }
 return new_vma;

 - out_free_mempol:
 +out_free_mempol:
 mpol_put(vma_policy(new_vma));
 - out_free_vma:
 +out_free_vma:
 kmem_cache_free(vm_area_cachep, new_vma);
 +out:
 return NULL;
  }


It is OK to me, thanks.

During these days (2-4 months), I shall try to make some patches for
Linux mm:

 - I am learning Linux kernel mmu, so I can re-use part of code to user
   mode (add softmmu to qemu linux user in my working time). Then I can
   try some mm patches when I am reading related code.

 - At present, cross-building various archs with allmodconfig looks OK
   (have no many issues), so for me, I can stop and start another parts
   (e.g. mmu, loongson machine of mips arch, ...).

Welcome any ideas, suggestions and completions for it:

 - Assume I am not quite familiar with mmu -- in honest, I feel I am
   really not.

 - Is it possible to build the related 'softmmu' as a module which can
   be used by both kernel mode and user mode (if really it is, I shall
   try to perform it -- I can do it in my working time).

 - ...

Thanks.
--
Chen Gang

Open, share, and attitude like air, water, and life which God blessed
  

Re: [PATCH] mm: mmap: Simplify the failure return working flow

2015-08-18 Thread Andrew Morton
On Wed, 19 Aug 2015 06:27:58 +0800 Chen Gang  
wrote:

> From: Chen Gang 

As sent, this patch is From:you@hotmail and Signed-off-by:you@gmail.

This is peculiar.  I'm assuming that it should have been From:you@gmail and
I have made that change to my copy of the patch.

You can do this yourself by putting an explicit From: line at the start
of the changelog.


> @@ -2958,23 +2957,23 @@ struct vm_area_struct *copy_vma(struct vm_area_struct 
> **vmap,
>   *need_rmap_locks = (new_vma->vm_pgoff <= vma->vm_pgoff);
>   } else {
>   new_vma = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
> - if (new_vma) {
> - *new_vma = *vma;
> - new_vma->vm_start = addr;
> - new_vma->vm_end = addr + len;
> - new_vma->vm_pgoff = pgoff;
> - if (vma_dup_policy(vma, new_vma))
> - goto out_free_vma;
> - INIT_LIST_HEAD(_vma->anon_vma_chain);
> - if (anon_vma_clone(new_vma, vma))
> - goto out_free_mempol;
> - if (new_vma->vm_file)
> - get_file(new_vma->vm_file);
> - if (new_vma->vm_ops && new_vma->vm_ops->open)
> - new_vma->vm_ops->open(new_vma);
> - vma_link(mm, new_vma, prev, rb_link, rb_parent);
> - *need_rmap_locks = false;
> - }
> + if (!new_vma)
> + return NULL;
> + *new_vma = *vma;
> + new_vma->vm_start = addr;
> + new_vma->vm_end = addr + len;
> + new_vma->vm_pgoff = pgoff;
> + if (vma_dup_policy(vma, new_vma))
> + goto out_free_vma;
> + INIT_LIST_HEAD(_vma->anon_vma_chain);
> + if (anon_vma_clone(new_vma, vma))
> + goto out_free_mempol;
> + if (new_vma->vm_file)
> + get_file(new_vma->vm_file);
> + if (new_vma->vm_ops && new_vma->vm_ops->open)
> + new_vma->vm_ops->open(new_vma);
> + vma_link(mm, new_vma, prev, rb_link, rb_parent);
> + *need_rmap_locks = false;
>   }
>   return new_vma;

Embedding a return deep inside the function isn't good.  It can lead to
resource leaks, locking leaks etc as the code evolves.  This is the
main reason why the kernel uses goto, IMO: single-entry, single-exit.

So,

--- a/mm/mmap.c~mm-mmap-simplify-the-failure-return-working-flow-fix
+++ a/mm/mmap.c
@@ -2952,7 +2952,7 @@ struct vm_area_struct *copy_vma(struct v
} else {
new_vma = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
if (!new_vma)
-   return NULL;
+   goto out;
*new_vma = *vma;
new_vma->vm_start = addr;
new_vma->vm_end = addr + len;
@@ -2971,10 +2971,11 @@ struct vm_area_struct *copy_vma(struct v
}
return new_vma;
 
- out_free_mempol:
+out_free_mempol:
mpol_put(vma_policy(new_vma));
- out_free_vma:
+out_free_vma:
kmem_cache_free(vm_area_cachep, new_vma);
+out:
return NULL;
 }
 
_

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] mm: mmap: Simplify the failure return working flow

2015-08-18 Thread Andrew Morton
On Wed, 19 Aug 2015 06:27:58 +0800 Chen Gang xili_gchen_5...@hotmail.com 
wrote:

 From: Chen Gang xili_gchen_5...@hotmail.com

As sent, this patch is From:you@hotmail and Signed-off-by:you@gmail.

This is peculiar.  I'm assuming that it should have been From:you@gmail and
I have made that change to my copy of the patch.

You can do this yourself by putting an explicit From: line at the start
of the changelog.


 @@ -2958,23 +2957,23 @@ struct vm_area_struct *copy_vma(struct vm_area_struct 
 **vmap,
   *need_rmap_locks = (new_vma-vm_pgoff = vma-vm_pgoff);
   } else {
   new_vma = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
 - if (new_vma) {
 - *new_vma = *vma;
 - new_vma-vm_start = addr;
 - new_vma-vm_end = addr + len;
 - new_vma-vm_pgoff = pgoff;
 - if (vma_dup_policy(vma, new_vma))
 - goto out_free_vma;
 - INIT_LIST_HEAD(new_vma-anon_vma_chain);
 - if (anon_vma_clone(new_vma, vma))
 - goto out_free_mempol;
 - if (new_vma-vm_file)
 - get_file(new_vma-vm_file);
 - if (new_vma-vm_ops  new_vma-vm_ops-open)
 - new_vma-vm_ops-open(new_vma);
 - vma_link(mm, new_vma, prev, rb_link, rb_parent);
 - *need_rmap_locks = false;
 - }
 + if (!new_vma)
 + return NULL;
 + *new_vma = *vma;
 + new_vma-vm_start = addr;
 + new_vma-vm_end = addr + len;
 + new_vma-vm_pgoff = pgoff;
 + if (vma_dup_policy(vma, new_vma))
 + goto out_free_vma;
 + INIT_LIST_HEAD(new_vma-anon_vma_chain);
 + if (anon_vma_clone(new_vma, vma))
 + goto out_free_mempol;
 + if (new_vma-vm_file)
 + get_file(new_vma-vm_file);
 + if (new_vma-vm_ops  new_vma-vm_ops-open)
 + new_vma-vm_ops-open(new_vma);
 + vma_link(mm, new_vma, prev, rb_link, rb_parent);
 + *need_rmap_locks = false;
   }
   return new_vma;

Embedding a return deep inside the function isn't good.  It can lead to
resource leaks, locking leaks etc as the code evolves.  This is the
main reason why the kernel uses goto, IMO: single-entry, single-exit.

So,

--- a/mm/mmap.c~mm-mmap-simplify-the-failure-return-working-flow-fix
+++ a/mm/mmap.c
@@ -2952,7 +2952,7 @@ struct vm_area_struct *copy_vma(struct v
} else {
new_vma = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
if (!new_vma)
-   return NULL;
+   goto out;
*new_vma = *vma;
new_vma-vm_start = addr;
new_vma-vm_end = addr + len;
@@ -2971,10 +2971,11 @@ struct vm_area_struct *copy_vma(struct v
}
return new_vma;
 
- out_free_mempol:
+out_free_mempol:
mpol_put(vma_policy(new_vma));
- out_free_vma:
+out_free_vma:
kmem_cache_free(vm_area_cachep, new_vma);
+out:
return NULL;
 }
 
_

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/