* [U-Boot] [PATCH] sf: Fix NULL pointer exception for flashes without lock methods
@ 2015-11-13 10:46 Bin Meng
2015-11-13 10:49 ` Fabio Estevam
2015-11-13 14:47 ` [U-Boot] " Tom Rini
0 siblings, 2 replies; 5+ messages in thread
From: Bin Meng @ 2015-11-13 10:46 UTC (permalink / raw)
To: u-boot
commit c3c016c "sf: Add SPI NOR protection mechanism" introduced
flash_lock()/flash_unlock()/flash_is_locked() methods for SPI flash,
but not every flash driver supplies these. We should test these
methods against NULL before actually calling them.
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
---
drivers/mtd/spi/sf_ops.c | 18 ++++++++++++------
include/spi_flash.h | 2 +-
2 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c
index d832464..384224d 100644
--- a/drivers/mtd/spi/sf_ops.c
+++ b/drivers/mtd/spi/sf_ops.c
@@ -268,9 +268,12 @@ int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len)
return -1;
}
- if (flash->flash_is_locked(flash, offset, len) > 0) {
- printf("offset 0x%x is protected and cannot be erased\n", offset);
- return -EINVAL;
+ if (flash->flash_is_locked) {
+ if (flash->flash_is_locked(flash, offset, len) > 0) {
+ printf("offset 0x%x is protected and cannot be erased\n",
+ offset);
+ return -EINVAL;
+ }
}
cmd[0] = flash->erase_cmd;
@@ -315,9 +318,12 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
page_size = flash->page_size;
- if (flash->flash_is_locked(flash, offset, len) > 0) {
- printf("offset 0x%x is protected and cannot be written\n", offset);
- return -EINVAL;
+ if (flash->flash_is_locked) {
+ if (flash->flash_is_locked(flash, offset, len) > 0) {
+ printf("offset 0x%x is protected and cannot be written\n",
+ offset);
+ return -EINVAL;
+ }
}
cmd[0] = flash->write_cmd;
diff --git a/include/spi_flash.h b/include/spi_flash.h
index 0ae0062..f25b3e7 100644
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -237,7 +237,7 @@ static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
static inline int spi_flash_protect(struct spi_flash *flash, u32 ofs, u32 len,
bool prot)
{
- if (!flash->flash_lock)
+ if (!flash->flash_lock || !flash->flash_unlock)
return -EOPNOTSUPP;
if (prot)
--
1.8.2.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [U-Boot] [PATCH] sf: Fix NULL pointer exception for flashes without lock methods
2015-11-13 10:46 [U-Boot] [PATCH] sf: Fix NULL pointer exception for flashes without lock methods Bin Meng
@ 2015-11-13 10:49 ` Fabio Estevam
2015-11-13 13:07 ` Bin Meng
2015-11-13 14:47 ` [U-Boot] " Tom Rini
1 sibling, 1 reply; 5+ messages in thread
From: Fabio Estevam @ 2015-11-13 10:49 UTC (permalink / raw)
To: u-boot
On Fri, Nov 13, 2015 at 8:46 AM, Bin Meng <bmeng.cn@gmail.com> wrote:
> commit c3c016c "sf: Add SPI NOR protection mechanism" introduced
> flash_lock()/flash_unlock()/flash_is_locked() methods for SPI flash,
> but not every flash driver supplies these. We should test these
> methods against NULL before actually calling them.
>
> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Thanks for the fix.
Reviewed-by: Fabio Estevam <fabio.estevam@freescale.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [U-Boot] [PATCH] sf: Fix NULL pointer exception for flashes without lock methods
2015-11-13 10:49 ` Fabio Estevam
@ 2015-11-13 13:07 ` Bin Meng
2015-11-13 13:31 ` Jagan Teki
0 siblings, 1 reply; 5+ messages in thread
From: Bin Meng @ 2015-11-13 13:07 UTC (permalink / raw)
To: u-boot
Hi Tom,
On Fri, Nov 13, 2015 at 6:49 PM, Fabio Estevam <festevam@gmail.com> wrote:
> On Fri, Nov 13, 2015 at 8:46 AM, Bin Meng <bmeng.cn@gmail.com> wrote:
>> commit c3c016c "sf: Add SPI NOR protection mechanism" introduced
>> flash_lock()/flash_unlock()/flash_is_locked() methods for SPI flash,
>> but not every flash driver supplies these. We should test these
>> methods against NULL before actually calling them.
>>
>> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
>
> Thanks for the fix.
>
> Reviewed-by: Fabio Estevam <fabio.estevam@freescale.com>
Could you please apply this directly as this fix booting crash at
least on Chromebook Link?
Regards,
Bin
^ permalink raw reply [flat|nested] 5+ messages in thread
* [U-Boot] [PATCH] sf: Fix NULL pointer exception for flashes without lock methods
2015-11-13 13:07 ` Bin Meng
@ 2015-11-13 13:31 ` Jagan Teki
0 siblings, 0 replies; 5+ messages in thread
From: Jagan Teki @ 2015-11-13 13:31 UTC (permalink / raw)
To: u-boot
On Nov 13, 2015 6:37 PM, "Bin Meng" <bmeng.cn@gmail.com> wrote:
>
> Hi Tom,
>
> On Fri, Nov 13, 2015 at 6:49 PM, Fabio Estevam <festevam@gmail.com> wrote:
> > On Fri, Nov 13, 2015 at 8:46 AM, Bin Meng <bmeng.cn@gmail.com> wrote:
> >> commit c3c016c "sf: Add SPI NOR protection mechanism" introduced
> >> flash_lock()/flash_unlock()/flash_is_locked() methods for SPI flash,
> >> but not every flash driver supplies these. We should test these
> >> methods against NULL before actually calling them.
> >>
> >> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> >
> > Thanks for the fix.
> >
> > Reviewed-by: Fabio Estevam <fabio.estevam@freescale.com>
>
> Could you please apply this directly as this fix booting crash at
> least on Chromebook Link?
Reviewed-by: Jagan Teki <jteki@openedev.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [U-Boot] sf: Fix NULL pointer exception for flashes without lock methods
2015-11-13 10:46 [U-Boot] [PATCH] sf: Fix NULL pointer exception for flashes without lock methods Bin Meng
2015-11-13 10:49 ` Fabio Estevam
@ 2015-11-13 14:47 ` Tom Rini
1 sibling, 0 replies; 5+ messages in thread
From: Tom Rini @ 2015-11-13 14:47 UTC (permalink / raw)
To: u-boot
On Fri, Nov 13, 2015 at 02:46:26AM -0800, Bin Meng wrote:
> commit c3c016c "sf: Add SPI NOR protection mechanism" introduced
> flash_lock()/flash_unlock()/flash_is_locked() methods for SPI flash,
> but not every flash driver supplies these. We should test these
> methods against NULL before actually calling them.
>
> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> Reviewed-by: Fabio Estevam <fabio.estevam@freescale.com>
> Reviewed-by: Jagan Teki <jteki@openedev.com>
Applied to u-boot/master, thanks!
--
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151113/4ac55502/attachment.sig>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-11-13 14:47 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-13 10:46 [U-Boot] [PATCH] sf: Fix NULL pointer exception for flashes without lock methods Bin Meng
2015-11-13 10:49 ` Fabio Estevam
2015-11-13 13:07 ` Bin Meng
2015-11-13 13:31 ` Jagan Teki
2015-11-13 14:47 ` [U-Boot] " Tom Rini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.