Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2283662imm; Thu, 7 Jun 2018 08:10:19 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJKlgCWtFtsLtMjLtfCQAFWAo1K4seOxGWeU85vOiOYG6OXUefFVLr538IVaR6jgNFFGDCW X-Received: by 2002:a63:6bc7:: with SMTP id g190-v6mr1919164pgc.230.1528384219409; Thu, 07 Jun 2018 08:10:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528384219; cv=none; d=google.com; s=arc-20160816; b=jyc/J26Ryp/VSb48Comafnxss4igAnkq73IsAlqzhM/BLFtOFdEb15RoVMkUOxFXoh 3tJ4SpPxzCZhbaamaUy7o/B15XYYgK7nFUJgSUPyoKI1Zdmhw8D+hVh3gEW3R9yoST2G LnWOBiHJ85f17j3Y6ADRUW0hAlQQ6sNwDLHwYMO3vUe/6UxLuiBGbn1fdTAW0OGWSZ4Q yaig7rwUS0cUPyEjmsRN5ln3v+ezOHdyZ/1W/PmEJIUZ2KCk2p6NkpxkVxA1FMpCHG3e M5EtsBGBaub8g2NtgZ1V+WVEQWNMI1TzaToxC90uX81CNSEFzXCHlYVYpVwUXHFWeGBh eYWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=YTYdrKuvCNtKYoBElYKO1ff468qPNYoCYO/TiY4DqVI=; b=Gfs9VehevHSGfmwvd8N3w+oHa0r5JpvijrmWDQrwulwZb4d1+ZsTSppTLj67gcq/wF 8f7FwsydJ4z1Z0h65HqEVUWB6i7dNhpsFd6WTKY0diu36YhyEW0V1t5FFSYcmuWPFKJg 44jbfEz0LY7iB0+J8CVlYz/UPqaHwcc0OI0onEVswbbnp9np2HJ/5Ryqdj93IZgGBExu JMzOgkPKxQ55Yc1UH9UxUz2TR987W/wPFmTXElPjvQ0/siXzbybmWXHLbVn9K7Hk33y6 d12m/vMYBXuNF6iV+KtHTgIVn+2hto8hDlgtCeQSMvlNzgRx/XYG0euISczttkBjJBSO 0Zog== 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 j193-v6si28721977pge.371.2018.06.07.08.10.01; Thu, 07 Jun 2018 08:10:19 -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 S935979AbeFGPDv (ORCPT + 99 others); Thu, 7 Jun 2018 11:03:51 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:41534 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935962AbeFGPDr (ORCPT ); Thu, 7 Jun 2018 11:03:47 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvbm-0005hK-ON; Thu, 07 Jun 2018 15:09:46 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvb3-0002sV-1T; Thu, 07 Jun 2018 15:09:01 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Clay McClure" , "Richard Weinberger" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 139/410] ubi: Fix race condition between ubi volume creation and udev In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Clay McClure commit a51a0c8d213594bc094cb8e54aad0cb6d7f7b9a6 upstream. Similar to commit 714fb87e8bc0 ("ubi: Fix race condition between ubi device creation and udev"), we should make the volume active before registering it. Signed-off-by: Clay McClure Signed-off-by: Richard Weinberger [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- drivers/mtd/ubi/vmt.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) --- a/drivers/mtd/ubi/vmt.c +++ b/drivers/mtd/ubi/vmt.c @@ -308,6 +308,12 @@ int ubi_create_volume(struct ubi_device vol->last_eb_bytes = vol->usable_leb_size; } + /* Make volume "available" before it becomes accessible via sysfs */ + spin_lock(&ubi->volumes_lock); + ubi->volumes[vol_id] = vol; + ubi->vol_count += 1; + spin_unlock(&ubi->volumes_lock); + /* Register character device for the volume */ cdev_init(&vol->cdev, &ubi_vol_cdev_operations); vol->cdev.owner = THIS_MODULE; @@ -350,11 +356,6 @@ int ubi_create_volume(struct ubi_device if (err) goto out_sysfs; - spin_lock(&ubi->volumes_lock); - ubi->volumes[vol_id] = vol; - ubi->vol_count += 1; - spin_unlock(&ubi->volumes_lock); - ubi_volume_notify(ubi, vol, UBI_VOLUME_ADDED); self_check_volumes(ubi); return err; @@ -374,6 +375,10 @@ out_sysfs: out_cdev: cdev_del(&vol->cdev); out_mapping: + spin_lock(&ubi->volumes_lock); + ubi->volumes[vol_id] = NULL; + ubi->vol_count -= 1; + spin_unlock(&ubi->volumes_lock); if (do_free) kfree(vol->eba_tbl); out_acc: