Author: mav
Date: Mon Dec 19 18:55:10 2016
New Revision: 310284
URL: https://svnweb.freebsd.org/changeset/base/310284

Log:
  When writing fixed format sense data, set VALID bit only if provided value
  for INFORMATION field fit into available 4 bytes (has no non-zero bytes
  except last 4), as explicitly required by SPC-5 specification.
  
  MFC after:    2 weeks

Modified:
  head/sys/cam/scsi/scsi_all.c

Modified: head/sys/cam/scsi/scsi_all.c
==============================================================================
--- head/sys/cam/scsi/scsi_all.c        Mon Dec 19 18:32:26 2016        
(r310283)
+++ head/sys/cam/scsi/scsi_all.c        Mon Dec 19 18:55:10 2016        
(r310284)
@@ -4020,11 +4020,17 @@ scsi_set_sense_data_va(struct scsi_sense
                                        data_dest = &sense->info[0];
                                        len_to_copy = MIN(sense_len,
                                            sizeof(sense->info));
-                                       /*
-                                        * We're setting the info field, so
-                                        * set the valid bit.
-                                        */
-                                       sense->error_code |= SSD_ERRCODE_VALID;
+
+                                       /* Set VALID bit only if no overflow. */
+                                       for (i = 0; i < sense_len - len_to_copy;
+                                           i++) {
+                                               if (data[i] != 0)
+                                                       break;
+                                       }
+                                       if (i >= sense_len - len_to_copy) {
+                                               sense->error_code |=
+                                                   SSD_ERRCODE_VALID;
+                                       }
                                }
 
                                /*
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to