mirror of
https://github.com/apache/nuttx.git
synced 2026-08-01 20:28:58 +00:00
drivers/analog/dac7554: Add NULL checks after kmm_malloc in dac7554_initialize
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>
This commit is contained in:
parent
283742e29c
commit
36bdf9fb37
1 changed files with 13 additions and 0 deletions
|
|
@ -248,10 +248,23 @@ FAR struct dac_dev_s *dac7554_initialize(FAR struct spi_dev_s *spi,
|
|||
/* Initialize the DAC7554 device structure */
|
||||
|
||||
priv = kmm_malloc(sizeof(struct dac7554_dev_s));
|
||||
if (priv == NULL)
|
||||
{
|
||||
aerr("ERROR: Failed to allocate dac7554_dev_s instance\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
priv->spi = spi;
|
||||
priv->spidev = spidev;
|
||||
|
||||
g_dacdev = kmm_malloc(sizeof(struct dac_dev_s));
|
||||
if (g_dacdev == NULL)
|
||||
{
|
||||
aerr("ERROR: Failed to allocate dac_dev_s instance\n");
|
||||
kmm_free(priv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_dacdev->ad_ops = &g_dacops;
|
||||
g_dacdev->ad_priv = priv;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue