patch-lib_obsd-device_c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. $OpenBSD: patch-lib_obsd-device_c,v 1.5 2014/08/21 08:02:56 dcoppa Exp $
  2. --- lib/obsd-device.c.orig Fri Jan 7 22:04:28 2011
  3. +++ lib/obsd-device.c Thu Aug 21 09:59:31 2014
  4. @@ -41,9 +41,12 @@ obsd_init(struct pci_access *a)
  5. {
  6. char *name = pci_get_param(a, "obsd.path");
  7. - a->fd = open(name, O_RDWR, 0);
  8. - if (a->fd < 0)
  9. - a->error("obsd_init: %s open failed", name);
  10. + a->fd = open(name, O_RDWR | O_CLOEXEC);
  11. + if (a->fd == -1) {
  12. + a->fd = open(name, O_RDONLY | O_CLOEXEC);
  13. + if (a->fd == -1)
  14. + a->error("obsd_init: %s open failed (%s)", name, strerror(errno));
  15. + }
  16. }
  17. static void
  18. @@ -56,11 +59,6 @@ static int
  19. obsd_read(struct pci_dev *d, int pos, byte *buf, int len)
  20. {
  21. struct pci_io pi;
  22. - union {
  23. - u_int32_t u32;
  24. - u_int16_t u16[2];
  25. - u_int8_t u8[4];
  26. - } u;
  27. if (!(len == 1 || len == 2 || len == 4))
  28. return pci_generic_block_read(d, pos, buf, len);
  29. @@ -81,18 +79,16 @@ obsd_read(struct pci_dev *d, int pos, byte *buf, int l
  30. else
  31. d->access->error("obsd_read: ioctl(PCIOCREAD) failed");
  32. }
  33. - u.u32 = pi.pi_data;
  34. -
  35. switch (len)
  36. {
  37. case 1:
  38. - buf[0] = (u8) u.u8[pos % 4];
  39. + buf[0] = (u8) (pi.pi_data >> ((pos % 4) * 8));
  40. break;
  41. case 2:
  42. - ((u16 *) buf)[0] = letoh16(u.u16[(pos % 4) / 2]);
  43. + ((u16 *) buf)[0] = (u16) htole16(pi.pi_data >> ((pos % 4) * 8));
  44. break;
  45. case 4:
  46. - ((u32 *) buf)[0] = (u32) letoh32(pi.pi_data);
  47. + ((u32 *) buf)[0] = (u32) htole32(pi.pi_data);
  48. break;
  49. }
  50. return 1;