Re: [PATCH v1 1/1] test_firmware: return ENOMEM instead of ENOSPC on failed allocation

From: Mirsad Goran Todorovac
Date: Tue Jun 06 2023 - 02:56:15 EST


On 6/6/23 07:37, Dan Carpenter wrote:
On Mon, Jun 05, 2023 at 06:27:47PM +0200, Mirsad Goran Todorovac wrote:
In a couple of situations like:

name = kstrndup(buf, count, GFP_KERNEL);
if (!name)
return -ENOSPC;

the error is not actually "No space left on device", but "Out of memory".

So, it is semantically correct to return -ENOMEM in all failed kstrndup()
and kzalloc() cases in this driver, as it is not a problem with disk
space, but with kernel memory allocator.

The semantically correct should be:

name = kstrndup(buf, count, GFP_KERNEL);
if (!name)
return -ENOMEM;

Cc: Dan Carpenter <error27@xxxxxxxxx>
Cc: Takashi Iwai <tiwai@xxxxxxx>
Cc: Kees Cook <keescook@xxxxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Mirsad Goran Todorovac <mirsad.todorovac@xxxxxxxxxxxx>
---

The Cc stable might be a little bit much... No Fixes tag either. But
otherwise it looks fine.

Thank you. I will fix these and resubmit.

Best regards,
Mirsad Todorovac

regards,
dan carpenter