Skip to contentSkip to conversation

nvmem: u-boot-env: fix crc32 casting type

PATCH In review Rafał Miłecki 2 participants 2 messages Aug 18, 2022 – Aug 29, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvmem: u-boot-env: fix crc32 casting type

From: Rafał Miłecki <[email protected]>

This fixes:
drivers/nvmem/u-boot-env.c:141:17: sparse: sparse: cast to restricted __le32

Fixes f955dc1445069 ("nvmem: add driver handling U-Boot environment variables")
---
 drivers/nvmem/u-boot-env.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvmem/u-boot-env.c +1 -1
index 9b9abfb8f187..fb993ef4249f 100644
@@ -138,7 +138,7 @@ static int u_boot_env_parse(struct u_boot_env *priv)
 		data_offset = offsetof(struct u_boot_env_image_redundant, data);
 		break;
 	}
-	crc32 = le32_to_cpu(*(uint32_t *)(buf + crc32_offset));
+	crc32 = le32_to_cpu(*(__le32 *)(buf + crc32_offset));
 	crc32_data_len = priv->mtd->size - crc32_data_offset;
 	data_len = priv->mtd->size - data_offset;
 
Signature · 1 line
2.34.1
#1 lore raw

Hello Rafał,

Quoted 17 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

This fixes:
drivers/nvmem/u-boot-env.c:141:17: sparse: sparse: cast to restricted __le32

Fixes f955dc1445069 ("nvmem: add driver handling U-Boot environment variables")
---
 drivers/nvmem/u-boot-env.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvmem/u-boot-env.c +0 -0
index 9b9abfb8f187..fb993ef4249f 100644

drivers/nvmem/u-boot-env.c static int u_boot_env_parse(struct u_boot_env *priv) · line 141

Quoted 5 lines
drivers/nvmem/u-boot-env.c +1 -1
@@ -138,7 +138,7 @@ static int u_boot_env_parse(struct u_boot_env *priv)
 		data_offset = offsetof(struct u_boot_env_image_redundant, data);
 		break;
 	}
-	crc32 = le32_to_cpu(*(uint32_t *)(buf + crc32_offset));
+	crc32 = le32_to_cpu(*(__le32 *)(buf + crc32_offset));

I had to do a double take to make sure alignment is not violated. It's not, because crc32_offset is always zero.

How about rewriting this as

  /* CRC32 is always at offset 0 */
  crc32 = le32_to_cpup(buf);

To make the alignment clear to the reader?

drivers/nvmem/u-boot-env.c static int u_boot_env_parse(struct u_boot_env *priv) · line 144

Quoted 3 lines
drivers/nvmem/u-boot-env.c +0 -0
 	crc32_data_len = priv->mtd->size - crc32_data_offset;
 	data_len = priv->mtd->size - data_offset;
 

Cheers,
Ahmad

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |