diff mbox series

mic: avoid statically declaring a 'struct device'.

Message ID 20190710130703.1857586-1-arnd@arndb.de
State New
Headers show
Series mic: avoid statically declaring a 'struct device'. | expand

Commit Message

Arnd Bergmann July 10, 2019, 1:06 p.m. UTC
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 from
a platform_device_info. This avoids the warning and some other problems,
but is still not ideal because the device creation should really be
separated from the driver.

Fixes: dd8d8d44df64 ("misc: mic: MIC card driver specific changes to enable SCIF")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>

---
 drivers/misc/mic/card/mic_x100.c | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

-- 
2.20.0

Comments

Arnd Bergmann July 10, 2019, 3:43 p.m. UTC | #1
On Wed, Jul 10, 2019 at 3:07 PM Arnd Bergmann <arnd@arndb.de> wrote:

> A slightly better way here is to create the platform device from

> a platform_device_info. This avoids the warning and some other problems,

> but is still not ideal because the device creation should really be

> separated from the driver.

>

> Fixes: dd8d8d44df64 ("misc: mic: MIC card driver specific changes to enable SCIF")

> Signed-off-by: Arnd Bergmann <arnd@arndb.de>


Please ignore this version, it is completely broken, I'll send a
replacement after
more build testing.

       Arnd
diff mbox series

Patch

diff --git a/drivers/misc/mic/card/mic_x100.c b/drivers/misc/mic/card/mic_x100.c
index 266ffb6f6c44..a5821166f943 100644
--- a/drivers/misc/mic/card/mic_x100.c
+++ b/drivers/misc/mic/card/mic_x100.c
@@ -282,18 +282,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,
@@ -307,6 +295,12 @@  static int __init mic_init(void)
 {
 	int ret;
 	struct cpuinfo_x86 *c = &cpu_data(0);
+	struct platform_device_info mic_platform_info = {
+		.name = mic_driver_name,
+		.dma_mask = DMA_BIT_MASK(64),
+	};
+	struct platform_device *pdev;
+
 
 	if (!(c->x86 == 11 && c->x86_model == 1)) {
 		ret = -ENODEV;
@@ -316,9 +310,11 @@  static int __init mic_init(void)
 
 	request_module("mic_x100_dma");
 	mic_init_card_debugfs();
-	ret = platform_device_register(&mic_platform_dev);
+
+	pdev = platform_device_register_full(&mic_platform_info);
+	ret = PTR_ERR_OR_ZERO(pdev);
 	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);