Received: by 10.213.65.68 with SMTP id h4csp217855imn; Fri, 23 Mar 2018 03:08:27 -0700 (PDT) X-Google-Smtp-Source: AG47ELue3u3JNrcStU0Df0vQIripdgz3JXICJjHPiz1jKtxegDI+IlOetudczQ9Ip4dIpsLaKimi X-Received: by 2002:a17:902:9a8b:: with SMTP id w11-v6mr22327821plp.136.1521799707433; Fri, 23 Mar 2018 03:08:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521799707; cv=none; d=google.com; s=arc-20160816; b=Q59jVdQidWe7psSOKnYHUIKIbWH7fuqmSpkGkOPBwm+sAWvIu+RdvLVGlwe6ZPelUO +OFxKFjC1zY4X5nGJ5uHgLEMzI5KzzHxbpslKB7LJmGkHbUAkVKOkkDsNEe0QbuIMBwu 4cRTrItoaS7pi8zpy3fU8RYFR50aBPF5OwwIogXGSgLhyzmgOAQTnLC6yBVew+DLNDQA buP7iSJMPa7xWp6h/1Bqj+C3UsHWPjweeW8fV8KM5ITZJtbMbRcy2XY0sUrkDRfDD00d GkqvBN+7bIucqXisxDqAXqG2rKahNpJv2z6O1/fkuIl1uJwK4/yJDBe3s33+wcSNFkpN HV+Q== 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=8/tfImPPqnb7k5Pwsu3h0oiT1WEkejlHWo7zpN3lkPg=; b=kKjefcSFSultsvKND9Qt4+/HLF+NITy0txYOogwfWeHq6/Zp89vS26Q3Hyx9DOkVyY GbfwvOxuS+CraSqmqKfpmXX2CXugacmWcwRpEQZXFSR3HFS0EqVwsWBvb/Bnw/VF7sUg 715tsLkVbyOQDKGtVDjCtISwLq3QWmCx6SVISmPK4fwXKUINm1oHCSaum/xmyhyHINp/ 2k4WhwDzIKCwBliYyvzqvwhDegcSMuxKc/YmGCQzY3UQmK5kDrJsnDT83UkjLpDmDItU Fxa/ZbSK19vHGdU2gRg/7/636PKP1VCq0IfPYBxvqSq+FAAaeHjefrvBrvYcHs4W4EzS LXzw== 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 h11-v6si8186715plk.742.2018.03.23.03.08.12; Fri, 23 Mar 2018 03:08:27 -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 S932346AbeCWKHG (ORCPT + 99 others); Fri, 23 Mar 2018 06:07:06 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:41068 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932312AbeCWKHA (ORCPT ); Fri, 23 Mar 2018 06:07:00 -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 F3E8BD09; Fri, 23 Mar 2018 10:06:59 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Finn Thain , Michael Schmitz , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.9 067/177] scsi: mac_esp: Replace bogus memory barrier with spinlock Date: Fri, 23 Mar 2018 10:53:15 +0100 Message-Id: <20180323094208.286238281@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180323094205.090519271@linuxfoundation.org> References: <20180323094205.090519271@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: Finn Thain [ Upstream commit 4da2b1eb230ba4ad19b58984dc52e05b1073df5f ] Commit da244654c66e ("[SCSI] mac_esp: fix for quadras with two esp chips") added mac_scsi_esp_intr() to handle the IRQ lines from a pair of on-board ESP chips (a normal shared IRQ did not work). Proper mutual exclusion was missing from that patch. This patch fixes race conditions between comparison and assignment of esp_chips[] pointers. Signed-off-by: Finn Thain Reviewed-by: Michael Schmitz Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/mac_esp.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) --- a/drivers/scsi/mac_esp.c +++ b/drivers/scsi/mac_esp.c @@ -55,6 +55,7 @@ struct mac_esp_priv { int error; }; static struct esp *esp_chips[2]; +static DEFINE_SPINLOCK(esp_chips_lock); #define MAC_ESP_GET_PRIV(esp) ((struct mac_esp_priv *) \ platform_get_drvdata((struct platform_device *) \ @@ -562,15 +563,18 @@ static int esp_mac_probe(struct platform } host->irq = IRQ_MAC_SCSI; - esp_chips[dev->id] = esp; - mb(); - if (esp_chips[!dev->id] == NULL) { - err = request_irq(host->irq, mac_scsi_esp_intr, 0, "ESP", NULL); - if (err < 0) { - esp_chips[dev->id] = NULL; - goto fail_free_priv; - } + + /* The request_irq() call is intended to succeed for the first device + * and fail for the second device. + */ + err = request_irq(host->irq, mac_scsi_esp_intr, 0, "ESP", NULL); + spin_lock(&esp_chips_lock); + if (err < 0 && esp_chips[!dev->id] == NULL) { + spin_unlock(&esp_chips_lock); + goto fail_free_priv; } + esp_chips[dev->id] = esp; + spin_unlock(&esp_chips_lock); err = scsi_esp_register(esp, &dev->dev); if (err) @@ -579,8 +583,13 @@ static int esp_mac_probe(struct platform return 0; fail_free_irq: - if (esp_chips[!dev->id] == NULL) + spin_lock(&esp_chips_lock); + esp_chips[dev->id] = NULL; + if (esp_chips[!dev->id] == NULL) { + spin_unlock(&esp_chips_lock); free_irq(host->irq, esp); + } else + spin_unlock(&esp_chips_lock); fail_free_priv: kfree(mep); fail_free_command_block: @@ -599,9 +608,13 @@ static int esp_mac_remove(struct platfor scsi_esp_unregister(esp); + spin_lock(&esp_chips_lock); esp_chips[dev->id] = NULL; - if (!(esp_chips[0] || esp_chips[1])) + if (esp_chips[!dev->id] == NULL) { + spin_unlock(&esp_chips_lock); free_irq(irq, NULL); + } else + spin_unlock(&esp_chips_lock); kfree(mep);