Skip to contentSkip to conversation

Handle maloc() failure in xen_get_nr_phys_cpus()

PATCH In review Simon Horman 2 participants 3 messages May 9, 2007 – May 10, 2007

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

PATCH 1/1 Handle maloc() failure in xen_get_nr_phys_cpus()

Currently xen_get_nr_phys_cpus() doesn't write to xen_phys_notes if allocation fails, but it doesn't return an error either, leaving xen_phys_notes wide open to be accessed by other functions later.

kexec/crashdump-xen.c +5 -6
Index: kexec-tools-unstable/kexec/crashdump-xen.c
===================================================================
@@ -93,13 +93,12 @@ int xen_get_nr_phys_cpus(void)
 	if ((cpus = kexec_iomem_for_each_line(match, NULL, NULL))) {
 		n = sizeof(struct crash_note_info) * cpus;
 		xen_phys_notes = malloc(n);
-		if (xen_phys_notes) {
-			memset(xen_phys_notes, 0, n);
-			kexec_iomem_for_each_line(match,
-						  xen_crash_note_callback,
-						  NULL);
+		if (!xen_phys_notes) {
+			fprintf(stderr, "failed to allocate xen_phys_notes.\n");
+			return -1;
 		}
-
+		memset(xen_phys_notes, 0, n);
+		kexec_iomem_for_each_line(match, xen_crash_note_callback, NULL);
 		xen_phys_cpus = cpus;
 	}
 

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Simon Horman

Currently xen_get_nr_phys_cpus() doesn't write to xen_phys_notes if allocation fails, but it doesn't return an error either, leaving xen_phys_notes wide open to be accessed by other functions later.

Looks good to me.

Quoted 14 lines

Index: kexec-tools-unstable/kexec/crashdump-xen.c
===================================================================

kexec/crashdump-xen.c +0 -5
@@ -93,13 +93,12 @@ int xen_get_nr_phys_cpus(void)
 	if ((cpus = kexec_iomem_for_each_line(match, NULL, NULL))) {
 		n = sizeof(struct crash_note_info) * cpus;
 		xen_phys_notes = malloc(n);
-		if (xen_phys_notes) {
-			memset(xen_phys_notes, 0, n);
-			kexec_iomem_for_each_line(match,
-						  xen_crash_note_callback,
-						  NULL);

kexec/crashdump-xen.c int xen_get_nr_phys_cpus(void) · line 104

Quoted 10 lines
kexec/crashdump-xen.c +5 -1
+		if (!xen_phys_notes) {
+			fprintf(stderr, "failed to allocate xen_phys_notes.\n");
+			return -1;
 		}
-
+		memset(xen_phys_notes, 0, n);
+		kexec_iomem_for_each_line(match, xen_crash_note_callback, NULL);
 		xen_phys_cpus = cpus;
 	}
 

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#2 lore raw
Quoted 10 lines · Ian Campbell
Quoted 5 lines · Simon Horman

Currently xen_get_nr_phys_cpus() doesn't write to xen_phys_notes if allocation fails, but it doesn't return an error either, leaving xen_phys_notes wide open to be accessed by other functions later.

Looks good to me.

Thanks, I've applied it now.

Signature · 9 lines
Horms
  H: http://www.vergenet.net/~horms/
  W: http://www.valinux.co.jp/en/


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec