Received: by 10.192.165.148 with SMTP id m20csp3823306imm; Mon, 7 May 2018 20:46:58 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoOcQHj57FXTIt+m50oDYBEUkR7ONHzKUYfTJ5PRLC91/TG+BML5Den/V+OOPHUnuodFRg/ X-Received: by 2002:a63:7341:: with SMTP id d1-v6mr30865253pgn.404.1525751218753; Mon, 07 May 2018 20:46:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525751218; cv=none; d=google.com; s=arc-20160816; b=dFBfCHp1NYfxWgiTQBymMOri/osrxQSzUkEXyySbtSjYxRTBvew47cLCphTJcTbnaJ U2Ildgo0BSFgkq5c43tKKTImT63/AJh4N/QndsoaZfVFUOQt7OBnzCBViCOGCkbgwIe1 d6A+u+duds7aQxWAr69cbBJkzBxXnJlUKunZyo1DkS/k/ZVf0CeKVzqchv1g+746Hc9T kGbFy1p9hYUaiYB0NmSz6rtIMdly+XzJrCdW7YjEeQaCx+eGYinKg64xiE5WBHcV01xf YC/Cf8UV7Rwwwayfm9XNqMOwASoF9ltJy+MZ/lklzc9pvPgTjYKNdgMCV1URjlme25Cl yz5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=1mosFw6MIu5/k7pj6Z/h6NGEh9//1GFf52xY7AR3kcs=; b=AlcP54Kyc2H7u5Kos+KaEm1sIAFx+WS32MBcp989jCfbz3OACH6PNjQ2zeZ7Sa4Ylo D+eyxBCnjRcgJPVqSJhPYFSe5shshr1s7CwskScKAM+e3ewb+u6LfkzIxhauyhOtS4+e QRyKD3TcMCACRHIgUFiNsDPNRnOnydOGy9dZ7aXMOzcvgPvCmh2DwwTPLP3UdIp4v6v5 gWv5u6D0zptenOiGuLgb1W/WLprDL+LVnhSB8fbqRP0g6IEL1NVyFDzx7tPWYCkbrKZH VpzHWNdsF0QCNJyCPLgtIC7qjsKqnRw+tjKTFa4fMYlEILB/hx/dALXODhBDvjCHk5X7 3M3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mjfAEl+9; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j18-v6si18534496pgn.78.2018.05.07.20.46.43; Mon, 07 May 2018 20:46:58 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mjfAEl+9; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754220AbeEHDq1 (ORCPT + 99 others); Mon, 7 May 2018 23:46:27 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:37207 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753794AbeEHDqZ (ORCPT ); Mon, 7 May 2018 23:46:25 -0400 Received: by mail-pf0-f193.google.com with SMTP id e9so19287767pfi.4; Mon, 07 May 2018 20:46:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=1mosFw6MIu5/k7pj6Z/h6NGEh9//1GFf52xY7AR3kcs=; b=mjfAEl+96d6kPhBPsIj916QhD279m1ubvreh6lYjPmesPPpEx7FfNW3vFZ5/W/0MpC 4pOs6GsJZ9lJaIWhRR6bSfVnshNkwwkZVEvJReqHGEViN5ZyoOyEnkfr3eDR6Oq8qAUE bIObLC1/C7Zv4OULudlVkmopcOAQtvd2dUI0/Rby7UDDAAtEmwHcgEOuJ/4IyhQ/eBOG 7LolW/NRpWjZRDTCpab5RwBbMny3PUT0R69CKwqtYAOZne4FgLAROXEdGIhY9qn50tO5 Ppc0s+XSG/hp8fASfMB8DB/GSG/bwyW3pcwv6TuRkCQN8PnaxkVrlEmCxGC+VyBv4if9 8MDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=1mosFw6MIu5/k7pj6Z/h6NGEh9//1GFf52xY7AR3kcs=; b=Zl/eDyAYy1E3Cu8ajRUjW15P0CqopM3A/XPFw8NvvB5FCb6VC6OoGv8qpn1hqxwkAl 2/B9TSUZnXt/JR4tln6/n0MFX2UNY0u6Gea3l8z1CTR8ihE0mdtuivh2WCoTjOwbRCWo Q2u5Jg1q5gkRUjxXiY/RHPMZCDZuaf7OORSDPPszUKAax7Ks3pCxzYcYXheC4w7yNFR3 JjY2IxArBWr4c5AzlmLak/Fd+A3TayvO8wxV2FivBim826VeDkthzt+5B1RG23J2LVLz sUYsn68j9EgcJh1KhH/A94oRIhf3WExTKb7TwCSqhjwElhxJt0kOedPcrJTBwC3FVRiw lvTw== X-Gm-Message-State: ALQs6tC/RZ8W2NaqO15jX7fwsEIdOz8EjhPv3xflewjEUVSuxKIJR51n 9wJnLcmWVQ5SwgXWBfQzBbI= X-Received: by 2002:a63:7f56:: with SMTP id p22-v6mr31615354pgn.306.1525751184744; Mon, 07 May 2018 20:46:24 -0700 (PDT) Received: from oslab.tsinghua.edu.cn ([2402:f000:1:4413:18bf:4b0b:7f52:49b]) by smtp.gmail.com with ESMTPSA id v10-v6sm34196007pgt.33.2018.05.07.20.46.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 May 2018 20:46:24 -0700 (PDT) From: Jia-Ju Bai To: tj@kernel.org Cc: linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] ata: ata_piix: Fix a possible data race in piix_pci_device_resume Date: Tue, 8 May 2018 11:46:13 +0800 Message-Id: <20180508034613.12969-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The write operation to "host->flags" is protected by the lock on line 1048, but the read operation to this data on line 1046 is not protected by the lock. Thus, there may exist a data race for "host->flags". To fix this data race, the read operation to "host->flags" should be also protected by the lock. Signed-off-by: Jia-Ju Bai --- drivers/ata/ata_piix.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c index 7ecb1322a514..c99fdf473dee 100644 --- a/drivers/ata/ata_piix.c +++ b/drivers/ata/ata_piix.c @@ -1043,8 +1043,8 @@ static int piix_pci_device_resume(struct pci_dev *pdev) unsigned long flags; int rc; + spin_lock_irqsave(&host->lock, flags); if (host->flags & PIIX_HOST_BROKEN_SUSPEND) { - spin_lock_irqsave(&host->lock, flags); host->flags &= ~PIIX_HOST_BROKEN_SUSPEND; spin_unlock_irqrestore(&host->lock, flags); @@ -1060,8 +1060,10 @@ static int piix_pci_device_resume(struct pci_dev *pdev) dev_err(&pdev->dev, "failed to enable device after resume (%d)\n", rc); - } else + } else { + spin_unlock_irqrestore(&host->lock, flags); rc = ata_pci_device_do_resume(pdev); + } if (rc == 0) ata_host_resume(host); -- 2.17.0