Thread (6 messages) 6 messages, 3 authors, 2012-04-24

Re: [EDAC ABI v13 24/25] edac: change the mem allocation scheme to make Documentation/kobject.txt happy

From: Joe Perches <joe@perches.com>
Date: 2012-04-18 17:17:49
Also in: lkml

On Mon, 2012-04-16 at 17:38 -0300, Mauro Carvalho Chehab wrote:
Kernel kobjects have rigid rules: each container object should be
dynamically allocated, and can't be allocated into a single kmalloc.

EDAC never obeyed this rule: it has a single malloc function that
allocates all needed data into a single kzalloc.

As this is not accepted anymore, change the allocation schema of the
EDAC *_info structs to enforce this Kernel standard.
[]
quoted hunk ↗ jump to hunk
diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
[]
quoted hunk ↗ jump to hunk
@@ -2228,9 +2228,9 @@ static int init_csrows(struct mem_ctl_info *mci)
 			edac_mode = EDAC_NONE;
 
 		for (j = 0; j < pvt->channel_count; j++) {
-			csrow->channels[j].dimm->mtype = mtype;
-			csrow->channels[j].dimm->edac_mode = edac_mode;
-			csrow->channels[j].dimm->nr_pages = nr_pages;
+			csrow->channels[j]->dimm->mtype = mtype;
+			csrow->channels[j]->dimm->edac_mode = edac_mode;
+			csrow->channels[j]->dimm->nr_pages = nr_pages;
It might be better to use an automatic for
	typeof foo dimm = csrow->channels[j]->dimm;
	dimm->mtype = mtype;
	etc...
[]
quoted hunk ↗ jump to hunk
@@ -293,39 +286,56 @@ struct mem_ctl_info *edac_mc_alloc(unsigned edac_index,
 	mci->mem_is_per_rank = per_rank;
 
 	/*
-	 * Fills the csrow struct
+	 * Alocate and fill the csrow/channels structs
 	 */
+	mci->csrows = kzalloc(sizeof(*mci->csrows) * tot_csrows, GFP_KERNEL);
kcalloc

[]
+		csr->channels = kzalloc(sizeof(*csr->channels) * tot_cschannels,
+					GFP_KERNEL);
here too
quoted hunk ↗ jump to hunk
@@ -391,7 +401,31 @@ struct mem_ctl_info *edac_mc_alloc(unsigned edac_index,
 
 	trace_hw_event_init("edac", (unsigned)edac_index);
 
+	debugf1("EDAC MCI allocated\n");
 	return mci;
+
+error:
+	debugf1("Failed to allocate one or more EDAC MCI structs\n");
Generally, it's not necessary to have specific "OOM" messages
as allocations without GFP_NOWARN do dump_stack()s
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help