Commit 5254ff11 authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Kleber Sacilotto de Souza

mic: avoid statically declaring a 'struct device'.

BugLink: https://bugs.launchpad.net/bugs/1864773

[ Upstream commit bc83f79b ]

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: dd8d8d44 ("misc: mic: MIC card driver specific changes to enable SCIF")
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Link: https://lore.kernel.org/r/20190712092426.872625-1-arnd@arndb.deSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent 72bcf74a
...@@ -249,6 +249,9 @@ static int __init mic_probe(struct platform_device *pdev) ...@@ -249,6 +249,9 @@ static int __init mic_probe(struct platform_device *pdev)
mdrv->dev = &pdev->dev; mdrv->dev = &pdev->dev;
snprintf(mdrv->name, sizeof(mic_driver_name), mic_driver_name); 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.pa = MIC_X100_MMIO_BASE;
mdev->mmio.len = MIC_X100_MMIO_LEN; mdev->mmio.len = MIC_X100_MMIO_LEN;
mdev->mmio.va = devm_ioremap(&pdev->dev, MIC_X100_MMIO_BASE, mdev->mmio.va = devm_ioremap(&pdev->dev, MIC_X100_MMIO_BASE,
...@@ -294,18 +297,6 @@ static void mic_platform_shutdown(struct platform_device *pdev) ...@@ -294,18 +297,6 @@ static void mic_platform_shutdown(struct platform_device *pdev)
mic_remove(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 = { static struct platform_driver __refdata mic_platform_driver = {
.probe = mic_probe, .probe = mic_probe,
.remove = mic_remove, .remove = mic_remove,
...@@ -315,6 +306,8 @@ static struct platform_driver __refdata mic_platform_driver = { ...@@ -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) static int __init mic_init(void)
{ {
int ret; int ret;
...@@ -327,9 +320,12 @@ static int __init mic_init(void) ...@@ -327,9 +320,12 @@ static int __init mic_init(void)
} }
mic_init_card_debugfs(); 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) { if (ret) {
pr_err("platform_device_register ret %d\n", ret); pr_err("platform_device_register_full ret %d\n", ret);
goto cleanup_debugfs; goto cleanup_debugfs;
} }
ret = platform_driver_register(&mic_platform_driver); ret = platform_driver_register(&mic_platform_driver);
...@@ -340,7 +336,7 @@ static int __init mic_init(void) ...@@ -340,7 +336,7 @@ static int __init mic_init(void)
return ret; return ret;
device_unregister: device_unregister:
platform_device_unregister(&mic_platform_dev); platform_device_unregister(mic_platform_dev);
cleanup_debugfs: cleanup_debugfs:
mic_exit_card_debugfs(); mic_exit_card_debugfs();
done: done:
...@@ -350,7 +346,7 @@ static int __init mic_init(void) ...@@ -350,7 +346,7 @@ static int __init mic_init(void)
static void __exit mic_exit(void) static void __exit mic_exit(void)
{ {
platform_driver_unregister(&mic_platform_driver); platform_driver_unregister(&mic_platform_driver);
platform_device_unregister(&mic_platform_dev); platform_device_unregister(mic_platform_dev);
mic_exit_card_debugfs(); mic_exit_card_debugfs();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment