mtd: cfi_cmdset_0001: Factor out do_write_buffer_locked() to reduce stack frame
PATCH 1/1 mtd: cfi_cmdset_0001: Factor out do_write_buffer_locked() to reduce stack frame
Compiler is not happy about used stack frame:
drivers/mtd/chips/cfi_cmdset_0001.c: In function 'do_write_buffer':drivers/mtd/chips/cfi_cmdset_0001.c:1887:1: error: the frame size of 1296 bytes is larger than 1280 bytes [-Werror=frame-larger-than=]
Fix this by factoring out do_write_buffer_locked().
--- drivers/mtd/chips/cfi_cmdset_0001.c | 77 +++++++++++++++++------------ 1 file changed, 45 insertions(+), 32 deletions(-)
drivers/mtd/chips/cfi_cmdset_0001.c +45 -32
@@ -1720,40 +1720,24 @@ static int cfi_intelext_write_words (struct mtd_info *mtd, loff_t to , size_t le } -static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip, -unsigned long adr,const struct kvec **pvec, -unsigned long *pvec_seek,int len) +static int __xipram do_write_buffer_locked(struct map_info *map, struct flchip *chip, +unsigned long cmd_adr,unsigned long adr, +const struct kvec **pvec, +unsigned long *pvec_seek,int len) {struct cfi_private *cfi = map->fldrv_priv;map_word status, write_cmd, datum; -unsigned long cmd_adr; -int ret, wbufsize, word_gap, words; +int ret, word_gap, words;const struct kvec *vec;unsigned long vec_seek;unsigned long initial_adr;int initial_len = len; - wbufsize =cfi_interleave (cfi) << cfi->cfiq->MaxBufWriteSize; - adr += chip->start; initial_adr = adr; - cmd_adr = adr & ~(wbufsize-1 ); - -/* Sharp LH28F640BF chips need the first address for the -* Page Buffer Program command. See Table 5 of -* LH28F320BF, LH28F640BF, LH28F128BF Series (Appendix FUM00701) */ -if (is_LH28F640BF (cfi)) - cmd_adr = adr;/* Let's determine this according to the interleave only once */ write_cmd = (cfi->cfiq->P_ID !=P_ID_INTEL_PERFORMANCE ) ?CMD (0xe8 ) :CMD (0xe9 ); -mutex_lock (&chip->mutex); - ret =get_chip (map, chip, cmd_adr,FL_WRITING ); -if (ret) { -mutex_unlock (&chip->mutex); -return ret; - } -XIP_INVAL_CACHED_RANGE (map, initial_adr, initial_len);ENABLE_VPP (map);xip_disable (map, chip, cmd_adr);
@@ -1789,7 +1773,7 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,xip_enable (map, chip, cmd_adr);printk (KERN_ERR "%s: Chip not ready for buffer write. Xstatus = %lx, status = %lx\n" , map->name, Xstatus.x[0 ], status.x[0 ]); - goto out; +return ret; }/* Figure out the number of words to write */
@@ -1853,7 +1837,7 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip, chip->state =FL_STATUS ;xip_enable (map, chip, cmd_adr);printk (KERN_ERR "%s: buffer write error (status timeout)\n" , map->name); - goto out; +return ret; }/* check for errors */
@@ -1866,21 +1850,50 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,map_write (map,CMD (0x70 ), cmd_adr);xip_enable (map, chip, cmd_adr); -if (chipstatus &0x02 ) { - ret = -EROFS ; - }else if (chipstatus &0x08 ) { +if (chipstatus &0x02 ) +return -EROFS ; + +if (chipstatus &0x08 ) {printk (KERN_ERR "%s: buffer write error (bad VPP)\n" , map->name); - ret = -EIO ; - }else { -printk (KERN_ERR "%s: buffer write error (status 0x%lx)\n" , map->name, chipstatus); - ret = -EINVAL ; +return -EIO ; } - goto out; +printk (KERN_ERR "%s: buffer write error (status 0x%lx)\n" , map->name, chipstatus); +return -EINVAL ; }xip_enable (map, chip, cmd_adr); - out:DISABLE_VPP (map); +return 0 ; +} + +static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip, +unsigned long adr,const struct kvec **pvec, +unsigned long *pvec_seek,int len) +{ +struct cfi_private *cfi = map->fldrv_priv; +unsigned long cmd_adr; +int ret, wbufsize; + + wbufsize =cfi_interleave (cfi) << cfi->cfiq->MaxBufWriteSize; + adr += chip->start; + cmd_adr = adr & ~(wbufsize -1 ); + +/* Sharp LH28F640BF chips need the first address for the +* Page Buffer Program command. See Table 5 of +* LH28F320BF, LH28F640BF, LH28F128BF Series (Appendix FUM00701) */ +if (is_LH28F640BF (cfi)) + cmd_adr = adr; + +mutex_lock (&chip->mutex); + ret =get_chip (map, chip, cmd_adr,FL_WRITING ); +if (ret) { +mutex_unlock (&chip->mutex); +return ret; + } + + ret =do_write_buffer_locked (map, chip, cmd_adr, adr, pvec, pvec_seek, len); + +DISABLE_VPP (map);put_chip (map, chip, cmd_adr);mutex_unlock (&chip->mutex);return ret;
Signature · 1 line
2.50.1
Quoted 6 lines · Andy Shevchenko
Compiler is not happy about used stack frame:
drivers/mtd/chips/cfi_cmdset_0001.c: In function 'do_write_buffer':drivers/mtd/chips/cfi_cmdset_0001.c:1887:1: error: the frame size of 1296 bytes is larger than 1280 bytes [-Werror=frame-larger-than=]Fix this by factoring out
do_write_buffer_locked().
...
drivers/mtd/chips/cfi_cmdset_0001.c static int cfi_intelext_write_words (struct mtd_info *mtd, loff_t to , size_t le · line 1742
Quoted 2 lines
drivers/mtd/chips/cfi_cmdset_0001.c +0
-0XIP_INVAL_CACHED_RANGE (map, initial_adr, initial_len);ENABLE_VPP (map);
It seems more logical to leave these two in the original call.
...
Quoted 18 lines
drivers/mtd/chips/cfi_cmdset_0001.c +18
-0+static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip, +unsigned long adr,const struct kvec **pvec, +unsigned long *pvec_seek,int len) +{ +struct cfi_private *cfi = map->fldrv_priv; +unsigned long cmd_adr; +int ret, wbufsize; + + wbufsize =cfi_interleave (cfi) << cfi->cfiq->MaxBufWriteSize; + adr += chip->start; + cmd_adr = adr & ~(wbufsize -1 ); + +/* Sharp LH28F640BF chips need the first address for the +* Page Buffer Program command. See Table 5 of +* LH28F320BF, LH28F640BF, LH28F128BF Series (Appendix FUM00701) */ +if (is_LH28F640BF (cfi)) + cmd_adr = adr; +
drivers/mtd/chips/cfi_cmdset_0001.c static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip, · line 1896
Quoted 10 lines
drivers/mtd/chips/cfi_cmdset_0001.c +9
-0+mutex_lock (&chip->mutex); + ret =get_chip (map, chip, cmd_adr,FL_WRITING ); +if (ret) { +mutex_unlock (&chip->mutex); +return ret; + } + + ret =do_write_buffer_locked (map, chip, cmd_adr, adr, pvec, pvec_seek, len); +DISABLE_VPP (map);
Otherwise this will seem dangling here.
drivers/mtd/chips/cfi_cmdset_0001.c static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip, · line 1899
Quoted 3 lines
drivers/mtd/chips/cfi_cmdset_0001.c +0
-0put_chip (map, chip, cmd_adr);mutex_unlock (&chip->mutex);return ret;
...
Another approach is to leave goto as is in the _locked() and move DISABLE_VPP() there.
Tell me what do you prefer?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Miquel Raynal
maintainerHi Andy,
Quoted 10 lines
Quoted 1 line
Fix this by factoring out
do_write_buffer_locked()....
drivers/mtd/chips/cfi_cmdset_0001.c static int cfi_intelext_write_words (struct mtd_info *mtd, loff_t to , size_t le · line 1742
Quoted 2 lines
drivers/mtd/chips/cfi_cmdset_0001.c +0
-0XIP_INVAL_CACHED_RANGE (map, initial_adr, initial_len);ENABLE_VPP (map);It seems more logical to leave these two in the original call.
...
[...]
Quoted 8 lines
drivers/mtd/chips/cfi_cmdset_0001.c static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip, · line 1896
Quoted 1 line
drivers/mtd/chips/cfi_cmdset_0001.c +1
-0+DISABLE_VPP (map);Otherwise this will seem dangling here.
drivers/mtd/chips/cfi_cmdset_0001.c static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip, · line 1899
Quoted 3 lines
drivers/mtd/chips/cfi_cmdset_0001.c +0
-0put_chip (map, chip, cmd_adr);mutex_unlock (&chip->mutex);return ret;
Quoted 6 lines
...
Another approach is to leave goto as is in the
_locked()and moveDISABLE_VPP()there.Tell me what do you prefer?
While I also find more logical to keep the ENABLE_VPP/DISABLE_VPP together, I do not mind to see them in one side or the other. I would by default let them in the main caller and suffi the inner function with "_locked()" as you did, but I'm fine either ways.
Thanks,
Miquèl
Raghavendra, Vignesh
maintainerHi,
Quoted 28 lines · Miquel Raynal
Hi Andy,
Quoted 10 lines
Quoted 1 line
Fix this by factoring out
do_write_buffer_locked()....
drivers/mtd/chips/cfi_cmdset_0001.c static int cfi_intelext_write_words (struct mtd_info *mtd, loff_t to , size_t le · line 1742
Quoted 2 lines
drivers/mtd/chips/cfi_cmdset_0001.c +0
-0XIP_INVAL_CACHED_RANGE (map, initial_adr, initial_len);ENABLE_VPP (map);It seems more logical to leave these two in the original call.
...
[...]
Quoted 13 lines
drivers/mtd/chips/cfi_cmdset_0001.c static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip, · line 1896
Quoted 1 line
drivers/mtd/chips/cfi_cmdset_0001.c +1
-0+DISABLE_VPP (map);Otherwise this will seem dangling here.
drivers/mtd/chips/cfi_cmdset_0001.c static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip, · line 1899
Quoted 3 lines
drivers/mtd/chips/cfi_cmdset_0001.c +0
-0put_chip (map, chip, cmd_adr);mutex_unlock (&chip->mutex);return ret;...
Another approach is to leave goto as is in the
_locked()and moveDISABLE_VPP()there.
Quoted 7 lines
Quoted 1 line
Tell me what do you prefer?
While I also find more logical to keep the ENABLE_VPP/DISABLE_VPP together, I do not mind to see them in one side or the other. I would by default let them in the main caller and suffi the inner function with "
_locked()" as you did, but I'm fine either ways.
Keeping ENABLE_VPP/DISABLE_VPP together along with _locked() suffix for inner function is cleaner to read.
Regards
Vignesh
Quoted 1 line · Vignesh
On 1/29/2026 11:53 PM, Miquel Raynal wrote:
...
Quoted 24 lines
Quoted 24 lines
Quoted 6 lines
drivers/mtd/chips/cfi_cmdset_0001.c static int cfi_intelext_write_words (struct mtd_info *mtd, loff_t to , size_t le · line 1742
Quoted 2 lines
drivers/mtd/chips/cfi_cmdset_0001.c +0
-0XIP_INVAL_CACHED_RANGE (map, initial_adr, initial_len);ENABLE_VPP (map);It seems more logical to leave these two in the original call.
...
[...]
Quoted 14 lines
drivers/mtd/chips/cfi_cmdset_0001.c static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip, · line 1896
Quoted 1 line
drivers/mtd/chips/cfi_cmdset_0001.c +1
-0+DISABLE_VPP (map);Otherwise this will seem dangling here.
drivers/mtd/chips/cfi_cmdset_0001.c static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip, · line 1899
Quoted 3 lines
drivers/mtd/chips/cfi_cmdset_0001.c +0
-0put_chip (map, chip, cmd_adr);mutex_unlock (&chip->mutex);return ret;...
Another approach is to leave goto as is in the
_locked()and moveDISABLE_VPP()there.Tell me what do you prefer?
Quoted 7 lines
Quoted 4 lines
While I also find more logical to keep the ENABLE_VPP/DISABLE_VPP together, I do not mind to see them in one side or the other. I would by default let them in the main caller and suffi the inner function with "
_locked()" as you did, but I'm fine either ways.Keeping ENABLE_VPP/DISABLE_VPP together along with
_locked()suffix for inner function is cleaner to read.
I just sent a v2 where I kept them in the original call.
Signature · 2 lines
With Best Regards, Andy Shevchenko