sg engine: do type check only when sd has been setup
[fio.git] / engines / sg.c
index 99c5856a5082d816863af2b693c3effb100edb48..3462688a8d5295980bb6204c56f77581825989ea 100644 (file)
@@ -166,7 +166,7 @@ static int fio_sgio_ioctl_doio(struct thread_data *td,
 
        ret = ioctl(f->fd, SG_IO, hdr);
        if (ret < 0)
-               return -errno;
+               return ret;
 
        return FIO_Q_COMPLETED;
 }
@@ -178,12 +178,12 @@ static int fio_sgio_rw_doio(struct fio_file *f, struct io_u *io_u, int sync)
 
        ret = write(f->fd, hdr, sizeof(*hdr));
        if (ret < 0)
-               return errno;
+               return ret;
 
        if (sync) {
                ret = read(f->fd, hdr, sizeof(*hdr));
                if (ret < 0)
-                       return -errno;
+                       return ret;
                return FIO_Q_COMPLETED;
        }
 
@@ -390,7 +390,7 @@ static int fio_sgio_open(struct thread_data *td, struct fio_file *f)
        if (ret)
                return ret;
 
-       if (!sd->type_checked && fio_sgio_type_check(td, f)) {
+       if (sd && !sd->type_checked && fio_sgio_type_check(td, f)) {
                generic_close_file(td, f);
                return 1;
        }