Received: by 10.213.65.68 with SMTP id h4csp233557imn; Fri, 23 Mar 2018 03:31:15 -0700 (PDT) X-Google-Smtp-Source: AG47ELsmTQBSO0fHOq0+Lls7/66uyPWpIWN74ONvIFBCjgIyJacaSQQded5Jmuqe9arTnV5KFj6E X-Received: by 10.98.245.156 with SMTP id b28mr10032737pfm.90.1521801075860; Fri, 23 Mar 2018 03:31:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521801075; cv=none; d=google.com; s=arc-20160816; b=VYHT2T4IalhY3wwRAUeR0GXK2Y3hSo28XZMhB4Fq/qTjHdSmHg/pZ95ba1cw5WwWKq 12HWzGPn6/fWK+iWNgNYSy2mH/CgsDBW1nZEiJnjrRKn5ZEm99oljxvpmd+dBwI53/8W fJtHw9E8JiX6hwhWtNGPrelYa3MFG5J/jc5e23qgezRf/7E8yCc/3HuH2pZjTG4FPu3w uBubD0SahB2lEuyxmMhn7QFOmmWvDEZUklXyzM477FH4iJfNBNv1A/zrLnCXLLyrmcsz HLzK59Zly30c0HCRlyqKrkEwpFcwaQq917ogfJf/YeaXYt/rdqLv1ilMlq8ASN1NJjm7 Q16Q== 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=XD1g6vSnYvnj1tulIIB+ZU0tpbwTqrguHTwYm6nzg00=; b=RmHAmBfRxiB7x+Z7RKXyQPDBWsoTXf6crRFBx8uEBGsuyTAC26Gs0dXwe1a0JHKcKK MsuRSwyePJ2CYa8L3Ap0RQ//qG12CsvubHS2rRi2rc4uQVmHJxH9M/AU7RcQS4gadBrC wBEYZKw2UwoppHuoG2VT7tdzXUXc7+sxvwjHfNolxFB9US5dy27grsyVr1KIZQxjDRt1 oOlz0j29jyftusQ7C8MbgHE2W/BTwCJ8Zgkb19CegDsvtJd2fLhsaWEdj+JUOJDKHHCV YQlI/2ukxV/HZgNZBLfnYWXEm+8TxhwTsIWfxXsq1X9+Vh+TGYnZvtmaLWNTyrJJUbtS 1dcg== 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 m185si6523995pfc.361.2018.03.23.03.31.01; Fri, 23 Mar 2018 03:31:15 -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 S1756257AbeCWK3D (ORCPT + 99 others); Fri, 23 Mar 2018 06:29:03 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:47988 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933957AbeCWKTN (ORCPT ); Fri, 23 Mar 2018 06:19:13 -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 E445AF53; Fri, 23 Mar 2018 10:19:12 +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 3.18 23/47] scsi: mac_esp: Replace bogus memory barrier with spinlock Date: Fri, 23 Mar 2018 10:55:14 +0100 Message-Id: <20180323094249.111998633@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180323094248.117679641@linuxfoundation.org> References: <20180323094248.117679641@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 3.18-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);