Skip to contentSkip to conversation

malloc: solve dead code issue in memalign()

PATCH In review Stephen Warren 2 participants 3 messages Feb 4, 2016 – Feb 8, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 malloc: solve dead code issue in memalign()

From: Stephen Warren <[email protected]>

The recent change to memalign() caused the allocation failure detection code to be dead code; the "retry" logic is always activated under the same condition that the original failure detection code is, and also fully handles any possible failures. This patch solves the presence of dead code.

Two alternatives are possible:

a) Delete the now-dead test, and rely on the "retry" path to handle any allocation problems, as it does.

b) Make the "retry" path fall through to the existing (currently dead) failure detection code, thus making it not-dead.

(b) was chosen since it reduces the diff between U-Boot's and the upstream dlmalloc. This should make it marginally easier to import a new version of dlmalloc in the future.

Reported by: Coverity Scan

Fixes 4f144a416469 ("malloc: work around some memalign fragmentation issues")
---
 common/dlmalloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
common/dlmalloc.c +1 -1
index 2b964d16b11e..5ea37dfb6e4c 100644
@@ -2848,7 +2848,7 @@ Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes;
       return m;
     /* Otherwise, fail */
     fREe(m);
-    return NULL;
+    m = NULL;
   }
 
   if (m == NULL) return NULL; /* propagate failure */
Signature · 1 line
2.7.0
#1 lore raw

PATCH 1/1 malloc: solve dead code issue in memalign()

Quoted 16 lines · Stephen Warren

From: Stephen Warren <[email protected]>

The recent change to memalign() caused the allocation failure detection code to be dead code; the "retry" logic is always activated under the same condition that the original failure detection code is, and also fully handles any possible failures. This patch solves the presence of dead code.

Two alternatives are possible:

a) Delete the now-dead test, and rely on the "retry" path to handle any allocation problems, as it does.

b) Make the "retry" path fall through to the existing (currently dead) failure detection code, thus making it not-dead.

Quoted 7 lines

(b) was chosen since it reduces the diff between U-Boot's and the upstream dlmalloc. This should make it marginally easier to import a new version of dlmalloc in the future.

Reported by: Coverity Scan

Fixes 4f144a416469 ("malloc: work around some memalign fragmentation issues")

Thanks for the quick turn-around!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160204/57c35465/attachment.sig>
#2 lore raw
In reply to Stephen Warren
Quoted 16 lines · Stephen Warren

From: Stephen Warren <[email protected]>

The recent change to memalign() caused the allocation failure detection code to be dead code; the "retry" logic is always activated under the same condition that the original failure detection code is, and also fully handles any possible failures. This patch solves the presence of dead code.

Two alternatives are possible:

a) Delete the now-dead test, and rely on the "retry" path to handle any allocation problems, as it does.

b) Make the "retry" path fall through to the existing (currently dead) failure detection code, thus making it not-dead.

Quoted 8 lines

(b) was chosen since it reduces the diff between U-Boot's and the upstream dlmalloc. This should make it marginally easier to import a new version of dlmalloc in the future.

Reported by: Coverity Scan

Fixes 4f144a416469 ("malloc: work around some memalign fragmentation issues")

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160208/caeb8108/attachment.sig>