Thread (27 messages) 27 messages, 3 authors, 2015-07-23

Re: [PATCH v8 1/9] nvmem: Add a simple NVMEM framework for nvmem providers

From: Srinivas Kandagatla <hidden>
Date: 2015-07-21 18:41:06
Also in: linux-arm-kernel, linux-arm-msm, linux-devicetree, lkml


On 21/07/15 18:59, Stephen Boyd wrote:
On 07/21/2015 02:41 AM, Srinivas Kandagatla wrote:
quoted
Thanks Stephen for review,

On 20/07/15 22:11, Stephen Boyd wrote:
quoted
On 07/20/2015 07:43 AM, Srinivas Kandagatla wrote:
quoted
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
new file mode 100644
index 0000000..bde5528
--- /dev/null
+++ b/drivers/nvmem/core.c
@@ -0,0 +1,384 @@

+
+static int nvmem_add_cells(struct nvmem_device *nvmem,
+               const struct nvmem_config *cfg)
+{
+    struct nvmem_cell **cells;
+    const struct nvmem_cell_info *info = cfg->cells;
+    int i, rval;
+
+    cells = kzalloc(sizeof(*cells) * cfg->ncells, GFP_KERNEL);
kcalloc?
Only reason for using kzalloc is to give the code more flexibility to
free any pointer in the array in case of errors.
Still lost. The arrays are allocated down below in the for loop. This is
allocating a bunch of pointers so using kcalloc() here avoids problems
with overflows causing kzalloc() to allocate fewer pointers than
requested. I'm not suggesting we replace the for loop with a kcalloc,
just this single line.
Yes we could replace the loop with kcalloc, but the problem is how can 
we handle freeing an element from that array?

AFAIK we can only free the full array rather than each element if we 
allocate it via kcalloc, correct me if Am wrong?
quoted
quoted
quoted
+    if (!cells)
+        return -ENOMEM;
+
+    for (i = 0; i < cfg->ncells; i++) {
+        cells[i] = kzalloc(sizeof(**cells), GFP_KERNEL);
+        if (!cells[i]) {
+            rval = -ENOMEM;
+            goto err;
+        }
+
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help