Received: by 10.213.65.68 with SMTP id h4csp525398imn; Fri, 16 Mar 2018 10:23:14 -0700 (PDT) X-Google-Smtp-Source: AG47ELssPhi/bSxyFKpHFAQZms48tiKAMN5Y06t5tk7EZ51zruItZcYfGFdlOXDUrL8CTbUGj4cV X-Received: by 10.99.0.193 with SMTP id 184mr2093807pga.322.1521220994622; Fri, 16 Mar 2018 10:23:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521220994; cv=none; d=google.com; s=arc-20160816; b=Z4A7f805szB4TKaw898dCYIbD5Qw41OCTU/GhXD/OdpJn3GdC4EoK7JZ2ou8BW3cPZ DlK4k3b+LoMYVLQb61zhfTFQ3miHU+TSf7Wgr6lWP2B0CKwB+3efr+5LU8DCUuIsAkpZ rTGfbneJ6KHPku40vr4IO5bQR/mzIx9w5uZkTfXX9hEUgMIR0XQQQukSa9ku35Ui7bbj 6WE/ZPW9ks+1lXhIM4De51iFDDLZ904lsdVc7uLJ45DAuwGN7akWl1IdglER1XL8GJfz b/rmAyYSFn44A2BcLsCyacWCxeZKNftTB7Va9dnvBZH+eqZsJHoScYyhNq0fA9x/7LFA qUQg== 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=eqZkltvilYGdRB2eLYoCGn0drk7e69aIY6YqSjOpjdY=; b=sa2O1ZuebFtCWI+/zZfS5LATXpZmps5vQw9nbCBIq7D6/Y94mOpq4PI+gbq9metUah ePQUafoiNMgjrrvby1Sz05RS/T55NfoUN4JvyfdUGgHeC4aRpnSMwagc8cW6SnZ9wdym 5vUR4knlae9dOpedlN6aClYZTyp+4Uyyl1alXud1HISfmGgZoIDchOO6MEQLuR2oezRx lSacFwfIYAn5ktyIKEZus81Off2QR3uc69/BFTv8qRe/f1v1DQor7L+wvXVSC1oNlASM eSJ8X02OIsGteHuXPCy1i2aZRM/XvNtGGL/Q/ga9Wm3Cjdf216efVUOXH8Y1/w6K2IvV sB8A== 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 z7si5046310pgp.660.2018.03.16.10.22.59; Fri, 16 Mar 2018 10:23:14 -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 S933130AbeCPRV2 (ORCPT + 99 others); Fri, 16 Mar 2018 13:21:28 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:36222 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932706AbeCPP3k (ORCPT ); Fri, 16 Mar 2018 11:29:40 -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 CDF3EFB0; Fri, 16 Mar 2018 15:29:39 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Clay McClure , Richard Weinberger Subject: [PATCH 4.4 46/63] ubi: Fix race condition between ubi volume creation and udev Date: Fri, 16 Mar 2018 16:23:18 +0100 Message-Id: <20180316152304.810109748@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180316152259.964532775@linuxfoundation.org> References: <20180316152259.964532775@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.4-stable 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 Cc: Signed-off-by: Richard Weinberger Signed-off-by: Greg Kroah-Hartman --- 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 @@ -265,6 +265,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; @@ -304,11 +310,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; @@ -328,6 +329,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: