Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp11554025rwb; Fri, 25 Nov 2022 17:43:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf7NHtephoPVW3qqOX7fbGMpSG3PrJSaPGjCG0wY/ji/KUOf1ReqREZ3R9K8pmZvIWJVAn5p X-Received: by 2002:a17:903:120c:b0:188:fc5f:84f3 with SMTP id l12-20020a170903120c00b00188fc5f84f3mr33649003plh.2.1669427004490; Fri, 25 Nov 2022 17:43:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669427004; cv=none; d=google.com; s=arc-20160816; b=Iht0CcgiAh8wKmI5WkrLGC/ciYhtrcfSk5xqrYuIRh5GygMR3Uwblu1EZ/jq4o/sE3 0aKkNJ6vkbSelgUrwLrUrf4xEsTEKUuF5slR5loxI8G2SrP8P/tLqOH5E61KcGv/heDy GtiUC9wHEJHFZyl0YjDkdVh5rsbIj8qNgZHG2C7A4VXqNV6mSYXTnLbMDA3iY3CbuM01 FPgHiQCZXE8TRDSpgHnbntF88+QtEODO4eKZFJpPqelX0m/XJjH2IkJuPZ+2jjJJDTZe 7yhRUV7CGqjU2L83ovRL5AtjvN35O/Wd1vNNxBisfYuRj+cn6KylHegAwUQ8WWtDWDcL 093A== 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; bh=cint/M770DyK0zb9+XCzTEDQ9aK29LpAY4uvCYAzEz4=; b=KyoOplr3/dXFah42v5KnDbvZCsiI/kDmk2m36/mNRu9gufynd5agS7ICioL0em8faA 42c5aogDSKNR68QHLIS1B/Z8BLY0ODxikvPGLOm/1ObR0dtKftK4ZItFXrIISw8S+bU2 mbqg2e+ZnJyPP8Fz4iTWw1kF+acoid4Zvd9xKiwSKfftaqyxgEq4nVjB3cS7epGpSO3Y RS8Or1BjjHNkIsh8Bm8drFnJy4IIebeD5qL0rP3WEc1pm4iz8uYzngeQXSl8QjZcQsQP GfKOnoao+BBYgbm6BcTkRYDOgyld/zF7CgB8+++sj5fFn5fkTWW70pTTnWP3PqO7wVPS 3ssA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ck5-20020a17090afe0500b00218ed5d3fc5si7569306pjb.35.2022.11.25.17.43.08; Fri, 25 Nov 2022 17:43:24 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230001AbiKZB0O (ORCPT + 86 others); Fri, 25 Nov 2022 20:26:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229722AbiKZB0M (ORCPT ); Fri, 25 Nov 2022 20:26:12 -0500 Received: from cstnet.cn (smtp84.cstnet.cn [159.226.251.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EAFC343878; Fri, 25 Nov 2022 17:26:10 -0800 (PST) Received: from localhost.localdomain (unknown [124.16.138.125]) by APP-05 (Coremail) with SMTP id zQCowABXd8wna4FjF24+Ag--.33231S2; Sat, 26 Nov 2022 09:25:59 +0800 (CST) From: Jiasheng Jiang To: error27@gmail.com, maximlevitsky@gmail.com, oakad@yahoo.com, ulf.hansson@linaro.org, christophe.jaillet@wanadoo.fr, axboe@kernel.dk, hare@suse.de Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, Jiasheng Jiang Subject: [PATCH v2] memstick/ms_block: Add check for alloc_ordered_workqueue Date: Sat, 26 Nov 2022 09:25:58 +0800 Message-Id: <20221126012558.34374-1-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: zQCowABXd8wna4FjF24+Ag--.33231S2 X-Coremail-Antispam: 1UD129KBjvJXoW7AFy5WF4UCF1xAFyxJF1kZrb_yoW8Xw4fpa 15CF9rWw4rGa1DGrn8tr15WFW3C3W8G3yfG3sagwnIvwn5ArsxXFyxtas0qFs8uFZ3JF4D AFsxt3yDWFyDJw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvG14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r1I6r4UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j 6F4UM28EF7xvwVC2z280aVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVCY1x0267AKxVW8Jr 0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj 6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr 0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E 8cxan2IY04v7MxkIecxEwVAFwVWkMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r 1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CE b7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0x vE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAI cVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa 73UjIFyTuYvjfUOMKZDUUUU X-Originating-IP: [124.16.138.125] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS 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 As the alloc_ordered_workqueue may return NULL pointer, it should be better to add check for the return value. Moreover, the msb->io_queue should be freed if error occurs later. Fixes: 0ab30494bc4f ("memstick: add support for legacy memorysticks") Signed-off-by: Jiasheng Jiang --- Changelog: v1 -> v2: 1. Assign error number to rc if alloc_ordered_workqueue fails. 2. Free msb->io_queue if error occurs later. --- drivers/memstick/core/ms_block.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/memstick/core/ms_block.c b/drivers/memstick/core/ms_block.c index ba8414519515..04115cd92433 100644 --- a/drivers/memstick/core/ms_block.c +++ b/drivers/memstick/core/ms_block.c @@ -2116,6 +2116,11 @@ static int msb_init_disk(struct memstick_dev *card) dbg("Set total disk size to %lu sectors", capacity); msb->io_queue = alloc_ordered_workqueue("ms_block", WQ_MEM_RECLAIM); + if (!msb->io_queue) { + rc = -ENOMEM; + goto out_cleanup_disk; + } + INIT_WORK(&msb->io_work, msb_io_work); sg_init_table(msb->prealloc_sg, MS_BLOCK_MAX_SEGS+1); @@ -2125,10 +2130,12 @@ static int msb_init_disk(struct memstick_dev *card) msb_start(card); rc = device_add_disk(&card->dev, msb->disk, NULL); if (rc) - goto out_cleanup_disk; + goto out_destroy_workqueue; dbg("Disk added"); return 0; +out_destroy_workqueue: + destroy_workqueue(msb->io_queue); out_cleanup_disk: put_disk(msb->disk); out_free_tag_set: -- 2.25.1