* grub-core/disk/pata.c (grub_pata_pio_read): Handle unaligned buffer.

(grub_pata_pio_write): Likewise.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2011-12-13 15:55:36 +01:00
parent 02a2bf8384
commit b70b6d1107
2 changed files with 9 additions and 4 deletions

View file

@ -1,3 +1,8 @@
2011-12-13 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/disk/pata.c (grub_pata_pio_read): Handle unaligned buffer.
(grub_pata_pio_write): Likewise.
2011-12-13 Vladimir Serbinenko <phcoder@gmail.com>
Add noreturn attributes and remove unreachable code.

View file

@ -116,12 +116,13 @@ grub_pata_wait (void)
static void
grub_pata_pio_read (struct grub_pata_device *dev, char *buf, grub_size_t size)
{
grub_uint16_t *buf16 = (grub_uint16_t *) buf;
unsigned int i;
/* Read in the data, word by word. */
for (i = 0; i < size / 2; i++)
buf16[i] = grub_le_to_cpu16 (grub_inw(dev->ioaddress + GRUB_ATA_REG_DATA));
grub_set_unaligned16 (buf + 2 * i,
grub_le_to_cpu16 (grub_inw(dev->ioaddress
+ GRUB_ATA_REG_DATA)));
if (size & 1)
buf[size - 1] = (char) grub_le_to_cpu16 (grub_inw (dev->ioaddress
+ GRUB_ATA_REG_DATA));
@ -130,12 +131,11 @@ grub_pata_pio_read (struct grub_pata_device *dev, char *buf, grub_size_t size)
static void
grub_pata_pio_write (struct grub_pata_device *dev, char *buf, grub_size_t size)
{
grub_uint16_t *buf16 = (grub_uint16_t *) buf;
unsigned int i;
/* Write the data, word by word. */
for (i = 0; i < size / 2; i++)
grub_outw(grub_cpu_to_le16 (buf16[i]), dev->ioaddress + GRUB_ATA_REG_DATA);
grub_outw(grub_cpu_to_le16 (grub_get_unaligned16 (buf + 2 * i)), dev->ioaddress + GRUB_ATA_REG_DATA);
}
/* ATA pass through support, used by hdparm.mod. */