qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH for-2.4] m25p80: fix s->blk usage before assignment
@ 2015-04-15  9:43 Stefan Hajnoczi
  2015-04-15  9:53 ` Paolo Bonzini
  2015-04-21 13:20 ` Stefan Hajnoczi
  0 siblings, 2 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2015-04-15  9:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Paolo Bonzini, Peter Crosthwaite, Stefan Hajnoczi

Delay the call to blk_blockalign() until s->blk has been assigned.

This never caused a crash because blk_blockalign(NULL, size) defaults to
4096 alignment but it's technically incorrect.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 hw/block/m25p80.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
index afe243b..d6a37a5 100644
--- a/hw/block/m25p80.c
+++ b/hw/block/m25p80.c
@@ -621,7 +621,6 @@ static int m25p80_init(SSISlave *ss)
 
     s->size = s->pi->sector_size * s->pi->n_sectors;
     s->dirty_page = -1;
-    s->storage = blk_blockalign(s->blk, s->size);
 
     /* FIXME use a qdev drive property instead of drive_get_next() */
     dinfo = drive_get_next(IF_MTD);
@@ -629,6 +628,7 @@ static int m25p80_init(SSISlave *ss)
     if (dinfo) {
         DB_PRINT_L(0, "Binding to IF_MTD drive\n");
         s->blk = blk_by_legacy_dinfo(dinfo);
+        s->storage = blk_blockalign(s->blk, s->size);
 
         /* FIXME: Move to late init */
         if (blk_read(s->blk, 0, s->storage,
@@ -638,6 +638,7 @@ static int m25p80_init(SSISlave *ss)
         }
     } else {
         DB_PRINT_L(0, "No BDRV - binding to RAM\n");
+        s->storage = blk_blockalign(NULL, s->size);
         memset(s->storage, 0xFF, s->size);
     }
 
-- 
2.1.0

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

* Re: [Qemu-devel] [PATCH for-2.4] m25p80: fix s->blk usage before assignment
  2015-04-15  9:43 [Qemu-devel] [PATCH for-2.4] m25p80: fix s->blk usage before assignment Stefan Hajnoczi
@ 2015-04-15  9:53 ` Paolo Bonzini
  2015-04-21 13:20 ` Stefan Hajnoczi
  1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2015-04-15  9:53 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Kevin Wolf, Peter Crosthwaite



On 15/04/2015 11:43, Stefan Hajnoczi wrote:
> Delay the call to blk_blockalign() until s->blk has been assigned.
> 
> This never caused a crash because blk_blockalign(NULL, size) defaults to
> 4096 alignment but it's technically incorrect.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  hw/block/m25p80.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
> index afe243b..d6a37a5 100644
> --- a/hw/block/m25p80.c
> +++ b/hw/block/m25p80.c
> @@ -621,7 +621,6 @@ static int m25p80_init(SSISlave *ss)
>  
>      s->size = s->pi->sector_size * s->pi->n_sectors;
>      s->dirty_page = -1;
> -    s->storage = blk_blockalign(s->blk, s->size);
>  
>      /* FIXME use a qdev drive property instead of drive_get_next() */
>      dinfo = drive_get_next(IF_MTD);
> @@ -629,6 +628,7 @@ static int m25p80_init(SSISlave *ss)
>      if (dinfo) {
>          DB_PRINT_L(0, "Binding to IF_MTD drive\n");
>          s->blk = blk_by_legacy_dinfo(dinfo);
> +        s->storage = blk_blockalign(s->blk, s->size);
>  
>          /* FIXME: Move to late init */
>          if (blk_read(s->blk, 0, s->storage,
> @@ -638,6 +638,7 @@ static int m25p80_init(SSISlave *ss)
>          }
>      } else {
>          DB_PRINT_L(0, "No BDRV - binding to RAM\n");
> +        s->storage = blk_blockalign(NULL, s->size);
>          memset(s->storage, 0xFF, s->size);
>      }
>  
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

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

* Re: [Qemu-devel] [PATCH for-2.4] m25p80: fix s->blk usage before assignment
  2015-04-15  9:43 [Qemu-devel] [PATCH for-2.4] m25p80: fix s->blk usage before assignment Stefan Hajnoczi
  2015-04-15  9:53 ` Paolo Bonzini
@ 2015-04-21 13:20 ` Stefan Hajnoczi
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2015-04-21 13:20 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: Kevin Wolf, Paolo Bonzini, Peter Crosthwaite, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 519 bytes --]

On Wed, Apr 15, 2015 at 10:43:44AM +0100, Stefan Hajnoczi wrote:
> Delay the call to blk_blockalign() until s->blk has been assigned.
> 
> This never caused a crash because blk_blockalign(NULL, size) defaults to
> 4096 alignment but it's technically incorrect.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  hw/block/m25p80.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Thanks, applied to my block-next tree:
https://github.com/stefanha/qemu/commits/block-next

Stefan

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

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

end of thread, other threads:[~2015-04-21 13:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-15  9:43 [Qemu-devel] [PATCH for-2.4] m25p80: fix s->blk usage before assignment Stefan Hajnoczi
2015-04-15  9:53 ` Paolo Bonzini
2015-04-21 13:20 ` Stefan Hajnoczi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).