drivers/analog/dac7554: Add NULL checks after kmm_malloc in dac7554_initialize#18996
Merged
Merged
Conversation
…nitialize dac7554_initialize() calls kmm_malloc twice without checking the return value. If either allocation fails, the subsequent pointer dereferences lead to a NULL pointer access and crash. Add NULL checks for both allocations, following the pattern already used in mcp3008.c, mcp48xx.c, and mcp47x6.c. When the second allocation fails, free the first allocation before returning NULL. Signed-off-by: hanzj <hanzjian@zepp.com>
xiaoxiang781216
approved these changes
May 30, 2026
lupyuen
approved these changes
May 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add missing NULL checks after both
kmm_malloccalls indac7554_initialize()to prevent NULL pointer dereference on allocation failure.Problem
dac7554_initialize()callskmm_malloctwice — first forpriv(adac7554_dev_s), then forg_dacdev(adac_dev_s) — without checking either return value. If either allocation fails, the code immediately dereferences the NULL pointer, causing a crash.The function's doc comment states "a NULL on failure", but the implementation never returns NULL.
Solution
Add NULL checks for both allocations, following the same pattern already established in
mcp3008.c,mcp48xx.c, andmcp47x6.c:kmm_mallocforpriv: return NULL if it fails.kmm_mallocforg_dacdev: freeprivand return NULL if it fails.Changes
File:
drivers/analog/dac7554.c(+13 lines)Location (~line 250):
Verification
✅ Checkpatch:
./tools/checkpatch.sh -g HEAD— All checks pass✅ Code Review: Pattern matches the existing fixes in
mcp3008_initialize()(commitdd5670ed),mcp48xx_initialize()andmcp47x6_initialize()(commitfa1589a6).privalloc failsg_dacdevalloc failspriv, returns NULLSigned-off-by
hanzj hanzjian@zepp.com