* [PATCH] cxl: Fix memory allocation failure test
@ 2016-10-30 19:35 Christophe JAILLET
2016-10-30 20:11 ` walter harms
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Christophe JAILLET @ 2016-10-30 19:35 UTC (permalink / raw)
To: imunsie, fbarrat
Cc: linuxppc-dev, linux-kernel, kernel-janitors, Christophe JAILLET
'cxl_context_alloc()' does not return an error pointer. It is just a
shortcut for a call to 'kzalloc' with 'sizeof(struct cxl_context)' as the
size parameter.
So its return value should be compared with NULL.
While fixing it, simplify a bit the code.
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
un-compiled because I don't have the required cross build environment.
---
drivers/misc/cxl/api.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/drivers/misc/cxl/api.c b/drivers/misc/cxl/api.c
index 2e5233b60971..2b88ad8a2a89 100644
--- a/drivers/misc/cxl/api.c
+++ b/drivers/misc/cxl/api.c
@@ -30,10 +30,8 @@ struct cxl_context *cxl_dev_context_init(struct pci_dev *dev)
return ERR_CAST(afu);
ctx = cxl_context_alloc();
- if (IS_ERR(ctx)) {
- rc = PTR_ERR(ctx);
- goto err_dev;
- }
+ if (!ctx)
+ return ERR_PTR(-ENOMEM);
ctx->kernelapi = true;
@@ -61,7 +59,6 @@ struct cxl_context *cxl_dev_context_init(struct pci_dev *dev)
kfree(mapping);
err_ctx:
kfree(ctx);
-err_dev:
return ERR_PTR(rc);
}
EXPORT_SYMBOL_GPL(cxl_dev_context_init);
--
2.9.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] cxl: Fix memory allocation failure test
2016-10-30 19:35 [PATCH] cxl: Fix memory allocation failure test Christophe JAILLET
@ 2016-10-30 20:11 ` walter harms
2016-10-31 6:16 ` Andrew Donnellan
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: walter harms @ 2016-10-30 20:11 UTC (permalink / raw)
To: Christophe JAILLET
Cc: imunsie, fbarrat, linuxppc-dev, linux-kernel, kernel-janitors
Am 30.10.2016 20:35, schrieb Christophe JAILLET:
> 'cxl_context_alloc()' does not return an error pointer. It is just a
> shortcut for a call to 'kzalloc' with 'sizeof(struct cxl_context)' as the
> size parameter.
>
> So its return value should be compared with NULL.
> While fixing it, simplify a bit the code.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> un-compiled because I don't have the required cross build environment.
> ---
> drivers/misc/cxl/api.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/misc/cxl/api.c b/drivers/misc/cxl/api.c
> index 2e5233b60971..2b88ad8a2a89 100644
> --- a/drivers/misc/cxl/api.c
> +++ b/drivers/misc/cxl/api.c
> @@ -30,10 +30,8 @@ struct cxl_context *cxl_dev_context_init(struct pci_dev *dev)
> return ERR_CAST(afu);
>
> ctx = cxl_context_alloc();
> - if (IS_ERR(ctx)) {
> - rc = PTR_ERR(ctx);
> - goto err_dev;
> - }
> + if (!ctx)
> + return ERR_PTR(-ENOMEM);
>
So far i see it is only used 2 times,
To avoid such problems it should be replaced with
kzalloc(sizeof(struct cxl_context), GFP_KERNEL); (from context.c)
or even better:
ctx = kzalloc(*ctx, GFP_KERNEL);
This way the error had been spotted much more early.
just my 2 cents,
re,
wh
> ctx->kernelapi = true;
>
> @@ -61,7 +59,6 @@ struct cxl_context *cxl_dev_context_init(struct pci_dev *dev)
> kfree(mapping);
> err_ctx:
> kfree(ctx);
> -err_dev:
> return ERR_PTR(rc);
> }
> EXPORT_SYMBOL_GPL(cxl_dev_context_init);
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] cxl: Fix memory allocation failure test
2016-10-30 19:35 [PATCH] cxl: Fix memory allocation failure test Christophe JAILLET
2016-10-30 20:11 ` walter harms
@ 2016-10-31 6:16 ` Andrew Donnellan
2016-11-02 16:45 ` Frederic Barrat
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Andrew Donnellan @ 2016-10-31 6:16 UTC (permalink / raw)
To: Christophe JAILLET, imunsie, fbarrat
Cc: kernel-janitors, linuxppc-dev, linux-kernel
On 31/10/16 06:35, Christophe JAILLET wrote:
> 'cxl_context_alloc()' does not return an error pointer. It is just a
> shortcut for a call to 'kzalloc' with 'sizeof(struct cxl_context)' as the
> size parameter.
>
> So its return value should be compared with NULL.
> While fixing it, simplify a bit the code.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
> ---
> un-compiled because I don't have the required cross build environment.
Compiles on my system!
--
Andrew Donnellan OzLabs, ADL Canberra
andrew.donnellan@au1.ibm.com IBM Australia Limited
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] cxl: Fix memory allocation failure test
2016-10-30 19:35 [PATCH] cxl: Fix memory allocation failure test Christophe JAILLET
2016-10-30 20:11 ` walter harms
2016-10-31 6:16 ` Andrew Donnellan
@ 2016-11-02 16:45 ` Frederic Barrat
2016-11-16 1:56 ` Ian Munsie
2016-11-22 0:34 ` Michael Ellerman
4 siblings, 0 replies; 6+ messages in thread
From: Frederic Barrat @ 2016-11-02 16:45 UTC (permalink / raw)
To: Christophe JAILLET, imunsie; +Cc: kernel-janitors, linuxppc-dev, linux-kernel
Le 30/10/2016 à 20:35, Christophe JAILLET a écrit :
> 'cxl_context_alloc()' does not return an error pointer. It is just a
> shortcut for a call to 'kzalloc' with 'sizeof(struct cxl_context)' as the
> size parameter.
>
> So its return value should be compared with NULL.
> While fixing it, simplify a bit the code.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
Acked-by: Frederic Barrat <fbarrat@linux.vnet.ibm.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] cxl: Fix memory allocation failure test
2016-10-30 19:35 [PATCH] cxl: Fix memory allocation failure test Christophe JAILLET
` (2 preceding siblings ...)
2016-11-02 16:45 ` Frederic Barrat
@ 2016-11-16 1:56 ` Ian Munsie
2016-11-22 0:34 ` Michael Ellerman
4 siblings, 0 replies; 6+ messages in thread
From: Ian Munsie @ 2016-11-16 1:56 UTC (permalink / raw)
To: Christophe JAILLET; +Cc: fbarrat, linuxppc-dev, linux-kernel, kernel-janitors
Acked-by: Ian Munsie <imunsie@au1.ibm.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: cxl: Fix memory allocation failure test
2016-10-30 19:35 [PATCH] cxl: Fix memory allocation failure test Christophe JAILLET
` (3 preceding siblings ...)
2016-11-16 1:56 ` Ian Munsie
@ 2016-11-22 0:34 ` Michael Ellerman
4 siblings, 0 replies; 6+ messages in thread
From: Michael Ellerman @ 2016-11-22 0:34 UTC (permalink / raw)
To: Christophe Jaillet, imunsie, fbarrat
Cc: kernel-janitors, Christophe JAILLET, linuxppc-dev, linux-kernel
On Sun, 2016-10-30 at 19:35:57 UTC, Christophe Jaillet wrote:
> 'cxl_context_alloc()' does not return an error pointer. It is just a
> shortcut for a call to 'kzalloc' with 'sizeof(struct cxl_context)' as the
> size parameter.
>
> So its return value should be compared with NULL.
> While fixing it, simplify a bit the code.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
> Acked-by: Frederic Barrat <fbarrat@linux.vnet.ibm.com>
> Acked-by: Ian Munsie <imunsie@au1.ibm.com>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/5cd4f5cec2374d2c09299211d2b357
cheers
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2016-11-22 0:34 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-30 19:35 [PATCH] cxl: Fix memory allocation failure test Christophe JAILLET
2016-10-30 20:11 ` walter harms
2016-10-31 6:16 ` Andrew Donnellan
2016-11-02 16:45 ` Frederic Barrat
2016-11-16 1:56 ` Ian Munsie
2016-11-22 0:34 ` Michael Ellerman
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).