Received: by 10.213.65.68 with SMTP id h4csp246390imn; Fri, 23 Mar 2018 03:50:51 -0700 (PDT) X-Google-Smtp-Source: AG47ELtsDbQ97Vh72pJ6ro7pjCCeAztUsxImATjnmpISVY2LkPxsp/8GMCm1brN9UnqWQC1KaH6n X-Received: by 10.101.83.136 with SMTP id x8mr20287055pgq.288.1521802251218; Fri, 23 Mar 2018 03:50:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521802251; cv=none; d=google.com; s=arc-20160816; b=SnmztleADOfLAWgy3zsQMtDNs38pxgFpxoui1j2JLJFCYEmKXRQMjek73QQWvfiq+0 p6+m1Pn7FzDE7MVsE3734VQUtlY+SjO69moAZPqm0sktsK2mKHFDCv1oguCZ8wEysHx/ Is8au3H4Rs4EFJBzwrwmzxa/FSNwxJdnN1u/d8RJTfq0qL4hvR3IC4Lzt3VqO8RkPOyM kAXGIyIKvREAtINZV6ClFHYxPSpR2/z1eI6bzfKWPpmGEXkfvE/IL/tZivMKPl1Wr4XE rt5ranNXI+QN29fTpyl3GBuvxj1IJskXfAEualacSsEibPQCTK+YEjCB74MotrEshq05 x9Fw== 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=ouMnyY8R/R/fjhXL9qWFkyToPsN9RePpfoOeguZ0VUw=; b=Oi5sY05uTUARxVVgyjsFkVEiQK5ln6NMBDsN9iLyb/P57n7yxXzQXDVY4bJXd1QaSw DcVjfzh7nCm1NyruTqzgbemKSJpKPsbP7gqtVnuzS5M7g4mihWIwkIjsggjAgztMifIo AWhdZp8MKRDldKjfrHSUMsPDjKNEeEDa6vCnadoq7n7SiOgUDm9R0X3774uxF82MtN+q xRfeh6pue00A2eXhI4widBhLOHdQOUWovJ8R7e2MvaaBmPXYpG7q7q6YZPo75fyGoy8W jBWnaxJ28orO4LsP8IP51FMLSu+GXOe5P38f7YQLJhXvr2v/NUPGPgFsSI8O8J23x8Ka FRoQ== 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 r1si6546244pfb.238.2018.03.23.03.50.36; Fri, 23 Mar 2018 03:50:51 -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 S933372AbeCWKOp (ORCPT + 99 others); Fri, 23 Mar 2018 06:14:45 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45348 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933345AbeCWKOn (ORCPT ); Fri, 23 Mar 2018 06:14:43 -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 B9EDC119C; Fri, 23 Mar 2018 10:14:42 +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.4 43/97] scsi: mac_esp: Replace bogus memory barrier with spinlock Date: Fri, 23 Mar 2018 10:54:30 +0100 Message-Id: <20180323094200.059244813@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180323094157.535925724@linuxfoundation.org> References: <20180323094157.535925724@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: 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);