Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mic: avoid statically declaring a 'struct device'.

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 <arnd@arndb.de>
Link: https://lore.kernel.org/r/20190712092426.872625-1-arnd@arndb.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Arnd Bergmann and committed by
Greg Kroah-Hartman
bc83f79b dcfecd4d

+12 -16
+12 -16
drivers/misc/mic/card/mic_x100.c
··· 237 237 mdrv->dev = &pdev->dev; 238 238 snprintf(mdrv->name, sizeof(mic_driver_name), mic_driver_name); 239 239 240 + /* FIXME: use dma_set_mask_and_coherent() and check result */ 241 + dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); 242 + 240 243 mdev->mmio.pa = MIC_X100_MMIO_BASE; 241 244 mdev->mmio.len = MIC_X100_MMIO_LEN; 242 245 mdev->mmio.va = devm_ioremap(&pdev->dev, MIC_X100_MMIO_BASE, ··· 285 282 mic_remove(pdev); 286 283 } 287 284 288 - static u64 mic_dma_mask = DMA_BIT_MASK(64); 289 - 290 - static struct platform_device mic_platform_dev = { 291 - .name = mic_driver_name, 292 - .id = 0, 293 - .num_resources = 0, 294 - .dev = { 295 - .dma_mask = &mic_dma_mask, 296 - .coherent_dma_mask = DMA_BIT_MASK(64), 297 - }, 298 - }; 299 - 300 285 static struct platform_driver __refdata mic_platform_driver = { 301 286 .probe = mic_probe, 302 287 .remove = mic_remove, ··· 293 302 .name = mic_driver_name, 294 303 }, 295 304 }; 305 + 306 + static struct platform_device *mic_platform_dev; 296 307 297 308 static int __init mic_init(void) 298 309 { ··· 309 316 310 317 request_module("mic_x100_dma"); 311 318 mic_init_card_debugfs(); 312 - ret = platform_device_register(&mic_platform_dev); 319 + 320 + mic_platform_dev = platform_device_register_simple(mic_driver_name, 321 + 0, NULL, 0); 322 + ret = PTR_ERR_OR_ZERO(mic_platform_dev); 313 323 if (ret) { 314 - pr_err("platform_device_register ret %d\n", ret); 324 + pr_err("platform_device_register_full ret %d\n", ret); 315 325 goto cleanup_debugfs; 316 326 } 317 327 ret = platform_driver_register(&mic_platform_driver); ··· 325 329 return ret; 326 330 327 331 device_unregister: 328 - platform_device_unregister(&mic_platform_dev); 332 + platform_device_unregister(mic_platform_dev); 329 333 cleanup_debugfs: 330 334 mic_exit_card_debugfs(); 331 335 done: ··· 335 339 static void __exit mic_exit(void) 336 340 { 337 341 platform_driver_unregister(&mic_platform_driver); 338 - platform_device_unregister(&mic_platform_dev); 342 + platform_device_unregister(mic_platform_dev); 339 343 mic_exit_card_debugfs(); 340 344 } 341 345