Skip to content

Commit 0fa712c

Browse files
Sergei Shtylyovambarus
authored andcommitted
mtd: spi-nor: sfdp: add/use local variable in spi_nor_parse_bfpt()
Despite of how spi_nor_parse_bfpt() abuses the structure fields during their calculation, gcc manages to make some decent code out of that. :-) Yet adding a local variable to store the BFPT DWORDs during calculations still saves 12 bytes of the object code (AArch64 gcc 4.8.5)... Signed-off-by: Sergei Shtylyov <[email protected]> Signed-off-by: Tudor Ambarus <[email protected]>
1 parent dec18bd commit 0fa712c

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

drivers/mtd/spi-nor/sfdp.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
437437
struct sfdp_bfpt bfpt;
438438
size_t len;
439439
int i, cmd, err;
440-
u32 addr;
440+
u32 addr, val;
441441
u16 half;
442442
u8 erase_mask;
443443

@@ -473,21 +473,21 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
473473
}
474474

475475
/* Flash Memory Density (in bits). */
476-
params->size = bfpt.dwords[BFPT_DWORD(2)];
477-
if (params->size & BIT(31)) {
478-
params->size &= ~BIT(31);
476+
val = bfpt.dwords[BFPT_DWORD(2)];
477+
if (val & BIT(31)) {
478+
val &= ~BIT(31);
479479

480480
/*
481481
* Prevent overflows on params->size. Anyway, a NOR of 2^64
482482
* bits is unlikely to exist so this error probably means
483483
* the BFPT we are reading is corrupted/wrong.
484484
*/
485-
if (params->size > 63)
485+
if (val > 63)
486486
return -EINVAL;
487487

488-
params->size = 1ULL << params->size;
488+
params->size = 1ULL << val;
489489
} else {
490-
params->size++;
490+
params->size = val + 1;
491491
}
492492
params->size >>= 3; /* Convert to bytes. */
493493

@@ -554,10 +554,10 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
554554
params);
555555

556556
/* Page size: this field specifies 'N' so the page size = 2^N bytes. */
557-
params->page_size = bfpt.dwords[BFPT_DWORD(11)];
558-
params->page_size &= BFPT_DWORD11_PAGE_SIZE_MASK;
559-
params->page_size >>= BFPT_DWORD11_PAGE_SIZE_SHIFT;
560-
params->page_size = 1U << params->page_size;
557+
val = bfpt.dwords[BFPT_DWORD(11)];
558+
val &= BFPT_DWORD11_PAGE_SIZE_MASK;
559+
val >>= BFPT_DWORD11_PAGE_SIZE_SHIFT;
560+
params->page_size = 1U << val;
561561

562562
/* Quad Enable Requirements. */
563563
switch (bfpt.dwords[BFPT_DWORD(15)] & BFPT_DWORD15_QER_MASK) {

0 commit comments

Comments
 (0)