[PATCH] PCI: acpiphp_ibm: Using kmemdup() to simplify code
From: Liao Yuanhong
Date: Mon Aug 11 2025 - 04:23:48 EST
Use kmemdup() to replace the original code's allocate-and-copy operations.
It enhances code readability and simplifies nested conditionals.
Signed-off-by: Liao Yuanhong <liaoyuanhong@xxxxxxxx>
---
drivers/pci/hotplug/acpiphp_ibm.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
index 18e01cd55a8e..6a16c8e8238f 100644
--- a/drivers/pci/hotplug/acpiphp_ibm.c
+++ b/drivers/pci/hotplug/acpiphp_ibm.c
@@ -140,11 +140,8 @@ static union apci_descriptor *ibm_slot_from_id(int id)
ret = des;
ibm_slot_done:
- if (ret) {
- ret = kmalloc(sizeof(union apci_descriptor), GFP_KERNEL);
- if (ret)
- memcpy(ret, des, sizeof(union apci_descriptor));
- }
+ if (ret)
+ ret = kmemdup(des, sizeof(union apci_descriptor), GFP_KERNEL);
kfree(table);
return ret;
}
--
2.34.1