Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3559550pxb; Mon, 24 Jan 2022 12:12:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJwdSa6H+QiMbnx/Y+ICSG5LBqO4i4fR7/K/5mmHE3Bp492jZYiIIdcMPMeFLEmbGuiYLFjM X-Received: by 2002:a17:903:2342:b0:14b:6f25:4b5f with SMTP id c2-20020a170903234200b0014b6f254b5fmr910720plh.14.1643055174548; Mon, 24 Jan 2022 12:12:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643055174; cv=none; d=google.com; s=arc-20160816; b=ToPnxTAtNiEy6Sd+wkwQIBvC16nztJ0eLLls0uFfdSeHtgzkObw/cBfQLDJP2U+o4v DR7C91k5ru74QwOdN41ESYvoNc+u5Z9xA+3Nvi9wZNAYNj+sRNcrqgQEdlpr323zCKUz R1Mis++6ke1puk/ninE50yCILPV+er7VHrgIIuKkZBwG9MHqs7h28ZMwoQM4Y26EKNIp Rn5Axfm+zABOdXPelO4gKoPbGPKcVsvU8/yGXhCFNjOf77BlrTEyquT+5xkxKSkTaneM deYzRVgZ5nNVyZCaBMYBE0BJvSB4ggzFvxwNkOoEJ0WMnilvXD1coYFXb7Z69AlazytE w2DQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=L6tFXTniupeFZhjF5MCSN5x6PSqgpTsFuujSgsWtXuw=; b=XMYrzQNrt3Uc3f1EHvdK9DC5GHQ50xT7unmF9Ukz3lWRG0GgTL8pwz2WgX0z5/UUOO sMC22t7H9AuaEl/kM8mc7f9XGDHTtC750pVfIrWWOXlEOtktR9JtTGIu3B6jgpfHDp8W L6HAU9vid9u6+HX8sLGaALf6JyUDsDxeZPLqh0gRGZ4KOytxEQfxyTkfEPmNIZ2TWwoO 8h3LlPC52KWls2RNm5D/2LquDegLvI3HoOtArFgmrTn2IVG/vfNg4QlIzENaWIE6mJkf xEJdM6ixPzuPNX0nxDC7qAo6iuP1LGLBnq7gdtz4xanpIpuMY/UpGufLWxiUL/X/LEvk rd3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0nvIP9mT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qe2si317305pjb.37.2022.01.24.12.12.41; Mon, 24 Jan 2022 12:12:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0nvIP9mT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237448AbiAXTPo (ORCPT + 99 others); Mon, 24 Jan 2022 14:15:44 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:37860 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344560AbiAXTH7 (ORCPT ); Mon, 24 Jan 2022 14:07:59 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A60EC611ED; Mon, 24 Jan 2022 19:07:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71E80C340E7; Mon, 24 Jan 2022 19:07:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643051277; bh=NmMex1hUSvPxt8t3CgZsrJCcWmi1yWg90e+EwbPuPPs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0nvIP9mTfwSRlCO/fZl6V5Rqg1K0Kd4UDW1JVadQf1BGpkAZ3Cm8qoF5hkBQTP5Gc JH6uDYUkkQd+8KtzAyCbhQuZcFfAzzyxAIyNEgtpLJBD7VlRlLrsC/s8xMIc07kQLE lMXJJcXScZ6C+uO6bUE6Bj775QtieYVM8eb9RX4I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexey Dobriyan , Bean Huo , Bart Van Assche , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.14 077/186] scsi: ufs: Fix race conditions related to driver data Date: Mon, 24 Jan 2022 19:42:32 +0100 Message-Id: <20220124183939.599917695@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183937.101330125@linuxfoundation.org> References: <20220124183937.101330125@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bart Van Assche [ Upstream commit 21ad0e49085deb22c094f91f9da57319a97188e4 ] The driver data pointer must be set before any callbacks are registered that use that pointer. Hence move the initialization of that pointer from after the ufshcd_init() call to inside ufshcd_init(). Link: https://lore.kernel.org/r/20211203231950.193369-7-bvanassche@acm.org Fixes: 3b1d05807a9a ("[SCSI] ufs: Segregate PCI Specific Code") Reported-by: Alexey Dobriyan Tested-by: Bean Huo Reviewed-by: Bean Huo Signed-off-by: Bart Van Assche Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/ufs/tc-dwc-g210-pci.c | 1 - drivers/scsi/ufs/ufshcd-pltfrm.c | 2 -- drivers/scsi/ufs/ufshcd.c | 7 +++++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/ufs/tc-dwc-g210-pci.c b/drivers/scsi/ufs/tc-dwc-g210-pci.c index 325d5e14fc0d8..a8b50fc1960d1 100644 --- a/drivers/scsi/ufs/tc-dwc-g210-pci.c +++ b/drivers/scsi/ufs/tc-dwc-g210-pci.c @@ -138,7 +138,6 @@ tc_dwc_g210_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) return err; } - pci_set_drvdata(pdev, hba); pm_runtime_put_noidle(&pdev->dev); pm_runtime_allow(&pdev->dev); diff --git a/drivers/scsi/ufs/ufshcd-pltfrm.c b/drivers/scsi/ufs/ufshcd-pltfrm.c index 8992354d4e2c7..6f076ff35dd38 100644 --- a/drivers/scsi/ufs/ufshcd-pltfrm.c +++ b/drivers/scsi/ufs/ufshcd-pltfrm.c @@ -348,8 +348,6 @@ int ufshcd_pltfrm_init(struct platform_device *pdev, goto dealloc_host; } - platform_set_drvdata(pdev, hba); - pm_runtime_set_active(&pdev->dev); pm_runtime_enable(&pdev->dev); diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index f46fa8a2f6585..694c0fc31fbf7 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -7904,6 +7904,13 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) struct Scsi_Host *host = hba->host; struct device *dev = hba->dev; + /* + * dev_set_drvdata() must be called before any callbacks are registered + * that use dev_get_drvdata() (frequency scaling, clock scaling, hwmon, + * sysfs). + */ + dev_set_drvdata(dev, hba); + if (!mmio_base) { dev_err(hba->dev, "Invalid memory reference for mmio_base is NULL\n"); -- 2.34.1