Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3056879imm; Sun, 1 Jul 2018 11:13:47 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd4vFJ165j2U3Rxmcz8jZBcGBj16Xay1dIUwPo/5hMAr0yzqrqQLTkMpzbf+C0zsuQcIqmt X-Received: by 2002:a62:859c:: with SMTP id m28-v6mr22441167pfk.42.1530468827466; Sun, 01 Jul 2018 11:13:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530468827; cv=none; d=google.com; s=arc-20160816; b=UmXAMKJZnxXlcUdoTPacm8u3cTOsJTvIgKVxh1Xf0S5bDSYX+C4I06AcpaWVSQbZYd x4OjXMdH+r2S0pBYAMY4tChrNhrzR6BBEOuo4OnSYObdOonvELy03eNzzDsNQbszg8Pa JQXE/1zu8KLHZmrV+xYOlxPUhUk12HFus+ykv8jYc3B5bNmuvp5boicZINuEaj0LyPlV uUGuLJzAlrQHvG0nZIt+g5tEkvNpeFOKzXYhm9br3sNEhv/EHqQkVqKcXjzWPBx+wcax LWcqLGMcvsjwhi3EOUGUumUPSe7fHtxzpYGQiszTcD8izT9ANNThNGN+Dgy3JFfdnzUa m6qQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=34YrqcrRNcAGokSzxn5KKmUsSOxT5ruyuNCLZ5zB5Yg=; b=jT2l0ji+wYu9J03jEPBCBha1i/gudehbSZWyoFcsLO7PqzeZBXGaPbc5spGICOobs9 pg7QD4IrAJoRzqrKI4q/A5ihsyVINsXlMft4/OCJR1ipDxRf3kP+KKeWipQUBiIwzzWp FTIl0qi4Y0J4xoEKx3PiMhZzLDUEKlvTVGUMCxQrtVKO5CrvzNoITEMNgpop4JnqOo5b SBSRo3gthNxD5KHv2OFRV8lW3MzMY7JTxtLS5P7ruHOTRONsIzg5oxU+KusqsZOTsmm2 LW9tS3A2Vvw91/EVZ4BsDNIJxLesYIi50+h27vwRO7M1QCcP2M6OutqzbmyhaN3jdJq3 KeZQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e98-v6si14303348plb.150.2018.07.01.11.13.33; Sun, 01 Jul 2018 11:13:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965511AbeGASMR (ORCPT + 99 others); Sun, 1 Jul 2018 14:12:17 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34086 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965345AbeGAQ1W (ORCPT ); Sun, 1 Jul 2018 12:27:22 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id BBED1AA6; Sun, 1 Jul 2018 16:27:21 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ben Hutchings , Martin Townsend , Richard Weinberger Subject: [PATCH 4.9 068/101] ubi: fastmap: Cancel work upon detach Date: Sun, 1 Jul 2018 18:21:54 +0200 Message-Id: <20180701160759.887412177@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701160757.138608453@linuxfoundation.org> References: <20180701160757.138608453@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Richard Weinberger commit 6e7d80161066c99d12580d1b985cb1408bb58cf1 upstream. Ben Hutchings pointed out that 29b7a6fa1ec0 ("ubi: fastmap: Don't flush fastmap work on detach") does not really fix the problem, it just reduces the risk to hit the race window where fastmap work races against free()'ing ubi->volumes[]. The correct approach is making sure that no more fastmap work is in progress before we free ubi data structures. So we cancel fastmap work right after the ubi background thread is stopped. By setting ubi->thread_enabled to zero we make sure that no further work tries to wake the thread. Fixes: 29b7a6fa1ec0 ("ubi: fastmap: Don't flush fastmap work on detach") Fixes: 74cdaf24004a ("UBI: Fastmap: Fix memory leaks while closing the WL sub-system") Cc: stable@vger.kernel.org Cc: Ben Hutchings Cc: Martin Townsend Signed-off-by: Richard Weinberger Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/ubi/build.c | 3 +++ drivers/mtd/ubi/wl.c | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c @@ -1137,6 +1137,9 @@ int ubi_detach_mtd_dev(int ubi_num, int */ get_device(&ubi->dev); +#ifdef CONFIG_MTD_UBI_FASTMAP + cancel_work_sync(&ubi->fm_work); +#endif ubi_debugfs_exit_dev(ubi); uif_close(ubi); --- a/drivers/mtd/ubi/wl.c +++ b/drivers/mtd/ubi/wl.c @@ -1505,6 +1505,7 @@ int ubi_thread(void *u) } dbg_wl("background thread \"%s\" is killed", ubi->bgt_name); + ubi->thread_enabled = 0; return 0; } @@ -1514,9 +1515,6 @@ int ubi_thread(void *u) */ static void shutdown_work(struct ubi_device *ubi) { -#ifdef CONFIG_MTD_UBI_FASTMAP - flush_work(&ubi->fm_work); -#endif while (!list_empty(&ubi->works)) { struct ubi_work *wrk;