Skip to content

Commit 665e6fd

Browse files
Mirsad Goran Todorovacgregkh
authored andcommitted
test_firmware: return ENOMEM instead of ENOSPC on failed memory allocation
commit 7dae593 upstream. 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". 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 failing allocation. The semantically correct should be: name = kstrndup(buf, count, GFP_KERNEL); if (!name) return -ENOMEM; Cc: Dan Carpenter <[email protected]> Cc: Takashi Iwai <[email protected]> Cc: Kees Cook <[email protected]> Cc: "Luis R. Rodriguez" <[email protected]> Cc: Scott Branden <[email protected]> Cc: Hans de Goede <[email protected]> Cc: Brian Norris <[email protected]> Fixes: c92316b ("test_firmware: add batched firmware tests") Fixes: 0a8adf5 ("test: add firmware_class loader test") Fixes: 548193c ("test_firmware: add support for firmware_request_platform") Fixes: eb91094 ("test: firmware_class: add asynchronous request trigger") Fixes: 061132d ("test_firmware: add test custom fallback trigger") Fixes: 7feebfa ("test_firmware: add support for request_firmware_into_buf") Signed-off-by: Mirsad Goran Todorovac <[email protected]> Reviewed-by: Dan Carpenter <[email protected]> Message-ID: <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 0ab95d5 commit 665e6fd

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/test_firmware.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ static int __kstrncpy(char **dst, const char *name, size_t count, gfp_t gfp)
214214
{
215215
*dst = kstrndup(name, count, gfp);
216216
if (!*dst)
217-
return -ENOSPC;
217+
return -ENOMEM;
218218
return count;
219219
}
220220

@@ -671,7 +671,7 @@ static ssize_t trigger_request_store(struct device *dev,
671671

672672
name = kstrndup(buf, count, GFP_KERNEL);
673673
if (!name)
674-
return -ENOSPC;
674+
return -ENOMEM;
675675

676676
pr_info("loading '%s'\n", name);
677677

@@ -719,7 +719,7 @@ static ssize_t trigger_request_platform_store(struct device *dev,
719719

720720
name = kstrndup(buf, count, GFP_KERNEL);
721721
if (!name)
722-
return -ENOSPC;
722+
return -ENOMEM;
723723

724724
pr_info("inserting test platform fw '%s'\n", name);
725725
efi_embedded_fw.name = name;
@@ -772,7 +772,7 @@ static ssize_t trigger_async_request_store(struct device *dev,
772772

773773
name = kstrndup(buf, count, GFP_KERNEL);
774774
if (!name)
775-
return -ENOSPC;
775+
return -ENOMEM;
776776

777777
pr_info("loading '%s'\n", name);
778778

@@ -817,7 +817,7 @@ static ssize_t trigger_custom_fallback_store(struct device *dev,
817817

818818
name = kstrndup(buf, count, GFP_KERNEL);
819819
if (!name)
820-
return -ENOSPC;
820+
return -ENOMEM;
821821

822822
pr_info("loading '%s' using custom fallback mechanism\n", name);
823823

@@ -868,7 +868,7 @@ static int test_fw_run_batch_request(void *data)
868868

869869
test_buf = kzalloc(TEST_FIRMWARE_BUF_SIZE, GFP_KERNEL);
870870
if (!test_buf)
871-
return -ENOSPC;
871+
return -ENOMEM;
872872

873873
if (test_fw_config->partial)
874874
req->rc = request_partial_firmware_into_buf

0 commit comments

Comments
 (0)