Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3707311pxb; Mon, 24 Jan 2022 15:57:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJxhY3KajZ3u0mOfbys2aQPs8eaBJVGc/9mmJNUOT0rfQdEXggl97WzHQd9DpmxvN1h1H90O X-Received: by 2002:a17:902:b213:b0:14b:17c1:edbe with SMTP id t19-20020a170902b21300b0014b17c1edbemr16224953plr.173.1643068661449; Mon, 24 Jan 2022 15:57:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643068661; cv=none; d=google.com; s=arc-20160816; b=LlWPVdkw70EfxbxueuGi/eB+iaQBDr9EtXeFeMCVI4Bj/71aM00aX3TqoCcJgmtsBM kz0vjyeK6pI/+IXiirx1YA06PR2yab99lgjluaR25GLdV4xnRIfTM+O/a+cH6+e25Vkc 7tIIWTkwhEtEo5pNAOeq5f9tg4u2aYQKri74CZD3jRGC27TCJT2qNpLjiRL/Bll80kZG VcGNvM1UXXklY6oRdNdpk1+d7Dh8BOugUVxcuvPW1/cvdy/Xqg7BgvBLrbPlfIRk7865 hqd0ylPN0tUPAMxdHXXFKWQ1n6pseoJHqANvoNgi0868dMTMJXJx0iZEBrjiImlxESKi kgUg== 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=4avHu9Typ7ZnAcli6/dGYi9CusgaWyFgHOcF37oHCdI=; b=tPBQH4WHY+vJ8yztnfy/IDZgUI7L7XmcSAxBZ1KbQKekl5Xh5zpOh6ynIb8NZ5/MTI BL+tbUataWHeb+mbTG0clGRZ7xP6HVEhRos5EO4yA0h8hbglJ5PWARxOfeQ7turcCuUN GOUJyULSUOAJaEkGkNIpaB9CUegVM+c3p9ZQ07ZympALFr8t32Fmra36TEpvaFNPrZj/ o5HlL71kZpAsl08iI1Ghqu3M6AOLjb8OEnm7PrJo02qvwVtYmBFraakT1dytRshBi387 LNL8C/8Mx4fcesK8/0XsZBT/m2uqTINGy79t8uXcA1LP6Huu806IR4bh/Qo197STkPw6 sBmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SlGCljlW; 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 y21si14502655pll.115.2022.01.24.15.57.29; Mon, 24 Jan 2022 15:57:41 -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=SlGCljlW; 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 S2363107AbiAXXni (ORCPT + 99 others); Mon, 24 Jan 2022 18:43:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1845250AbiAXXLz (ORCPT ); Mon, 24 Jan 2022 18:11:55 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C823BC0A02AC; Mon, 24 Jan 2022 13:18:48 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id F13BEB80FA1; Mon, 24 Jan 2022 21:18:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2679BC340E4; Mon, 24 Jan 2022 21:18:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643059125; bh=bKvUykkz+KduKvfpk3zvPSY4ukBWhuGAf3eo5VAQFFs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SlGCljlW4yuRVYWemOk+nm9PzBJRddwjeFSryF6019W0mZBQbsEPkfMqayUDvFSHG 2D0Y0FiDC2lYc9VqzTozfxWhVtK7OKAS1ngr8MlLTpyMx5P2Cr/AUMm6MkDI3fx+g0 s/3j/wUdW79Rd/RBClw4+BCyaCppfOMhDrL3yMGM= 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 5.16 0479/1039] scsi: ufs: Fix race conditions related to driver data Date: Mon, 24 Jan 2022 19:37:48 +0100 Message-Id: <20220124184141.372234326@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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-pci.c | 2 -- drivers/scsi/ufs/ufshcd-pltfrm.c | 2 -- drivers/scsi/ufs/ufshcd.c | 7 +++++++ 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/ufs/tc-dwc-g210-pci.c b/drivers/scsi/ufs/tc-dwc-g210-pci.c index 679289e1a78e6..7b08e2e07cc5f 100644 --- a/drivers/scsi/ufs/tc-dwc-g210-pci.c +++ b/drivers/scsi/ufs/tc-dwc-g210-pci.c @@ -110,7 +110,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-pci.c b/drivers/scsi/ufs/ufshcd-pci.c index f725248ba57f4..f76692053ca17 100644 --- a/drivers/scsi/ufs/ufshcd-pci.c +++ b/drivers/scsi/ufs/ufshcd-pci.c @@ -538,8 +538,6 @@ ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) return err; } - pci_set_drvdata(pdev, hba); - hba->vops = (struct ufs_hba_variant_ops *)id->driver_data; err = ufshcd_init(hba, mmio_base, pdev->irq); diff --git a/drivers/scsi/ufs/ufshcd-pltfrm.c b/drivers/scsi/ufs/ufshcd-pltfrm.c index eaeae83b999fd..8b16bbbcb806c 100644 --- a/drivers/scsi/ufs/ufshcd-pltfrm.c +++ b/drivers/scsi/ufs/ufshcd-pltfrm.c @@ -361,8 +361,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 13c09dbd99b92..4394081806978 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -9486,6 +9486,13 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) struct device *dev = hba->dev; char eh_wq_name[sizeof("ufs_eh_wq_00")]; + /* + * 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