Skip to content

Commit

Permalink
PMICDRV-183: Potential PMIC_ST_INV_HANDLE error when Pmic_CoreHandle_…
Browse files Browse the repository at this point in the history
…t uses uninit memory

If the Pmic_CoreHandle_t type is created in an uninitialized memory
region the individual fields may not start out as 0. For most fields
this is okay as the fields are assigned using `=`, but the
`drvInitStatus` field is initialized using `|=` so will not end up with
the expected value unless it is explicitly initialized to 0.

This change ensures that this field starts out as `DRV_INIT_UNINIT`.

Signed-off-by: Michael Leonard <[email protected]>
  • Loading branch information
LeonardMH committed Jul 1, 2024
1 parent eb75582 commit ab34bcb
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/pmic.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ int32_t Pmic_init(Pmic_CoreHandle_t *handle, const Pmic_CoreCfg_t *config) {
status = PMIC_ST_ERR_NULL_PARAM;
}

// Ensure starting condition of drvInitStatus is uninit
handle->drvInitStatus = DRV_INIT_UNINIT;

/* Check and update PMIC Handle for device type, Comm Mode, Main Slave Address
* and NVM Slave Address */
if (status == PMIC_ST_SUCCESS) {
Expand Down

0 comments on commit ab34bcb

Please sign in to comment.