Skip to content

Commit b403fde

Browse files
JPHutchinscarlescufi
authored andcommitted
drivers: flash: cleanup #ifs; fix missing ;
Fixes made running tests/drivers/flash Signed-off-by: J.P. Hutchins <[email protected]>
1 parent a9ac01c commit b403fde

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

drivers/flash/spi_nor.c

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ LOG_MODULE_REGISTER(spi_nor, CONFIG_FLASH_LOG_LEVEL);
7070
#define _INST_HAS_HOLD_OR(inst) DT_INST_NODE_HAS_PROP(inst, hold_gpios) ||
7171
#define ANY_INST_HAS_HOLD_GPIOS DT_INST_FOREACH_STATUS_OKAY(_INST_HAS_HOLD_OR) 0
7272

73+
#define DEV_CFG(_dev_) ((const struct spi_nor_config * const) (_dev_)->config)
74+
7375
/* Build-time data associated with the device. */
7476
struct spi_nor_config {
7577
/* Devicetree SPI configuration */
@@ -843,14 +845,11 @@ static int spi_nor_erase(const struct device *dev, off_t addr, size_t size)
843845
static int spi_nor_write_protection_set(const struct device *dev,
844846
bool write_protect)
845847
{
846-
#if ANY_INST_HAS_WP_GPIOS
847-
const struct spi_nor_config *cfg = dev->config;
848-
#endif
849848
int ret;
850849

851850
#if ANY_INST_HAS_WP_GPIOS
852-
if (cfg->wp) {
853-
gpio_pin_set_dt(cfg->wp, write_protect);
851+
if (DEV_CFG(dev)->wp) {
852+
gpio_pin_set_dt(DEV_CFG(dev)->wp, write_protect);
854853
}
855854
#endif
856855

@@ -1345,36 +1344,32 @@ static int spi_nor_pm_control(const struct device *dev, enum pm_device_action ac
13451344
*/
13461345
static int spi_nor_init(const struct device *dev)
13471346
{
1348-
#if (ANY_INST_HAS_WP_GPIOS || ANY_INST_HAS_HOLD_GPIOS)
1349-
const struct spi_nor_config *cfg = dev->config;
1350-
#endif
1351-
13521347
if (IS_ENABLED(CONFIG_MULTITHREADING)) {
13531348
struct spi_nor_data *const driver_data = dev->data;
13541349

13551350
k_sem_init(&driver_data->sem, 1, K_SEM_MAX_LIMIT);
13561351
}
13571352

13581353
#if ANY_INST_HAS_WP_GPIOS
1359-
if (cfg->wp) {
1360-
if (!device_is_ready(cfg->wp->port)) {
1354+
if (DEV_CFG(dev)->wp) {
1355+
if (!device_is_ready(DEV_CFG(dev)->wp->port)) {
13611356
LOG_ERR("Write-protect pin not ready");
13621357
return -ENODEV;
13631358
}
1364-
if (gpio_pin_configure_dt(cfg->wp, GPIO_OUTPUT_ACTIVE)) {
1365-
LOG_ERR("Write-protect pin failed to set active")
1359+
if (gpio_pin_configure_dt(DEV_CFG(dev)->wp, GPIO_OUTPUT_ACTIVE)) {
1360+
LOG_ERR("Write-protect pin failed to set active");
13661361
return -ENODEV;
13671362
}
13681363
}
13691364
#endif /* ANY_INST_HAS_WP_GPIOS */
13701365
#if ANY_INST_HAS_HOLD_GPIOS
1371-
if (cfg->hold) {
1372-
if (!device_is_ready(cfg->hold->port)) {
1366+
if (DEV_CFG(dev)->hold) {
1367+
if (!device_is_ready(DEV_CFG(dev)->hold->port)) {
13731368
LOG_ERR("Hold pin not ready");
13741369
return -ENODEV;
13751370
}
1376-
if (gpio_pin_configure_dt(cfg->hold, GPIO_OUTPUT_INACTIVE)) {
1377-
LOG_ERR("Hold pin failed to set inactive")
1371+
if (gpio_pin_configure_dt(DEV_CFG(dev)->hold, GPIO_OUTPUT_INACTIVE)) {
1372+
LOG_ERR("Hold pin failed to set inactive");
13781373
return -ENODEV;
13791374
}
13801375
}

0 commit comments

Comments
 (0)