Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp185068pxb; Sat, 11 Sep 2021 02:06:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFsiWArwQz9CoY/zBKOPVH35R1iFhhJ+RUro0xaH79Bi3qooK/5WZ7TYM9KOUhh04u3PsB X-Received: by 2002:aa7:c64c:: with SMTP id z12mr2305847edr.228.1631351199846; Sat, 11 Sep 2021 02:06:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631351199; cv=none; d=google.com; s=arc-20160816; b=GwKE7Z64ITj0FKasIVvdfUHBttmW0Dkfvj0Huodtw/QBMY1pv62J7zDJAZsNUOuvf6 Mz8C1F8xXX8SsnfdapstEmyYdtR0z8gGefYkmrvsXlz0yN8tPa01DoNdOLxMcWDDuTl1 YvV6o+fEQBgwTJYPb0h3Akt+dGv445/wI43z85wIx0iWR8eEXSmMrVdJ6oTA97oeyfzS 9tKH5a8jEVm3Ou1HU/k03jaQA3R93b+HZ5jKhh+KMY4AR87iaPMdCmDUWCPnDMqwXftw SCwka2/9GA6OP8M+6s9acBlhrYyhu9nvnO//43mHUr0vMkiOlYv3VP7mgBwq+qSrl3zz 1Trg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=40tlWQGaqtWcp+Olp3FNadicHpUrSBDhuGHeGTCGWdI=; b=z09x9kfswovyfMM2xlqlx92aKcU3N4jRbvkOxparBKb0VAS5sCZsmjaGUGybahRB7x QJlsNDhfXrvfPL+S5fge5evFBmnBWsA1vS5Sk0umm2+Pfs88Stt0rsAGgJVt0uZP/vcT dmS5BFXQxqSaQa2bluKDzM9+I6dPIjH+apVXJJ5mbC59ARVH5q6GsJQK6R8asfKDPzur 29BR5xgwWDD8vkCaxZ2DTAjsx3Q93YQ00Zku4qVwt9ntNrZIYlYOgDpiQb8t3QRqD9E2 9/uTe1vuB3tlbcbOj//UkfC/kdVC2BxJcfI9HYgu0TtsVZcQUzxArohX7aUBe5Ttgd1T /95g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dm14si1374612ejc.226.2021.09.11.02.06.15; Sat, 11 Sep 2021 02:06:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235474AbhIKJD5 (ORCPT + 99 others); Sat, 11 Sep 2021 05:03:57 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:19029 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235334AbhIKJD5 (ORCPT ); Sat, 11 Sep 2021 05:03:57 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4H669D3yYNzblpt; Sat, 11 Sep 2021 16:58:40 +0800 (CST) Received: from dggpemm500004.china.huawei.com (7.185.36.219) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Sat, 11 Sep 2021 17:02:43 +0800 Received: from huawei.com (10.174.28.241) by dggpemm500004.china.huawei.com (7.185.36.219) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Sat, 11 Sep 2021 17:02:43 +0800 From: Bixuan Cui To: , CC: , Subject: [PATCH -next] io-wq: Remove duplicate code in io_workqueue_create() Date: Sat, 11 Sep 2021 16:58:47 +0800 Message-ID: <20210911085847.34849-1-cuibixuan@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.28.241] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500004.china.huawei.com (7.185.36.219) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org While task_work_add() in io_workqueue_create() is true, then duplicate code is executed: -> clear_bit_unlock(0, &worker->create_state); -> io_worker_release(worker); -> atomic_dec(&acct->nr_running); -> io_worker_ref_put(wq); -> return false; -> clear_bit_unlock(0, &worker->create_state); // back to io_workqueue_create() -> io_worker_release(worker); -> kfree(worker); The io_worker_release() and clear_bit_unlock() are executed twice. Fixes: 3146cba99aa2 ("io-wq: make worker creation resilient against signals") Signed-off-by: Bixuan Cui --- fs/io-wq.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fs/io-wq.c b/fs/io-wq.c index 6c55362c1f99..95d0eaed7c00 100644 --- a/fs/io-wq.c +++ b/fs/io-wq.c @@ -329,8 +329,10 @@ static bool io_queue_worker_create(struct io_worker *worker, init_task_work(&worker->create_work, func); worker->create_index = acct->index; - if (!task_work_add(wq->task, &worker->create_work, TWA_SIGNAL)) + if (!task_work_add(wq->task, &worker->create_work, TWA_SIGNAL)) { + clear_bit_unlock(0, &worker->create_state); return true; + } clear_bit_unlock(0, &worker->create_state); fail_release: io_worker_release(worker); @@ -723,11 +725,8 @@ static void io_workqueue_create(struct work_struct *work) struct io_worker *worker = container_of(work, struct io_worker, work); struct io_wqe_acct *acct = io_wqe_get_acct(worker); - if (!io_queue_worker_create(worker, acct, create_worker_cont)) { - clear_bit_unlock(0, &worker->create_state); - io_worker_release(worker); + if (!io_queue_worker_create(worker, acct, create_worker_cont)) kfree(worker); - } } static bool create_io_worker(struct io_wq *wq, struct io_wqe *wqe, int index) -- 2.17.1