linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mic: avoid statically declaring a 'struct device'.
@ 2019-07-10 13:06 Arnd Bergmann
  2019-07-10 15:43 ` Arnd Bergmann
  0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2019-07-10 13:06 UTC (permalink / raw)
  To: Sudeep Dutt, Ashutosh Dixit, Arnd Bergmann, Greg Kroah-Hartman
  Cc: Nikhil Rao, Alexios Zavras, linux-kernel, clang-built-linux

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(-)

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);
-- 
2.20.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mic: avoid statically declaring a 'struct device'.
  2019-07-10 13:06 [PATCH] mic: avoid statically declaring a 'struct device' Arnd Bergmann
@ 2019-07-10 15:43 ` Arnd Bergmann
  0 siblings, 0 replies; 2+ messages in thread
From: Arnd Bergmann @ 2019-07-10 15:43 UTC (permalink / raw)
  To: Sudeep Dutt, Ashutosh Dixit, Arnd Bergmann, Greg Kroah-Hartman
  Cc: Nikhil Rao, Alexios Zavras, Linux Kernel Mailing List, clang-built-linux

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-07-10 15:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-10 13:06 [PATCH] mic: avoid statically declaring a 'struct device' Arnd Bergmann
2019-07-10 15:43 ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).