mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] mtd: cfi-flash: fail gracefully instead of crashing on NULL page
@ 2021-02-28 19:07 Ahmad Fatoum
  2021-02-28 19:07 ` [PATCH 2/3] usb: dwc2: fix mismatching argument to printf format specifier Ahmad Fatoum
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2021-02-28 19:07 UTC (permalink / raw)
  To: barebox

Until this is fixed, add a comment and have the driver return with an
error instead of crashing on null pointer dereference if it's mapped to
zero.

Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
Cc: Rouven Czerwinski <r.czerwinski@pengutronix.de>
---
 drivers/mtd/nor/cfi_flash.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/mtd/nor/cfi_flash.c b/drivers/mtd/nor/cfi_flash.c
index 225b03ec3d23..ba0bd1b4ebdd 100644
--- a/drivers/mtd/nor/cfi_flash.c
+++ b/drivers/mtd/nor/cfi_flash.c
@@ -969,6 +969,10 @@ static int cfi_probe_one(struct flash_info *info, int num)
 		return PTR_ERR(iores);
 	info->base = IOMEM(iores->start);
 
+	/* TODO: either remap memory region or disable NULL pointer page */
+	if (IS_ENABLED(CONFIG_MMU) && iores->start == 0)
+		return -EPERM;
+
 	ret = flash_detect_size(info);
 	if (ret) {
 		dev_warn(info->dev, "## Unknown FLASH on Bank at 0x%p - Size = 0x%08lx = %ld MB\n",
-- 
2.30.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/3] usb: dwc2: fix mismatching argument to printf format specifier
  2021-02-28 19:07 [PATCH 1/3] mtd: cfi-flash: fail gracefully instead of crashing on NULL page Ahmad Fatoum
@ 2021-02-28 19:07 ` Ahmad Fatoum
  2021-02-28 19:07 ` [PATCH 3/3] MIPS: qemu-malta: make barebox Malta images detectable Ahmad Fatoum
  2021-03-01 15:57 ` [PATCH 1/3] mtd: cfi-flash: fail gracefully instead of crashing on NULL page Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2021-02-28 19:07 UTC (permalink / raw)
  To: barebox

%pad prints a DMA address out of a pointer to dma_addr_t.
Casting the dma_addr_t itself to void *, will lead to printf
dereferencing it and printing the first sizeof(dma_addr_t).

The dwc2 driver is the only one using %pad. Fix it.

Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
 drivers/usb/dwc2/gadget.c | 2 +-
 drivers/usb/dwc2/host.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index b8ec37be78b8..053a243d64c3 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -307,7 +307,7 @@ static void dwc2_gadget_start_req(struct dwc2 *dwc2,
 		dwc2_writel(dwc2, ureq->dma, dma_reg);
 
 		dwc2_dbg(dwc2, "%s: 0x%pad => 0x%08x\n",
-			 __func__, (void *)ureq->dma, dma_reg);
+			 __func__, &ureq->dma, dma_reg);
 	}
 
 	if (hs_ep->isochronous && hs_ep->interval == 1) {
diff --git a/drivers/usb/dwc2/host.c b/drivers/usb/dwc2/host.c
index 7a070d91f3bc..b5a51f566804 100644
--- a/drivers/usb/dwc2/host.c
+++ b/drivers/usb/dwc2/host.c
@@ -181,7 +181,7 @@ static int transfer_chunk(struct dwc2 *dwc2, u8 hc,
 	}
 
 	dwc2_dbg(dwc2, "chunk: pid=%d xfer_len=%u pkts=%u dma_addr=%pad\n",
-		 *pid, xfer_len, num_packets, (void *)dma_addr);
+		 *pid, xfer_len, num_packets, &dma_addr);
 
 	dwc2_writel(dwc2, dma_addr, HCDMA(hc));
 
