Message ID | a824fe65-1708-16ba-68d6-df0f73e0f49a@users.sourceforge.net (mailing list archive) |
---|---|
State | Accepted |
Commit | 4dd9eab39c71628d113168a01473ee17b5f61eac |
Headers | show |
Series | PowerPC-pSeries: Adjustments for seven function implementations | expand |
Hello, On Wed, 18 Oct 2017 21:26:10 +0200 SF Markus Elfring <elfring@users.sourceforge.net> wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Wed, 18 Oct 2017 20:15:32 +0200 > > Return directly after a call of the function "kzalloc_node" failed > at the beginning. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > arch/powerpc/platforms/pseries/iommu.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/powerpc/platforms/pseries/iommu.c > b/arch/powerpc/platforms/pseries/iommu.c index > b6c12b8e3ace..207ff8351af1 100644 --- > a/arch/powerpc/platforms/pseries/iommu.c +++ > b/arch/powerpc/platforms/pseries/iommu.c @@ -61,7 +61,7 @@ static > struct iommu_table_group *iommu_pseries_alloc_group(int node) > table_group = kzalloc_node(sizeof(*table_group), GFP_KERNEL, > node); if (!table_group) > - goto fail_exit; > + return NULL; > > tbl = kzalloc_node(sizeof(*tbl), GFP_KERNEL, node); > if (!tbl) I have seen quite a few fixes that do inverse of this patch after a piece of code allocating some extra piece of memory was added before code that just returns on fail because it is the first allocation in the function. This is not useful. A final fail_exit that frees everything that could have been allocated is much better. That applies to 5/5 as well. Thanks Michal
>> @@ -61,7 +61,7 @@ static struct iommu_table_group *iommu_pseries_alloc_group(int node) >> table_group = kzalloc_node(sizeof(*table_group), GFP_KERNEL, >> node); if (!table_group) >> - goto fail_exit; >> + return NULL; >> >> tbl = kzalloc_node(sizeof(*tbl), GFP_KERNEL, node); >> if (!tbl) > > I have seen quite a few fixes that do inverse of this patch after a > piece of code allocating some extra piece of memory was added before > code that just returns on fail because it is the first allocation in > the function. > > This is not useful. How do you think about an information from the section “7) Centralized exiting of functions” in the document “coding-style.rst” then? “… If there is no cleanup needed then just return directly. …” > A final fail_exit that frees everything that could have been allocated > is much better. I got an other software development opinion for such use cases. I prefer only required function calls there. Regards, Markus
On Thu, 19 Oct 2017 14:04:43 +0200 SF Markus Elfring <elfring@users.sourceforge.net> wrote: > >> @@ -61,7 +61,7 @@ static struct iommu_table_group > >> *iommu_pseries_alloc_group(int node) table_group = > >> kzalloc_node(sizeof(*table_group), GFP_KERNEL, node); if > >> (!table_group) > >> - goto fail_exit; > >> + return NULL; > >> > >> tbl = kzalloc_node(sizeof(*tbl), GFP_KERNEL, node); > >> if (!tbl) > > > > I have seen quite a few fixes that do inverse of this patch after a > > piece of code allocating some extra piece of memory was added before > > code that just returns on fail because it is the first allocation in > > the function. > > > > This is not useful. > > How do you think about an information from the section “7) > Centralized exiting of functions” in the document “coding-style.rst” > then? > > “… > If there is no cleanup needed then just return directly. > …” There is also stated benefit " - errors by not updating individual exit points when making modifications are prevented " which is furthered by using the common cleanup even in case no cleanup is required but running the cleanup does not cause any harm. Thanks Michal
On Wed, 2017-10-18 at 19:26:10 UTC, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Wed, 18 Oct 2017 20:15:32 +0200 > > Return directly after a call of the function "kzalloc_node" failed > at the beginning. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> Applied to powerpc next, thanks. https://git.kernel.org/powerpc/c/4dd9eab39c71628d113168a01473ee cheers
diff --git a/arch/powerpc/platforms/pseries/iommu.c b/arch/powerpc/platforms/pseries/iommu.c index b6c12b8e3ace..207ff8351af1 100644 --- a/arch/powerpc/platforms/pseries/iommu.c +++ b/arch/powerpc/platforms/pseries/iommu.c @@ -61,7 +61,7 @@ static struct iommu_table_group *iommu_pseries_alloc_group(int node) table_group = kzalloc_node(sizeof(*table_group), GFP_KERNEL, node); if (!table_group) - goto fail_exit; + return NULL; tbl = kzalloc_node(sizeof(*tbl), GFP_KERNEL, node); if (!tbl)