public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dio: return -ENOMEM when kzalloc() fails
@ 2021-07-02 13:31 Salah Triki
  2021-07-02 14:44 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Salah Triki @ 2021-07-02 13:31 UTC (permalink / raw)
  To: gregkh, linux-kernel

Return -ENOMEM when kzalloc() fails in order to inform the caller of the
failure.

Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
 drivers/dio/dio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dio/dio.c b/drivers/dio/dio.c
index 193b40e7aec0..4c06c93c93d3 100644
--- a/drivers/dio/dio.c
+++ b/drivers/dio/dio.c
@@ -219,7 +219,7 @@ static int __init dio_init(void)
                 /* Found a board, allocate it an entry in the list */
 		dev = kzalloc(sizeof(struct dio_dev), GFP_KERNEL);
 		if (!dev)
-			return 0;
+			return -ENOMEM;
 
 		dev->bus = &dio_bus;
 		dev->dev.parent = &dio_bus.dev;
-- 
2.25.1


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

* Re: [PATCH] dio: return -ENOMEM when kzalloc() fails
  2021-07-02 13:31 [PATCH] dio: return -ENOMEM when kzalloc() fails Salah Triki
@ 2021-07-02 14:44 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2021-07-02 14:44 UTC (permalink / raw)
  To: Salah Triki; +Cc: linux-kernel

On Fri, Jul 02, 2021 at 02:31:14PM +0100, Salah Triki wrote:
> Return -ENOMEM when kzalloc() fails in order to inform the caller of the
> failure.
> 
> Signed-off-by: Salah Triki <salah.triki@gmail.com>
> ---
>  drivers/dio/dio.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/dio/dio.c b/drivers/dio/dio.c
> index 193b40e7aec0..4c06c93c93d3 100644
> --- a/drivers/dio/dio.c
> +++ b/drivers/dio/dio.c
> @@ -219,7 +219,7 @@ static int __init dio_init(void)
>                  /* Found a board, allocate it an entry in the list */
>  		dev = kzalloc(sizeof(struct dio_dev), GFP_KERNEL);
>  		if (!dev)
> -			return 0;
> +			return -ENOMEM;

Do you have this hardware to test with?

While this patch looks correct, it still is leaking lots of resources if
this every happens.  Can you fix this up "properly" so that all of the
resources allocated at this point in time will be correctly freed?

Or, really, this is an impossible error path to hit, given that it is at
boot time, so maybe it's just not worth it given that I doubt anyone has
this hardware...

thanks,

greg k-h

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

end of thread, other threads:[~2021-07-02 14:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-02 13:31 [PATCH] dio: return -ENOMEM when kzalloc() fails Salah Triki
2021-07-02 14:44 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox