linux/drivers/edac
Borislav Petkov (AMD) 51520e03e7 EDAC/mc: Fix error path ordering in edac_mc_alloc()
When the mci->pvt_info allocation in edac_mc_alloc() fails, the error path
will call put_device() which will end up calling the device's release
function.

However, the init ordering is wrong such that device_initialize() happens
*after* the failed allocation and thus the device itself and the release
function pointer are not initialized yet when they're called:

  MCE: In-kernel MCE decoding enabled.
  ------------[ cut here ]------------
  kobject: '(null)': is not initialized, yet kobject_put() is being called.
  WARNING: lib/kobject.c:734 at kobject_put, CPU#22: systemd-udevd
  CPU: 22 UID: 0 PID: 538 Comm: systemd-udevd Not tainted 7.0.0-rc1+ #2 PREEMPT(full)
  RIP: 0010:kobject_put
  Call Trace:
   <TASK>
   edac_mc_alloc+0xbe/0xe0 [edac_core]
   amd64_edac_init+0x7a4/0xff0 [amd64_edac]
   ? __pfx_amd64_edac_init+0x10/0x10 [amd64_edac]
   do_one_initcall
   ...

Reorder the calling sequence so that the device is initialized and thus the
release function pointer is properly set before it can be used.

This was found by Claude while reviewing another EDAC patch.

