From 35ca62b2dce957138bc59ff8c95933e0bcfab060 Mon Sep 17 00:00:00 2001 From: Pisit Sawangvonganan Date: Thu, 31 Oct 2024 14:20:31 +0700 Subject: [PATCH] drivers: eeprom: at2x: simplify `cmd[]` assignment in `at25_read`, `write` Simplify offset assignment in `eeprom_at25_read` and `eeprom_at25_write` by directly setting values in `cmd[]` instead of using an intermediary `paddr` pointer. This makes the code more compact and improves readability. Signed-off-by: Pisit Sawangvonganan --- drivers/eeprom/eeprom_at2x.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/eeprom/eeprom_at2x.c b/drivers/eeprom/eeprom_at2x.c index 4ed70d16f2f4948..07ee6200c1e851c 100644 --- a/drivers/eeprom/eeprom_at2x.c +++ b/drivers/eeprom/eeprom_at2x.c @@ -421,7 +421,6 @@ static int eeprom_at25_read(const struct device *dev, off_t offset, void *buf, const struct eeprom_at2x_config *config = dev->config; size_t cmd_len = 1 + config->addr_width / 8; uint8_t cmd[4] = { EEPROM_AT25_READ, 0, 0, 0 }; - uint8_t *paddr; int err; const struct spi_buf tx_buf = { .buf = cmd, @@ -455,16 +454,15 @@ static int eeprom_at25_read(const struct device *dev, off_t offset, void *buf, return -EINVAL; } - paddr = &cmd[1]; switch (config->addr_width) { case 24: - *paddr++ = offset >> 16; + cmd[1] = offset >> 16; __fallthrough; case 16: - *paddr++ = offset >> 8; + cmd[2] = offset >> 8; __fallthrough; case 8: - *paddr++ = offset; + cmd[3] = offset; break; default: __ASSERT(0, "invalid address width"); @@ -507,7 +505,6 @@ static int eeprom_at25_write(const struct device *dev, off_t offset, int count = eeprom_at2x_limit_write_count(dev, offset, len); uint8_t cmd[4] = { EEPROM_AT25_WRITE, 0, 0, 0 }; size_t cmd_len = 1 + config->addr_width / 8; - uint8_t *paddr; int err; const struct spi_buf tx_bufs[2] = { { @@ -524,16 +521,15 @@ static int eeprom_at25_write(const struct device *dev, off_t offset, .count = ARRAY_SIZE(tx_bufs), }; - paddr = &cmd[1]; switch (config->addr_width) { case 24: - *paddr++ = offset >> 16; + cmd[1] = offset >> 16; __fallthrough; case 16: - *paddr++ = offset >> 8; + cmd[2] = offset >> 8; __fallthrough; case 8: - *paddr++ = offset; + cmd[3] = offset; break; default: __ASSERT(0, "invalid address width");