MFC r1.27:
authorSascha Wildner <swildner@dragonflybsd.org>
Tue, 16 Sep 2008 12:39:45 +0000 (16 12:39 +0000)
committerSascha Wildner <swildner@dragonflybsd.org>
Tue, 16 Sep 2008 12:39:45 +0000 (16 12:39 +0000)
If ae is NULL, just print that the controller is unsupported and return,
instead of continuing and dereferencing it later.

Found-by: LLVM/Clang Static Analyzer
sys/dev/raid/amr/amr.c

index 2e03fa1..70aa51c 100644 (file)
@@ -53,7 +53,7 @@
  * SUCH DAMAGE.
  *
  *     $FreeBSD: src/sys/dev/amr/amr.c,v 1.7.2.13 2003/01/15 13:41:18 emoore Exp $
- *     $DragonFly: src/sys/dev/raid/amr/amr.c,v 1.25 2008/01/06 16:55:50 swildner Exp $
+ *     $DragonFly: src/sys/dev/raid/amr/amr.c,v 1.25.4.1 2008/09/16 12:39:45 swildner Exp $
  */
 
 /*
@@ -867,16 +867,26 @@ amr_bio_command(struct amr_softc *sc, struct amr_command **acp)
     ac->ac_bio = bio;
     ac->ac_data = bio->bio_buf->b_data;
     ac->ac_length = bio->bio_buf->b_bcount;
-    if (bio->bio_buf->b_cmd == BUF_CMD_READ) {
+
+    cmd = 0;
+    switch(bio->bio_buf->b_cmd) {
+    case BUF_CMD_READ:
        ac->ac_flags |= AMR_CMD_DATAIN;
        cmd = AMR_CMD_LREAD;
-    } else {
+       break;
+    case BUF_CMD_WRITE:
        ac->ac_flags |= AMR_CMD_DATAOUT;
        cmd = AMR_CMD_LWRITE;
+       break;
+    case BUF_CMD_FLUSH:
+       ac->ac_flags |= AMR_CMD_PRIORITY | AMR_CMD_DATAOUT;
+       cmd = AMR_CMD_FLUSH;
+       break;
     }
     amrd = (struct amrd_softc *)bio->bio_driver_info;
     driveno = amrd->amrd_drive - sc->amr_drive;
     blkcount = (bio->bio_buf->b_bcount + AMR_BLKSIZE - 1) / AMR_BLKSIZE;
+
     lba = bio->bio_offset / AMR_BLKSIZE;
     KKASSERT(lba < 0x100000000ULL);
 
@@ -1738,7 +1748,8 @@ amr_describe_controller(struct amr_softc *sc)
            break;
        }
     } else {
-       prod = "unsupported controller";
+       device_printf(sc->amr_dev, "<unsupported controller>\n");
+       return;
     }
 
     /*