Fixes: 0bbb265f70 ("EDAC/mc: Get rid of silly one-shot struct allocation in edac_mc_alloc()")
Reported-by: Claude Code:claude-opus-4.5
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Qiuxu Zhuo <qiuxu.zhuo@intel.com>
Cc: stable@kernel.org
Link: https://patch.msgid.link/20260331121623.4871-1-bp@kernel.org
2026-04-05 17:49:19 +02:00
..
a72_edac.c EDAC: Add EDAC driver for ARM Cortex A72 cores 2025-08-15 23:37:00 +02:00
al_mc_edac.c EDAC/al_mc: Make use of the helper function devm_add_action_or_reset() 2021-09-28 18:35:11 +02:00
altera_edac.c EDAC/altera: Remove IRQF_ONESHOT 2026-02-01 17:37:15 +01:00
altera_edac.h EDAC/altera: Set DDR and SDMMC interrupt mask before registration 2025-04-28 12:38:53 +02:00
amd64_edac.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
amd64_edac.h EDAC/amd64: Remove NUM_CONTROLLERS macro 2025-11-06 12:51:33 +01:00
amd76x_edac.c EDAC: Do not issue useless debug statements in the polling routine 2020-10-26 12:59:56 +01:00
armada_xp_edac.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
aspeed_edac.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
bluefield_edac.c EDAC/bluefield: Don't use bluefield_edac_readl() result on error 2025-05-22 17:58:28 +02:00
cpc925_edac.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
debugfs.c EDAC: Use string choice helper functions 2025-02-25 22:19:55 +01:00
dmc520_edac.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
e7xxx_edac.c EDAC: Sanitize MODULE_AUTHOR strings 2023-03-28 15:43:30 +02:00
e752x_edac.c EDAC: Sanitize MODULE_AUTHOR strings 2023-03-28 15:43:30 +02:00
ecs.c EDAC: Fix wrong executable file modes for C source files 2025-08-30 17:23:06 +02:00
edac_device_sysfs.c EDAC/device: Remove edac_dev_sysfs_block_attribute::store() 2024-03-27 18:26:57 +01:00
edac_device.c Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses 2026-02-22 08:26:33 -08:00
edac_device.h EDAC: Remove unused struct members 2024-03-27 18:26:58 +01:00
edac_mc_sysfs.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
edac_mc.c EDAC/mc: Fix error path ordering in edac_mc_alloc() 2026-04-05 17:49:19 +02:00
edac_mc.h EDAC/mc: Determine mci pointer from the error descriptor 2020-02-17 13:05:10 +01:00
edac_module.c EDAC: constantify the struct bus_type usage 2024-01-04 14:34:27 +01:00
edac_module.h EDAC/device: Fix period calculation in edac_device_reset_delay_period() 2022-12-30 15:51:41 +01:00
edac_pci_sysfs.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
edac_pci.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
edac_pci.h EDAC: Remove unused struct members 2024-03-27 18:26:58 +01:00
fsl_ddr_edac.c EDAC/fsl_ddr: Add support for i.MX9 DDR controller 2024-10-23 16:53:55 +02:00
fsl_ddr_edac.h EDAC/fsl_ddr: Add support for i.MX9 DDR controller 2024-10-23 16:53:55 +02:00
ghes_edac.c EDAC/ghes: Replace deprecated strcpy() in ghes_edac_report_mem_error() 2025-11-18 16:50:32 +01:00
highbank_l2_edac.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
highbank_mc_edac.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
i7core_edac.c Convert more 'alloc_obj' cases to default GFP_KERNEL arguments 2026-02-21 20:03:00 -08:00
i10nm_base.c EDAC/{skx_common,skx,i10nm}: Make skx_register_mci() independent of pci_dev 2025-11-19 12:11:40 -08:00
i3000_edac.c EDAC: Do not issue useless debug statements in the polling routine 2020-10-26 12:59:56 +01:00
i3200_edac.c EDAC/i3200: Fix a resource leak in i3200_probe1() 2026-01-04 08:31:44 +01:00
i5000_edac.c EDAC/i5000: Fix snprintf() size calculation in calculate_dimm_size() 2025-12-17 09:59:17 -08:00
i5100_edac.c EDAC: Sanitize MODULE_AUTHOR strings 2023-03-28 15:43:30 +02:00
i5400_edac.c EDAC/i5400: Fix snprintf() limit calculation in calculate_dimm_size() 2025-12-17 10:00:20 -08:00
i7300_edac.c EDAC: Use string choice helper functions 2025-02-25 22:19:55 +01:00
i82860_edac.c EDAC: Sanitize MODULE_AUTHOR strings 2023-03-28 15:43:30 +02:00
i82875p_edac.c EDAC: Do not issue useless debug statements in the polling routine 2020-10-26 12:59:56 +01:00
i82975x_edac.c EDAC: Do not issue useless debug statements in the polling routine 2020-10-26 12:59:56 +01:00
ie31200_edac.c bitmap updates for v6.19 2025-12-06 09:01:27 -08:00
igen6_edac.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
imh_base.c Convert 'alloc_flex' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
Kconfig EDAC/r82600: Remove this obsolete driver 2026-01-30 13:41:32 +01:00
layerscape_edac.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
loongson_edac.c EDAC: Add an EDAC driver for the Loongson memory controller 2025-01-04 12:02:04 +01:00
Makefile EDAC/r82600: Remove this obsolete driver 2026-01-30 13:41:32 +01:00
mce_amd.c x86/msr: Add explicit includes of <asm/msr.h> 2025-05-02 10:23:47 +02:00
mce_amd.h x86/mce/amd, edac: Remove report_gart_errors 2020-04-14 15:53:46 +02:00
mem_repair.c EDAC: Fix wrong executable file modes for C source files 2025-08-30 17:23:06 +02:00
mpc85xx_edac.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
mpc85xx_edac.h treewide: Replace GPLv2 boilerplate/reference with SPDX - gpl-2.0_56.RULE (part 2) 2022-06-10 14:51:35 +02:00
npcm_edac.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
octeon_edac-l2c.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
octeon_edac-lmc.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
octeon_edac-pc.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
octeon_edac-pci.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
pasemi_edac.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 333 2019-06-05 17:37:06 +02:00
pnd2_edac.c EDAC/pnd2: Make read-only const array intlv static 2025-03-03 16:39:26 +01:00
pnd2_edac.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 288 2019-06-05 17:36:37 +02:00
qcom_edac.c EDAC/qcom: Correct interrupt enable register configuration 2025-02-14 20:36:11 +01:00
sb_edac.c Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses 2026-02-22 08:26:33 -08:00
scrub.c EDAC: Fix wrong executable file modes for C source files 2025-08-30 17:23:06 +02:00
sifive_edac.c EDAC: Remove dynamic attributes from edac_device_alloc_ctl_info() 2024-03-27 18:26:58 +01:00
skx_base.c EDAC/{skx_common,skx,i10nm}: Make skx_register_mci() independent of pci_dev 2025-11-19 12:11:40 -08:00
skx_common.c Convert 'alloc_flex' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
skx_common.h EDAC/{skx_comm,imh}: Detect 2-level memory configuration 2025-11-21 10:20:51 -08:00
synopsys_edac.c EDAC/synopsys: Clear the ECC counters on init 2025-07-14 12:15:37 +02:00
thunderx_edac.c EDAC/thunderx: Remove unused struct error_syndrome 2024-05-27 14:42:04 +02:00
ti_edac.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
versal_edac.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
versalnet_edac.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
wq.c EDAC/wq: Remove unneeded flush_workqueue() 2022-08-25 10:50:35 +02:00
x38_edac.c EDAC/x38: Fix a resource leak in x38_probe1() 2026-01-04 08:35:39 +01:00
xgene_edac.c EDAC: Use string choice helper functions 2025-02-25 22:19:55 +01:00
zynqmp_edac.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00