Skip to contentSkip to conversation

misc: fs_loader: Fix alignment of fs_loader driver

PATCH In review Sean Anderson 3 participants 3 messages Sep 30, 2023 – Oct 11, 2023 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 misc: fs_loader: Fix alignment of fs_loader driver

DM_DRIVER_GET will redeclare the fs_loader driver without the correct alignment. This causes GCC to use the default section alignment of 32 bytes. This in turn creates a gap in the linker list due to the padding required to achieve the correct alignment, corrupting all further entries. Use DM_DRIVER_REF instead, which doesn't redeclare anything.

Fixes 0998a20cfc6 ("misc: fs_loader: Add function to get the chosen loader")

---

 drivers/misc/fs_loader.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/fs_loader.c +1 -1
index ccf5c7a8037..1ffc199ba1e 100644
@@ -316,7 +316,7 @@ int get_fs_loader(struct udevice **dev)
 		return ret;
 
 	/* Just create a new device */
-	ret = device_bind(dm_root(), DM_DRIVER_GET(fs_loader), "default-loader",
+	ret = device_bind(dm_root(), DM_DRIVER_REF(fs_loader), "default-loader",
 			  &default_plat, ofnode_null(), dev);
 	if (ret)
 		return ret;
Signature · 1 line
2.37.1
#1 lore raw
Quoted 5 lines · Sean Anderson

DM_DRIVER_GET will redeclare the fs_loader driver without the correct alignment. This causes GCC to use the default section alignment of 32 bytes. This in turn creates a gap in the linker list due to the padding required to achieve the correct alignment, corrupting all further entries. Use DM_DRIVER_REF instead, which doesn't redeclare anything.

doc/api/linker_lists.rst describes this problem.

We are using DM_DRIVER_GET() a lot and DM_DRIVER_REF() rarely.

I have seen that ll_entry_get exists since 2012 when Marek introduced linker lists into U-Boot and ll_entry_ref since 2021.

In which use cases are ll_entry_get() and DM_DRIVER_GET() really needed? Or can they both be completely replaced by ll_entry_ref() and DM_DRIVER_REF().

Best regards

Heinrich

Quoted 21 lines
Fixes 0998a20cfc6 ("misc: fs_loader: Add function to get the chosen loader")

---

  drivers/misc/fs_loader.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/fs_loader.c +1 -1
index ccf5c7a8037..1ffc199ba1e 100644
@@ -316,7 +316,7 @@ int get_fs_loader(struct udevice **dev)
  		return ret;
 
  	/* Just create a new device */
-	ret = device_bind(dm_root(), DM_DRIVER_GET(fs_loader), "default-loader",
+	ret = device_bind(dm_root(), DM_DRIVER_REF(fs_loader), "default-loader",
  			  &default_plat, ofnode_null(), dev);
  	if (ret)
  		return ret;
#2 lore raw
In reply to Sean Anderson
Quoted 8 lines · Sean Anderson

DM_DRIVER_GET will redeclare the fs_loader driver without the correct alignment. This causes GCC to use the default section alignment of 32 bytes. This in turn creates a gap in the linker list due to the padding required to achieve the correct alignment, corrupting all further entries. Use DM_DRIVER_REF instead, which doesn't redeclare anything.

Fixes 0998a20cfc6 ("misc: fs_loader: Add function to get the chosen loader")

Applied to u-boot/master, thanks!

Signature · 1 line
Tom