PATCH: minor simplification in ide.c
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.
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 ----
Quoted 5 lines · Tristan Gingold
Hi,
there is no need to alloc and free a buffer in
guess_disk_lchs.io_buffercan be used instead.
This slightly simplify the code.
I agree.
Laurent
Signature · 3 lines
----------------- [email protected] ------------------ "La perfection est atteinte non quand il ne reste rien à ajouter mais quand il ne reste rien à enlever." Saint Exupéry