Skip to content

Commit 6f754ba

Browse files
vittyvktorvalds
authored andcommitted
memory-hotplug: don't BUG() in register_memory_resource()
Out of memory condition is not a bug and while we can't add new memory in such case crashing the system seems wrong. Propagating the return value from register_memory_resource() requires interface change. Signed-off-by: Vitaly Kuznetsov <[email protected]> Reviewed-by: Igor Mammedov <[email protected]> Acked-by: David Rientjes <[email protected]> Cc: Tang Chen <[email protected]> Cc: Naoya Horiguchi <[email protected]> Cc: Xishi Qiu <[email protected]> Cc: Sheng Yong <[email protected]> Cc: Zhu Guihua <[email protected]> Cc: Dan Williams <[email protected]> Cc: David Vrabel <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 3e89e1c commit 6f754ba

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

mm/memory_hotplug.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ static struct resource *register_memory_resource(u64 start, u64 size)
131131
{
132132
struct resource *res;
133133
res = kzalloc(sizeof(struct resource), GFP_KERNEL);
134-
BUG_ON(!res);
134+
if (!res)
135+
return ERR_PTR(-ENOMEM);
135136

136137
res->name = "System RAM";
137138
res->start = start;
@@ -140,7 +141,7 @@ static struct resource *register_memory_resource(u64 start, u64 size)
140141
if (request_resource(&iomem_resource, res) < 0) {
141142
pr_debug("System RAM resource %pR cannot be added\n", res);
142143
kfree(res);
143-
res = NULL;
144+
return ERR_PTR(-EEXIST);
144145
}
145146
return res;
146147
}
@@ -1312,8 +1313,8 @@ int __ref add_memory(int nid, u64 start, u64 size)
13121313
int ret;
13131314

13141315
res = register_memory_resource(start, size);
1315-
if (!res)
1316-
return -EEXIST;
1316+
if (IS_ERR(res))
1317+
return PTR_ERR(res);
13171318

13181319
ret = add_memory_resource(nid, res);
13191320
if (ret < 0)

0 commit comments

Comments
 (0)