Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp870077ybl; Fri, 24 Jan 2020 11:03:18 -0800 (PST) X-Google-Smtp-Source: APXvYqx8FjsN2gG563ud+oFEg6+EkvkBU2D3jqx1W+7d9HC39yhCfRJnveXWQmbz/r3uyF9UzgTS X-Received: by 2002:aca:c08b:: with SMTP id q133mr201832oif.46.1579892598244; Fri, 24 Jan 2020 11:03:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579892598; cv=none; d=google.com; s=arc-20160816; b=vm89YYvALur5vGP7tJTPKCU/6SP8d4BKoWXWEA53MnAMg3ftBC5vCiu5diPmoBENTh jPLV/FTcJvpLchv0iQfYWB46siDUhPAYwb1stw5CKbixxLjVyZLAgvh9A1xcmn6cDM5N c/IMCkqN4xmdX/l+AnTStHv7t8FfAH34xiJwfCIAX36Sw+MU4IBnrc/+zNAkO62OtWbj kIAToulBKB8p4FzBvykM0+zrfolTB9y0rpGrFXnw5O5mnWZR4KHOzfoWVuyVUls++R7p DWlXdUL4QqthbNji9IMCR9h6fkXGGy/2ejRdPZT69MlPpYFwlR6Y1MEwLvnVRPLD0mdy Qdnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dw0u59HgS4vBxhtY/W5l3uNy+vg7xccm559sF+IcADw=; b=UseeKwfgvSH72E3andrTCOTDI2NQioVygy/gqObIC+O+tbZXH2SLWHCgNsan9/P5PZ qceKT6LAo147Kw1+Vn66HMAzuYZdPo137WhfqZHPHiSJG/UE0rjeSOhiCXiInBn70QIx 5wS3oBSecHNboYaS1HszvKMw4ZLzs3RcOgHzBPbaT2XcdnTvtNzTFQ/ZqzD3QrEEZmsz faXXMLqh3WQ/Q/zgaztP86wsGmOzvZbR0Nnw+biIV+cf5+sYvOGBFuTnUVowlXr8s8Oc O28tJK9qnR9k8bZHM24Pk4P3d9oOeTp5s6PNAmgd0nhg+ERVVXHKuEYB5/nSV4DTelWM Unaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=O+rhuEaa; 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 c10si3113979otr.88.2020.01.24.11.03.06; Fri, 24 Jan 2020 11:03:18 -0800 (PST) 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=@kernel.org header.s=default header.b=O+rhuEaa; 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 S2391627AbgAXL1J (ORCPT + 99 others); Fri, 24 Jan 2020 06:27:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:42320 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388367AbgAXL1E (ORCPT ); Fri, 24 Jan 2020 06:27:04 -0500 Received: from localhost (ip-213-127-102-57.ip.prioritytelecom.net [213.127.102.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B84B920718; Fri, 24 Jan 2020 11:27:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579865223; bh=IwRh4MwwKbEAJczjkT6p7Y8EFA00nRALELVHg28Gjt8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O+rhuEaaJHSugA+wgu+JzT+yAkVUho6aQe7EBUq2c32Gvlh614T0g9NP8ybDe/Tld X+4usQlWmjU9yIZIKwQfZ0XzjGVmfEKN9NTIicnw9ENbYUSK+izjJACbiTnCjY9a0y WuVlI5jyNR1r/obdG8eSI5BKKP91I0RKlf5GL9ko= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arnd Bergmann , Sasha Levin Subject: [PATCH 4.19 487/639] mic: avoid statically declaring a struct device. Date: Fri, 24 Jan 2020 10:30:57 +0100 Message-Id: <20200124093149.727225270@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200124093047.008739095@linuxfoundation.org> References: <20200124093047.008739095@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnd Bergmann [ Upstream commit bc83f79bd2119230888fb8574639d5a51b38f903 ] Generally, declaring a platform device as a static variable is a bad idea and can cause all kinds of problems, in particular with the DMA configuration and lifetime rules. A specific problem we hit here is from a bug in clang that warns about certain (otherwise valid) macros when used in static variables: drivers/misc/mic/card/mic_x100.c:285:27: warning: shift count >= width of type [-Wshift-count-overflow] static u64 mic_dma_mask = DMA_BIT_MASK(64); ^~~~~~~~~~~~~~~~ include/linux/dma-mapping.h:141:54: note: expanded from macro 'DMA_BIT_MASK' #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1)) ^ ~~~ A slightly better way here is to create the platform device dynamically and set the dma mask in the probe function. This avoids the warning and some other problems, but is still not ideal because the device creation should really be separated from the driver, and the fact that the device has no parent means we have to force the dma mask rather than having it set up from the bus that the device is actually on. Fixes: dd8d8d44df64 ("misc: mic: MIC card driver specific changes to enable SCIF") Signed-off-by: Arnd Bergmann Link: https://lore.kernel.org/r/20190712092426.872625-1-arnd@arndb.de Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/misc/mic/card/mic_x100.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/drivers/misc/mic/card/mic_x100.c b/drivers/misc/mic/card/mic_x100.c index b9f0710ffa6b0..4007adc666f37 100644 --- a/drivers/misc/mic/card/mic_x100.c +++ b/drivers/misc/mic/card/mic_x100.c @@ -249,6 +249,9 @@ static int __init mic_probe(struct platform_device *pdev) mdrv->dev = &pdev->dev; snprintf(mdrv->name, sizeof(mic_driver_name), mic_driver_name); + /* FIXME: use dma_set_mask_and_coherent() and check result */ + dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); + mdev->mmio.pa = MIC_X100_MMIO_BASE; mdev->mmio.len = MIC_X100_MMIO_LEN; mdev->mmio.va = devm_ioremap(&pdev->dev, MIC_X100_MMIO_BASE, @@ -294,18 +297,6 @@ static void mic_platform_shutdown(struct platform_device *pdev) mic_remove(pdev); } -static u64 mic_dma_mask = DMA_BIT_MASK(64); - -static struct platform_device mic_platform_dev = { - .name = mic_driver_name, - .id = 0, - .num_resources = 0, - .dev = { - .dma_mask = &mic_dma_mask, - .coherent_dma_mask = DMA_BIT_MASK(64), - }, -}; - static struct platform_driver __refdata mic_platform_driver = { .probe = mic_probe, .remove = mic_remove, @@ -315,6 +306,8 @@ static struct platform_driver __refdata mic_platform_driver = { }, }; +static struct platform_device *mic_platform_dev; + static int __init mic_init(void) { int ret; @@ -328,9 +321,12 @@ static int __init mic_init(void) request_module("mic_x100_dma"); mic_init_card_debugfs(); - ret = platform_device_register(&mic_platform_dev); + + mic_platform_dev = platform_device_register_simple(mic_driver_name, + 0, NULL, 0); + ret = PTR_ERR_OR_ZERO(mic_platform_dev); if (ret) { - pr_err("platform_device_register ret %d\n", ret); + pr_err("platform_device_register_full ret %d\n", ret); goto cleanup_debugfs; } ret = platform_driver_register(&mic_platform_driver); @@ -341,7 +337,7 @@ static int __init mic_init(void) return ret; device_unregister: - platform_device_unregister(&mic_platform_dev); + platform_device_unregister(mic_platform_dev); cleanup_debugfs: mic_exit_card_debugfs(); done: @@ -351,7 +347,7 @@ done: static void __exit mic_exit(void) { platform_driver_unregister(&mic_platform_driver); - platform_device_unregister(&mic_platform_dev); + platform_device_unregister(mic_platform_dev); mic_exit_card_debugfs(); } -- 2.20.1