linux: Only set errno after an error
authorChris Wilson <chris@chris-wilson.co.uk>
Sat, 4 Jun 2011 11:30:06 +0000 (12:30 +0100)
committerChris Wilson <chris@chris-wilson.co.uk>
Sat, 4 Jun 2011 11:30:06 +0000 (12:30 +0100)
errno is only valid after an error, and was being filled with a garbage
value upon eof.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
src/linux_sysfs.c

index 1832ee7..bbd4dfa 100644 (file)
@@ -387,7 +387,9 @@ pci_device_linux_sysfs_read( struct pci_device * dev, void * data,
        /* If zero bytes were read, then we assume it's the end of the
         * config file.
         */
-       if ( bytes <= 0 ) {
+       if (bytes == 0)
+           break;
+       if ( bytes < 0 ) {
            err = errno;
            break;
        }
@@ -445,7 +447,9 @@ pci_device_linux_sysfs_write( struct pci_device * dev, const void * data,
        /* If zero bytes were written, then we assume it's the end of the
         * config file.
         */
-       if ( bytes <= 0 ) {
+       if ( bytes == 0 )
+           break;
+       if ( bytes < 0 ) {
            err = errno;
            break;
        }