All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] nand/onenand: reject read-only drives
@ 2011-10-19  6:55 juha.riihimaki
  2011-10-19  6:55 ` [Qemu-devel] [PATCH 1/2] hw/nand: " juha.riihimaki
  2011-10-19  6:55 ` [Qemu-devel] [PATCH 2/2] hw/onenand: " juha.riihimaki
  0 siblings, 2 replies; 4+ messages in thread
From: juha.riihimaki @ 2011-10-19  6:55 UTC (permalink / raw)
  To: qemu-devel

From: Juha Riihimäki <juha.riihimaki@nokia.com>

Make NAND and OneNAND device models reject read-only drives.
Test for example by running

$ qemu-system-arm -drive if=none,file=/dev/zero,readonly,id=foo -device nand,drive=foo,chip_id=0x59 -kernel /dev/null

or

$ qemu-system-arm -drive if=none,file=/dev/zero,readonly,id=foo -device onenand,drive=foo -kernel /dev/null


Juha Riihimäki (2):
  hw/nand: reject read-only drives
  hw/onenand: reject read-only drives

 hw/nand.c    |   23 +++++++++++++++--------
 hw/onenand.c |    5 +++++
 2 files changed, 20 insertions(+), 8 deletions(-)

-- 
1.7.5.4

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

* [Qemu-devel] [PATCH 1/2] hw/nand: reject read-only drives
  2011-10-19  6:55 [Qemu-devel] [PATCH 0/2] nand/onenand: reject read-only drives juha.riihimaki
@ 2011-10-19  6:55 ` juha.riihimaki
  2011-10-19 16:56   ` Markus Armbruster
  2011-10-19  6:55 ` [Qemu-devel] [PATCH 2/2] hw/onenand: " juha.riihimaki
  1 sibling, 1 reply; 4+ messages in thread
From: juha.riihimaki @ 2011-10-19  6:55 UTC (permalink / raw)
  To: qemu-devel

From: Juha Riihimäki <juha.riihimaki@nokia.com>

Signed-off-by: Juha Riihimäki <juha.riihimaki@nokia.com>
---
 hw/nand.c |   23 +++++++++++++++--------
 1 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/hw/nand.c b/hw/nand.c
index c27783e..da6529d 100644
--- a/hw/nand.c
+++ b/hw/nand.c
@@ -19,6 +19,7 @@
 # include "flash.h"
 # include "blockdev.h"
 # include "sysbus.h"
+#include "qemu-error.h"
 
 # define NAND_CMD_READ0		0x00
 # define NAND_CMD_READ1		0x01
@@ -384,18 +385,24 @@ static int nand_device_init(SysBusDevice *dev)
         nand_init_2048(s);
         break;
     default:
-        hw_error("%s: Unsupported NAND block size.\n", __func__);
+        error_report("Unsupported NAND block size");
+        return -1;
     }
 
-    pagesize = 1 << s->oob_shift;
     s->mem_oob = 1;
-    if (s->bdrv && bdrv_getlength(s->bdrv) >=
+    if (s->bdrv) {
+        if (bdrv_is_read_only(s->bdrv)) {
+            error_report("Can't use a read-only drive");
+            return -1;
+        }
+        if (bdrv_getlength(s->bdrv) >=
             (s->pages << s->page_shift) + (s->pages << s->oob_shift)) {
-        pagesize = 0;
-        s->mem_oob = 0;
-    }
-
-    if (!s->bdrv) {
+            pagesize = 0;
+            s->mem_oob = 0;
+        } else {
+            pagesize = 1 << s->oob_shift;
+        }
+    } else {
         pagesize += 1 << s->page_shift;
     }
     if (pagesize) {
-- 
1.7.5.4

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

* [Qemu-devel] [PATCH 2/2] hw/onenand: reject read-only drives
  2011-10-19  6:55 [Qemu-devel] [PATCH 0/2] nand/onenand: reject read-only drives juha.riihimaki
  2011-10-19  6:55 ` [Qemu-devel] [PATCH 1/2] hw/nand: " juha.riihimaki
