qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] PATCH: minor simplification in ide.c
@ 2008-01-22 16:14 Tristan Gingold
  2008-01-22 16:23 ` Laurent Vivier
  0 siblings, 1 reply; 2+ messages in thread
From: Tristan Gingold @ 2008-01-22 16:14 UTC (permalink / raw)
  To: qemu-devel

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

Hi,

there is no need to alloc and free a buffer in guess_disk_lchs.   
io_buffer can be used instead.
This slightly simplify the code.



[-- Attachment #2: ide.diff --]
[-- Type: application/octet-stream, Size: 1687 bytes --]

Index: hw/ide.c
===================================================================
RCS file: /sources/qemu/qemu/hw/ide.c,v
retrieving revision 1.81
diff -c -r1.81 ide.c
*** hw/ide.c	14 Jan 2008 03:15:20 -0000	1.81
--- hw/ide.c	22 Jan 2008 16:04:39 -0000
***************
*** 2474,2495 ****
  static int guess_disk_lchs(IDEState *s,
                             int *pcylinders, int *pheads, int *psectors)
  {
!     uint8_t *buf;
      int ret, i, heads, sectors, cylinders;
      struct partition *p;
      uint32_t nr_sects;
  
-     buf = qemu_memalign(512, 512);
-     if (buf == NULL)
-         return -1;
      ret = bdrv_read(s->bs, 0, buf, 1);
      if (ret < 0) {
-         qemu_free(buf);
          return -1;
      }
      /* test msdos magic */
      if (buf[510] != 0x55 || buf[511] != 0xaa) {
-         qemu_free(buf);
          return -1;
      }
      for(i = 0; i < 4; i++) {
--- 2474,2490 ----
  static int guess_disk_lchs(IDEState *s,
                             int *pcylinders, int *pheads, int *psectors)
  {
!     uint8_t *buf = s->io_buffer;
      int ret, i, heads, sectors, cylinders;
      struct partition *p;
      uint32_t nr_sects;
  
      ret = bdrv_read(s->bs, 0, buf, 1);
      if (ret < 0) {
          return -1;
      }
      /* test msdos magic */
      if (buf[510] != 0x55 || buf[511] != 0xaa) {
          return -1;
      }
      for(i = 0; i < 4; i++) {
***************
*** 2512,2522 ****
              printf("guessed geometry: LCHS=%d %d %d\n",
                     cylinders, heads, sectors);
  #endif
-             qemu_free(buf);
              return 0;
          }
      }
-     qemu_free(buf);
      return -1;
  }
  
--- 2507,2515 ----

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

* Re: [Qemu-devel] PATCH: minor simplification in ide.c
  2008-01-22 16:14 [Qemu-devel] PATCH: minor simplification in ide.c Tristan Gingold
@ 2008-01-22 16:23 ` Laurent Vivier
  0 siblings, 0 replies; 2+ messages in thread
From: Laurent Vivier @ 2008-01-22 16:23 UTC (permalink / raw)
  To: qemu-devel

Le mardi 22 janvier 2008 à 17:14 +0100, Tristan Gingold a écrit :
> Hi,
> 
> there is no need to alloc and free a buffer in guess_disk_lchs.   
> io_buffer can be used instead.
> This slightly simplify the code.

I agree.

Laurent
-- 
----------------- Laurent.Vivier@bull.net  ------------------
  "La perfection est atteinte non quand il ne reste rien à
ajouter mais quand il ne reste rien à enlever." Saint Exupéry

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

end of thread, other threads:[~2008-01-22 16:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-22 16:14 [Qemu-devel] PATCH: minor simplification in ide.c Tristan Gingold
2008-01-22 16:23 ` Laurent Vivier

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).