Skip to contentSkip to conversation

drm/amd/ras: work around write overflow attribute warning

PATCH In review Arnd Bergmann 2 participants 2 messages Mar 18

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

PATCH 1/1 drm/amd/ras: work around write overflow attribute warning

From: Arnd Bergmann <[email protected]>

clang-22 warns about possibly copying beyind the end of an array:

In file included from drivers/gpu/drm/amd/amdgpu/../ras/rascore/ras_umc.c:24:
In file included from drivers/gpu/drm/amd/amdgpu/../ras/rascore/ras.h:27:
In file included from drivers/gpu/drm/amd/amdgpu/../ras/ras_mgr/ras_sys.h:29:
In file included from include/linux/string.h:386:
include/linux/fortify-string.h:569:4: error: call to '__write_overflow_field' declared with 'warning' attribute: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror,-Wattribute-warning]

  569 |                         __write_overflow_field(p_size_field, size);
      |                         ^

As far as I can tell, this is a false-postive warning, but there is an easy workaround, by using a direct struct assignment in place of the memcpy.

Fixes 7a3f9c0992c4 ("drm/amd/ras: Add umc common ras functions")
---
 drivers/gpu/drm/amd/ras/rascore/ras_umc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/ras/rascore/ras_umc.c +1 -1
index 23118f41eb96..fb426386b384 100644
@@ -290,7 +290,7 @@ static int ras_umc_get_new_records(struct ras_core_context *ras_core,
 		if (!entries[i])
 			continue;
 
-		memcpy(&records[i], entries[i], sizeof(struct eeprom_umc_record));
+		records[i] = *entries[i];
 		count++;
 		radix_tree_tag_clear(&ras_umc->root,
 				entries[i]->cur_nps_retired_row_pfn, UMC_ECC_NEW_DETECTED_TAG);
Signature · 1 line
2.39.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

clang-22 warns about possibly copying beyind the end of an array:

In file included from drivers/gpu/drm/amd/amdgpu/../ras/rascore/ras_umc.c:24:
In file included from drivers/gpu/drm/amd/amdgpu/../ras/rascore/ras.h:27:
In file included from drivers/gpu/drm/amd/amdgpu/../ras/ras_mgr/ras_sys.h:29:
In file included from include/linux/string.h:386:
include/linux/fortify-string.h:569:4: error: call to '__write_overflow_field' declared with 'warning' attribute: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror,-Wattribute-warning]

  569 |                         __write_overflow_field(p_size_field, size);
      |                         ^
Quoted 6 lines

As far as I can tell, this is a false-postive warning, but there is an easy workaround, by using a direct struct assignment in place of the memcpy.

Fixes 7a3f9c0992c4 ("drm/amd/ras: Add umc common ras functions")

Yeah, direct assignment is much preferred anyway. :)

Signature · 1 line
Kees Cook