@ 2011-10-19  6:55 ` juha.riihimaki
  1 sibling, 0 replies; 4+ messages in thread
From: juha.riihimaki @ 2011-10-19  6:55 UTC (permalink / raw)
  To: qemu-devel

From: Juha Riihimäki <juha.riihimaki@nokia.com>

Signed-off-by: Juha Riihimäki <juha.riihimaki@nokia.com>
---
 hw/onenand.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/hw/onenand.c b/hw/onenand.c
index 6f68f70..7898da9 100644
--- a/hw/onenand.c
+++ b/hw/onenand.c
@@ -26,6 +26,7 @@
 #include "memory.h"
 #include "exec-memory.h"
 #include "sysbus.h"
+#include "qemu-error.h"
 
 /* 11 for 2kB-page OneNAND ("2nd generation") and 10 for 1kB-page chips */
 #define PAGE_SHIFT	11
@@ -772,6 +773,10 @@ static int onenand_initfn(SysBusDevice *dev)
         s->image = memset(g_malloc(size + (size >> 5)),
                           0xff, size + (size >> 5));
     } else {
+        if (bdrv_is_read_only(s->bdrv)) {
+            error_report("Can't use a read-only drive");
+            return -1;
+        }
         s->bdrv_cur = s->bdrv;
     }
     s->otp = memset(g_malloc((64 + 2) << PAGE_SHIFT),
-- 
1.7.5.4

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

* Re: [Qemu-devel] [PATCH 1/2] hw/nand: reject read-only drives
  2011-10-19  6:55 ` [Qemu-devel] [PATCH 1/2] hw/nand: " juha.riihimaki
@ 2011-10-19 16:56   ` Markus Armbruster
  0 siblings, 0 replies; 4+ messages in thread
From: Markus Armbruster @ 2011-10-19 16:56 UTC (permalink / raw)
  To: juha.riihimaki; +Cc: qemu-devel

juha.riihimaki@nokia.com writes:

> From: Juha Riihimäki <juha.riihimaki@nokia.com>
>
> Signed-off-by: Juha Riihimäki <juha.riihimaki@nokia.com>
> ---
>  hw/nand.c |   23 +++++++++++++++--------
>  1 files changed, 15 insertions(+), 8 deletions(-)
>
> diff --git a/hw/nand.c b/hw/nand.c
> index c27783e..da6529d 100644
> --- a/hw/nand.c
> +++ b/hw/nand.c
> @@ -19,6 +19,7 @@
>  # include "flash.h"
>  # include "blockdev.h"
>  # include "sysbus.h"
> +#include "qemu-error.h"
>  
>  # define NAND_CMD_READ0		0x00
>  # define NAND_CMD_READ1		0x01
> @@ -384,18 +385,24 @@ static int nand_device_init(SysBusDevice *dev)
>          nand_init_2048(s);
>          break;
>      default:
> -        hw_error("%s: Unsupported NAND block size.\n", __func__);
> +        error_report("Unsupported NAND block size");
> +        return -1;

Not mentioned in commit message.  Separate patch?

>      }
>  
> -    pagesize = 1 << s->oob_shift;
>      s->mem_oob = 1;
> -    if (s->bdrv && bdrv_getlength(s->bdrv) >=
> +    if (s->bdrv) {
> +        if (bdrv_is_read_only(s->bdrv)) {
> +            error_report("Can't use a read-only drive");
> +            return -1;
> +        }
> +        if (bdrv_getlength(s->bdrv) >=
>              (s->pages << s->page_shift) + (s->pages << s->oob_shift)) {
> -        pagesize = 0;
> -        s->mem_oob = 0;
> -    }
> -
> -    if (!s->bdrv) {
> +            pagesize = 0;
> +            s->mem_oob = 0;
> +        } else {
> +            pagesize = 1 << s->oob_shift;
> +        }
> +    } else {
>          pagesize += 1 << s->page_shift;

Doesn't this use pagesize uninitialized?

>      }
>      if (pagesize) {

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

end of thread, other threads:[~2011-10-19 16:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-19  6:55 [Qemu-devel] [PATCH 0/2] nand/onenand: reject read-only drives juha.riihimaki
2011-10-19  6:55 ` [Qemu-devel] [PATCH 1/2] hw/nand: " juha.riihimaki
2011-10-19 16:56   ` Markus Armbruster
2011-10-19  6:55 ` [Qemu-devel] [PATCH 2/2] hw/onenand: " juha.riihimaki

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.