drivers/edac/skx_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
From: Rui Qi <qirui.001@bytedance.com>
Use ZERO_OR_NULL_PTR instead of simple NULL check to properly handle
the case where adxl_component_count is 0, which would result in
kcalloc returning ZERO_SIZE_PTR rather than NULL.
This ensures correct error handling when no ADXL components are
present and prevents potential issues with zero-sized allocations.
Signed-off-by: Rui Qi <qirui.001@bytedance.com>
---
drivers/edac/skx_common.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/edac/skx_common.c b/drivers/edac/skx_common.c
index 39c733dbc5b9..768d787813ec 100644
--- a/drivers/edac/skx_common.c
+++ b/drivers/edac/skx_common.c
@@ -90,7 +90,7 @@ int skx_adxl_get(void)
adxl_values = kcalloc(adxl_component_count, sizeof(*adxl_values),
GFP_KERNEL);
- if (!adxl_values) {
+ if (ZERO_OR_NULL_PTR(adxl_values)) {
adxl_component_count = 0;
return -ENOMEM;
}
--
2.20.1
Hi Rui Qi, Thanks for looking at the code. > From: Rui Qi <qirui.001@bytedance.com> > [...] > Subject: [PATCH] EDAC/skx_common: Fix allocation check when > adxl_component_count is 0 > > From: Rui Qi <qirui.001@bytedance.com> > > Use ZERO_OR_NULL_PTR instead of simple NULL check to properly handle the > case where adxl_component_count is 0, which would result in kcalloc > returning ZERO_SIZE_PTR rather than NULL. > > This ensures correct error handling when no ADXL components are present > and prevents potential issues with zero-sized allocations. If the ADXL component names are empty, skx_adxl_get() will immediately jump to error handling. So, the adxl_component_count value is guaranteed to be non-zero when passed to kcalloc(). > > Signed-off-by: Rui Qi <qirui.001@bytedance.com> > [...]
On 9/19/25 8:56 PM, Zhuo, Qiuxu wrote: > Hi Rui Qi, > > Thanks for looking at the code. > >> From: Rui Qi <qirui.001@bytedance.com> >> [...] >> Subject: [PATCH] EDAC/skx_common: Fix allocation check when >> adxl_component_count is 0 >> >> From: Rui Qi <qirui.001@bytedance.com> >> >> Use ZERO_OR_NULL_PTR instead of simple NULL check to properly handle the >> case where adxl_component_count is 0, which would result in kcalloc >> returning ZERO_SIZE_PTR rather than NULL. >> >> This ensures correct error handling when no ADXL components are present >> and prevents potential issues with zero-sized allocations. > > If the ADXL component names are empty, skx_adxl_get() will immediately jump to error handling. > So, the adxl_component_count value is guaranteed to be non-zero when passed to kcalloc(). > Well, I've rechecked the code, and your statement is correct. So my modification is indeed unnecessary. >> >> Signed-off-by: Rui Qi <qirui.001@bytedance.com> >> [...]
© 2016 - 2025 Red Hat, Inc.