Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp6715725rwd; Tue, 6 Jun 2023 00:29:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6pwg8EhU9Vqjv4X/Kls8P5U+iiXVL7956zx7jPs6ZYHhTYy+9/zLzwL+1/RTDyMSGKbg6v X-Received: by 2002:a05:6870:4296:b0:1a3:10fe:998e with SMTP id y22-20020a056870429600b001a310fe998emr953632oah.28.1686036551556; Tue, 06 Jun 2023 00:29:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686036551; cv=none; d=google.com; s=arc-20160816; b=ozWf5UsEJ4Wn1Yvs1m2hAp8PS5jDb83B2ZArq6aULbwKTklPjpxsqlj6FhsjpLemAT GjZkDQCMlT1ejZGWdA10QolL9ZP07IXdOXfXGCREEs6dxFPor7RFg4Xp35bUpMnOR0mS tAfEgFWddcDdukRMDXp+n5DkdVDSBDk3muvlqUe1lv9Wa2i/muwnlgnLwjrNHvu4Mjtx 3ld+a72mUNgx+0JMX5evCTfamIczY5nH78dtIvNOJ2Nl6ETwopgnOCbTap0x2Q6siMWr w/lSw5rW/3rQjKRjg0o35l0OiWJphYcDQLrbPkRtiDAHpFN2+ku9Y/zygB+jq5Xo7ox8 1Iqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=AH5lREoZ2pTgsVsDidZ7vdohu26w0BZ7M7YjnimK36s=; b=FXaeC9oS2YQTW19la6wCSE99/T3TU0yBEmIJPmdGEG2tmyY/ir4lALJ6BhXxWxzRA9 lmVQFolMQwBjY9AD+m6hJmQlsjAnAj7zCTNRUbVmlFBM9Fs8uOST6pD2WLIalG3yPIAo AwY+gdI4Qc6JLUQpvgxFtRzWk6V4buCcZfgHbYkTZfYvXMZjbSY+TGqenDs+7uL98IoJ HGiNA3ZHHBJjCEv2jgshAhYW9W/tQImHGtdHdhlD/R6HB58Os68kpjV4HDWcP0b1w8kX RZjVa0Ft52HvXve7pCoziq2ePnuUyqvv/qRFYtp8o4zYbpet0lZfenZ1i6bSdLcQp6AG DYJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@alu.unizg.hr header.s=mail header.b=oDhWwwPR; dkim=fail header.i=@alu.unizg.hr header.s=mail header.b=O15qSqTK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alu.unizg.hr Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t75-20020a63784e000000b00518b499da59si6537073pgc.901.2023.06.06.00.28.59; Tue, 06 Jun 2023 00:29:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@alu.unizg.hr header.s=mail header.b=oDhWwwPR; dkim=fail header.i=@alu.unizg.hr header.s=mail header.b=O15qSqTK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alu.unizg.hr Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235177AbjFFHLJ (ORCPT + 99 others); Tue, 6 Jun 2023 03:11:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234018AbjFFHLI (ORCPT ); Tue, 6 Jun 2023 03:11:08 -0400 Received: from domac.alu.hr (domac.alu.unizg.hr [IPv6:2001:b68:2:2800::3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41392C5 for ; Tue, 6 Jun 2023 00:11:07 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by domac.alu.hr (Postfix) with ESMTP id BDD43601AE; Tue, 6 Jun 2023 09:11:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=alu.unizg.hr; s=mail; t=1686035465; bh=UJK34aq/lMucjhp/a7/aUCCcSIOTJuKOc3zJhvpqDX0=; h=From:To:Cc:Subject:Date:From; b=oDhWwwPRXn2uDir6vnNDGoUYZCRa+F7dlRNW0WmR8pB4icDGJ/6lEMBdzHoiNKMkI RISqX4RK/EiNVE1AWm3UGXGC52ArzYkdCxc8N4xQqSCJOeGnqHLg8hZ3OmaTL3psf+ MpIsyEtZ49RMRk8nrLARHisBjrGm0VMaogwTkmbsxJ6OCqr60Pk/X1RNfWhSrTlJ8e +VgERmsUkQEYX1ueppI8GWn3lJ3TWuw6gXY0LFO58l/Z4uz+GMbfPUfNJfo5Xj17z/ pB+YbZJU2EDupeAO9RBPirpnnVy+HRH6pWPLlEUNNlJFtHXrahw5eVVVKZqnZn6iVi OYhGm5MjkerGA== X-Virus-Scanned: Debian amavisd-new at domac.alu.hr Received: from domac.alu.hr ([127.0.0.1]) by localhost (domac.alu.hr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uUg_2SDxUHnf; Tue, 6 Jun 2023 09:11:03 +0200 (CEST) Received: from defiant.. (unknown [77.237.113.62]) by domac.alu.hr (Postfix) with ESMTPSA id 74DAD601AC; Tue, 6 Jun 2023 09:10:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=alu.unizg.hr; s=mail; t=1686035463; bh=UJK34aq/lMucjhp/a7/aUCCcSIOTJuKOc3zJhvpqDX0=; h=From:To:Cc:Subject:Date:From; b=O15qSqTKKP14s7UI4/49Xm8k+X71oE/uB6zkgtUgj5tsVv8Y4puiwXzRzKXWnD1WV JMz2JKf+G4fXkvRhil0rrAEK69ybGH98GNLqJ2PlUP3u5zDcpxzCi2He7MSqcFddte VOWsFtDSFk6277kV7j6A7qHYn2wAyKbm6CEgX+m/ySxnT/D7Hk4AidXVD/Tku2EMp+ iEiyvk5yKdOAhcFm9yOU2YnFvlK33jgN92Witj+pD/FfjxrOkn+aJzZ7VlNE8MEbde dfdNJqbYHu5P4bOCrSuVcCzrDJy6jBM3vhWhmi0UEyRmQs9mnMbr/Nyn2NfrLdQvyg W0cIQAnlOlMFA== From: Mirsad Goran Todorovac To: Greg Kroah-Hartman , Mirsad Goran Todorovac , linux-kernel@vger.kernel.org Cc: Dan Carpenter , Takashi Iwai , Kees Cook , "Luis R. Rodriguez" , Scott Branden , Hans de Goede , Brian Norris Subject: [PATCH v2 1/1] test_firmware: return ENOMEM instead of ENOSPC on failed memory allocation Date: Tue, 6 Jun 2023 09:08:10 +0200 Message-Id: <20230606070808.9300-1-mirsad.todorovac@alu.unizg.hr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FILL_THIS_FORM,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: Takashi Iwai Cc: Kees Cook Cc: "Luis R. Rodriguez" Cc: Scott Branden Cc: Hans de Goede Cc: Brian Norris Fixes: c92316bf8e948 ("test_firmware: add batched firmware tests") Fixes: 0a8adf584759c ("test: add firmware_class loader test") Fixes: 548193cba2a7d ("test_firmware: add support for firmware_request_platform") Fixes: eb910947c82f9 ("test: firmware_class: add asynchronous request trigger") Fixes: 061132d2b9c95 ("test_firmware: add test custom fallback trigger") Fixes: 7feebfa487b92 ("test_firmware: add support for request_firmware_into_buf") Signed-off-by: Mirsad Goran Todorovac --- v1 -> v2: - minor clarifications in description and subject line - added Fixes: lines - added Cc: to authors of the fixed commits - removed Cc: stable as suggested lib/test_firmware.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/test_firmware.c b/lib/test_firmware.c index 1d7d480b8eeb..add4699fc6cd 100644 --- a/lib/test_firmware.c +++ b/lib/test_firmware.c @@ -214,7 +214,7 @@ static int __kstrncpy(char **dst, const char *name, size_t count, gfp_t gfp) { *dst = kstrndup(name, count, gfp); if (!*dst) - return -ENOSPC; + return -ENOMEM; return count; } @@ -671,7 +671,7 @@ static ssize_t trigger_request_store(struct device *dev, name = kstrndup(buf, count, GFP_KERNEL); if (!name) - return -ENOSPC; + return -ENOMEM; pr_info("loading '%s'\n", name); @@ -719,7 +719,7 @@ static ssize_t trigger_request_platform_store(struct device *dev, name = kstrndup(buf, count, GFP_KERNEL); if (!name) - return -ENOSPC; + return -ENOMEM; pr_info("inserting test platform fw '%s'\n", name); efi_embedded_fw.name = name; @@ -772,7 +772,7 @@ static ssize_t trigger_async_request_store(struct device *dev, name = kstrndup(buf, count, GFP_KERNEL); if (!name) - return -ENOSPC; + return -ENOMEM; pr_info("loading '%s'\n", name); @@ -817,7 +817,7 @@ static ssize_t trigger_custom_fallback_store(struct device *dev, name = kstrndup(buf, count, GFP_KERNEL); if (!name) - return -ENOSPC; + return -ENOMEM; pr_info("loading '%s' using custom fallback mechanism\n", name); @@ -868,7 +868,7 @@ static int test_fw_run_batch_request(void *data) test_buf = kzalloc(TEST_FIRMWARE_BUF_SIZE, GFP_KERNEL); if (!test_buf) - return -ENOSPC; + return -ENOMEM; if (test_fw_config->partial) req->rc = request_partial_firmware_into_buf -- 2.34.1