Skip to content

Commit

Permalink
hw/pflash: refactor pflash_data_write()
Browse files Browse the repository at this point in the history
Move the offset calculation, do it once at the start of the function and
let the 'p' variable point directly to the memory location which should
be updated.  This makes it simpler to update other buffers than
pfl->storage in an upcoming patch.  No functional change.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20240108160900.104835-2-kraxel@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
(cherry picked from commit 3b14a55)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
  • Loading branch information
kraxel authored and Michael Tokarev committed Jan 20, 2024
1 parent a290e43 commit 06679ac
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions hw/block/pflash_cfi01.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,33 +404,35 @@ static void pflash_update(PFlashCFI01 *pfl, int offset,
static inline void pflash_data_write(PFlashCFI01 *pfl, hwaddr offset,
uint32_t value, int width, int be)
{
uint8_t *p = pfl->storage;
uint8_t *p;

trace_pflash_data_write(pfl->name, offset, width, value, pfl->counter);
p = pfl->storage + offset;

switch (width) {
case 1:
p[offset] = value;
p[0] = value;
break;
case 2:
if (be) {
p[offset] = value >> 8;
p[offset + 1] = value;
p[0] = value >> 8;
p[1] = value;
} else {
p[offset] = value;
p[offset + 1] = value >> 8;
p[0] = value;
p[1] = value >> 8;
}
break;
case 4:
if (be) {
p[offset] = value >> 24;
p[offset + 1] = value >> 16;
p[offset + 2] = value >> 8;
p[offset + 3] = value;
p[0] = value >> 24;
p[1] = value >> 16;
p[2] = value >> 8;
p[3] = value;
} else {
p[offset] = value;
p[offset + 1] = value >> 8;
p[offset + 2] = value >> 16;
p[offset + 3] = value >> 24;
p[0] = value;
p[1] = value >> 8;
p[2] = value >> 16;
p[3] = value >> 24;
}
break;
}
Expand Down

0 comments on commit 06679ac

Please sign in to comment.