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

fpga: bridge: properly initialize bridge device before populating children

The current code path can lead to warnings because of uninitialized device,
which contains, as a consequence, uninitialized kobject. The uninitialized
device is passed to of_platform_populate, which will at some point, while
creating child device, try to get a reference on uninitialized parent,
resulting in the following warning:

kobject: '(null)' ((ptrval)): is not initialized, yet kobject_get() is
being called.

The warning is observed after migrating a kernel 5.10.x to 6.1.x.
Reverting commit 0d70af3c2530 ("fpga: bridge: Use standard dev_release for
class driver") seems to remove the warning.
This commit aggregates device_initialize() and device_add() into
device_register() but this new call is done AFTER of_platform_populate

Fixes: 0d70af3c2530 ("fpga: bridge: Use standard dev_release for class driver")
Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20230404133102.2837535-2-alexis.lothore@bootlin.com
Signed-off-by: Xu Yilun <yilun.xu@intel.com>

authored by

Alexis Lothoré and committed by
Xu Yilun
dc70eb86 d2b727cb

+2 -1
+2 -1
drivers/fpga/fpga-bridge.c
··· 363 363 bridge->dev.parent = parent; 364 364 bridge->dev.of_node = parent->of_node; 365 365 bridge->dev.id = id; 366 - of_platform_populate(bridge->dev.of_node, NULL, NULL, &bridge->dev); 367 366 368 367 ret = dev_set_name(&bridge->dev, "br%d", id); 369 368 if (ret) ··· 373 374 put_device(&bridge->dev); 374 375 return ERR_PTR(ret); 375 376 } 377 + 378 + of_platform_populate(bridge->dev.of_node, NULL, NULL, &bridge->dev); 376 379 377 380 return bridge; 378 381