-- 
2.30.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 3/3] MIPS: qemu-malta: make barebox Malta images detectable
  2021-02-28 19:07 [PATCH 1/3] mtd: cfi-flash: fail gracefully instead of crashing on NULL page Ahmad Fatoum
  2021-02-28 19:07 ` [PATCH 2/3] usb: dwc2: fix mismatching argument to printf format specifier Ahmad Fatoum
@ 2021-02-28 19:07 ` Ahmad Fatoum
  2021-03-01 15:57 ` [PATCH 1/3] mtd: cfi-flash: fail gracefully instead of crashing on NULL page Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2021-02-28 19:07 UTC (permalink / raw)
  To: barebox

is_barebox_mips_head checks whether 0x10-0x16 is "barebox".
Have the Malta images provide this signature like other MIPS boards
already do. This makes bootm work.

Cc: Antony Pavlov <antonynpavlov@gmail.com>
Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
 arch/mips/boards/qemu-malta/lowlevel.S | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/mips/boards/qemu-malta/lowlevel.S b/arch/mips/boards/qemu-malta/lowlevel.S
index e4ecde45cfd7..98821e0426b2 100644
--- a/arch/mips/boards/qemu-malta/lowlevel.S
+++ b/arch/mips/boards/qemu-malta/lowlevel.S
@@ -40,8 +40,7 @@ ENTRY_FUNCTION(BOARD_PBL_START)
 	   0x1fc00010 address is reserved for BoardID
 	*/
 	.org	0x10
-	.word	0xffffffff
-	.word	0xffffffff
+	.asciiz	"barebox"
 
 __start:
 	mips_disable_interrupts
-- 
2.30.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/3] mtd: cfi-flash: fail gracefully instead of crashing on NULL page
  2021-02-28 19:07 [PATCH 1/3] mtd: cfi-flash: fail gracefully instead of crashing on NULL page Ahmad Fatoum
  2021-02-28 19:07 ` [PATCH 2/3] usb: dwc2: fix mismatching argument to printf format specifier Ahmad Fatoum
  2021-02-28 19:07 ` [PATCH 3/3] MIPS: qemu-malta: make barebox Malta images detectable Ahmad Fatoum
@ 2021-03-01 15:57 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2021-03-01 15:57 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Sun, Feb 28, 2021 at 08:07:05PM +0100, Ahmad Fatoum wrote:
> Until this is fixed, add a comment and have the driver return with an
> error instead of crashing on null pointer dereference if it's mapped to
> zero.
> 
> Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
> ---
> Cc: Rouven Czerwinski <r.czerwinski@pengutronix.de>
> ---
>  drivers/mtd/nor/cfi_flash.c | 4 ++++
>  1 file changed, 4 insertions(+)

Applied, thanks

Sascha

> 
> diff --git a/drivers/mtd/nor/cfi_flash.c b/drivers/mtd/nor/cfi_flash.c
> index 225b03ec3d23..ba0bd1b4ebdd 100644
> --- a/drivers/mtd/nor/cfi_flash.c
> +++ b/drivers/mtd/nor/cfi_flash.c
> @@ -969,6 +969,10 @@ static int cfi_probe_one(struct flash_info *info, int num)
>  		return PTR_ERR(iores);
>  	info->base = IOMEM(iores->start);
>  
> +	/* TODO: either remap memory region or disable NULL pointer page */
> +	if (IS_ENABLED(CONFIG_MMU) && iores->start == 0)
> +		return -EPERM;
> +
>  	ret = flash_detect_size(info);
>  	if (ret) {
>  		dev_warn(info->dev, "## Unknown FLASH on Bank at 0x%p - Size = 0x%08lx = %ld MB\n",
> -- 
> 2.30.0
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-01 15:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-28 19:07 [PATCH 1/3] mtd: cfi-flash: fail gracefully instead of crashing on NULL page Ahmad Fatoum
2021-02-28 19:07 ` [PATCH 2/3] usb: dwc2: fix mismatching argument to printf format specifier Ahmad Fatoum
2021-02-28 19:07 ` [PATCH 3/3] MIPS: qemu-malta: make barebox Malta images detectable Ahmad Fatoum
2021-03-01 15:57 ` [PATCH 1/3] mtd: cfi-flash: fail gracefully instead of crashing on NULL page Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox