Skip to contentSkip to conversation

mpi/mpi-mpow: NULL dereference on allocation failure

PATCH In review Dan Carpenter 3 participants 3 messages Nov 21, 2011 Kernel janitors

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mpi/mpi-mpow: NULL dereference on allocation failure

We can't call mpi_free() on the elements if the first kzalloc() fails.

lib/mpi/mpi-mpow.c +2 -1
index 4cc7593..7328d0d 100644
@@ -73,7 +73,7 @@ int mpi_mulpowm(MPI res, MPI *basearray, MPI *exparray, MPI m)
 
 	G = kzalloc((1 << k) * sizeof *G, GFP_KERNEL);
 	if (!G)
-		goto nomem;
+		goto err_out;
 
 	/* and calculate */
 	tmp = mpi_alloc(mpi_get_nlimbs(m) + 1);
@@ -129,5 +129,6 @@ nomem:
 	for (i = 0; i < (1 << k); i++)
 		mpi_free(G[i]);
 	kfree(G);
+err_out:
 	return rc;
 }
#1 lore raw
Quoted 3 lines · Dan Carpenter

We can't call mpi_free() on the elements if the first kzalloc() fails.

Quoted 22 lines
lib/mpi/mpi-mpow.c +2 -1
index 4cc7593..7328d0d 100644
@@ -73,7 +73,7 @@ int mpi_mulpowm(MPI res, MPI *basearray, MPI *exparray, MPI m)
 
        G = kzalloc((1 << k) * sizeof *G, GFP_KERNEL);
        if (!G)
-               goto nomem;
+               goto err_out;
 
        /* and calculate */
        tmp = mpi_alloc(mpi_get_nlimbs(m) + 1);
@@ -129,5 +129,6 @@ nomem:
        for (i = 0; i < (1 << k); i++)
                mpi_free(G[i]);
        kfree(G);
+err_out:
        return rc;
  }
#2 lore raw
In reply to Dan Carpenter

Am 21.11.2011 15:50, schrieb Dan Carpenter:

Quoted 18 lines

We can't call mpi_free() on the elements if the first kzalloc() fails.

lib/mpi/mpi-mpow.c +1 -1
index 4cc7593..7328d0d 100644
@@ -73,7 +73,7 @@ int mpi_mulpowm(MPI res, MPI *basearray, MPI *exparray, MPI m)
 
 	G = kzalloc((1 << k) * sizeof *G, GFP_KERNEL);
 	if (!G)
-		goto nomem;
+		goto err_out;
 
 	/* and calculate */
 	tmp = mpi_alloc(mpi_get_nlimbs(m) + 1);

lib/mpi/mpi-mpow.c nomem: · line 134

Quoted 6 lines
lib/mpi/mpi-mpow.c +1 -0
@@ -129,5 +129,6 @@ nomem:
 	for (i = 0; i < (1 << k); i++)
 		mpi_free(G[i]);
 	kfree(G);
+err_out:
 	return rc;
 }

the patch is ok
but is there any reason *not* to use a more nice name that 'G' something more descriptive perhaps ?

re,
wh