drivers: espi: espi_taf_npcx: reorder NULL checks

Move the NULL checks for the protection configuration parameters
before dereferencing them to avoid potential NULL pointer
dereferences.

The device pointer is assumed to be valid.

No functional change intended.

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
This commit is contained in:
Gaetan Perrot
2025-12-29 23:32:28 +09:00
committed by Fabio Baltieri
parent 30bfb73e27
commit 0c8f4741b8

View File

@@ -217,13 +217,13 @@ static int espi_taf_npcx_configure(const struct device *dev, const struct espi_s
static int espi_taf_npcx_set_pr(const struct device *dev, const struct espi_saf_protection *pr)
{
struct espi_reg *const inst = HAL_INSTANCE(dev);
const struct espi_saf_pr *preg = pr->pregions;
size_t n = pr->nregions;
const struct espi_saf_pr *preg;
size_t n;
uint8_t regnum;
uint16_t offset;
uint32_t bitmask, rw_pr, override_rw;
if ((dev == NULL) || (pr == NULL)) {
if (pr == NULL) {
return -EINVAL;
}
@@ -231,6 +231,9 @@ static int espi_taf_npcx_set_pr(const struct device *dev, const struct espi_saf_
return -EINVAL;
}
preg = pr->pregions;
n = pr->nregions;
while (n--) {
regnum = preg->pr_num;