Skip to contentSkip to conversation

drm/amd/display: Use kcalloc() instead of kzalloc()

PATCH In review Lenko Donchev 2 participants 2 messages Jan 28, 2024 – Feb 21, 2024

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

PATCH 1/1 drm/amd/display: Use kcalloc() instead of kzalloc()

We are trying to get rid of all multiplications from allocation functions to prevent integer overflows. Here the multiplication is obviously safe, but using kcalloc() is more appropriate and improves readability. This patch has no effect on runtime behavior.

---
 drivers/gpu/drm/amd/display/dc/link/protocols/link_dpcd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/link/protocols/link_dpcd.c +1 -1
index 5c9a30211c10..b67cd78e7c58 100644
@@ -164,7 +164,7 @@ static void dpcd_extend_address_range(
 	if (new_addr_range.start != in_address || new_addr_range.end != end_address) {
 		*out_address = new_addr_range.start;
 		*out_size = ADDRESS_RANGE_SIZE(new_addr_range.start, new_addr_range.end);
-		*out_data = kzalloc(*out_size * sizeof(**out_data), GFP_KERNEL);
+		*out_data = kcalloc(*out_size, sizeof(**out_data), GFP_KERNEL);
 	}
 }
 
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 18 lines · Lenko Donchev

We are trying to get rid of all multiplications from allocation functions to prevent integer overflows. Here the multiplication is obviously safe, but using kcalloc() is more appropriate and improves readability. This patch has no effect on runtime behavior.

---
  drivers/gpu/drm/amd/display/dc/link/protocols/link_dpcd.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/link/protocols/link_dpcd.c +0 -0
index 5c9a30211c10..b67cd78e7c58 100644

drivers/gpu/drm/amd/display/dc/link/protocols/link_dpcd.c static void dpcd_extend_address_range( · line 170

Quoted 8 lines
drivers/gpu/drm/amd/display/dc/link/protocols/link_dpcd.c +1 -1
@@ -164,7 +164,7 @@ static void dpcd_extend_address_range(
  	if (new_addr_range.start != in_address || new_addr_range.end != end_address) {
  		*out_address = new_addr_range.start;
  		*out_size = ADDRESS_RANGE_SIZE(new_addr_range.start, new_addr_range.end);
-		*out_data = kzalloc(*out_size * sizeof(**out_data), GFP_KERNEL);
+		*out_data = kcalloc(*out_size, sizeof(**out_data), GFP_KERNEL);
  	}
  }
 

lgtm,