diff --git a/include/sg_lib_data.h b/include/sg_lib_data.h index 9739453..a870043 100644 --- a/include/sg_lib_data.h +++ b/include/sg_lib_data.h @@ -122,8 +122,6 @@ extern struct sg_lib_simple_value_name_t sg_lib_nvme_nvm_cmd_arr[]; extern struct sg_lib_value_name_t sg_lib_nvme_cmd_status_arr[]; extern struct sg_lib_4tuple_u8 sg_lib_scsi_status_sense_arr[]; -size_t sg_lib_scsi_status_sense_arr_len(void); - extern struct sg_value_2names_t sg_exit_str_arr[]; #ifdef __cplusplus diff --git a/lib/sg_cmds_basic.c b/lib/sg_cmds_basic.c index f4021bb..e625465 100644 --- a/lib/sg_cmds_basic.c +++ b/lib/sg_cmds_basic.c @@ -324,13 +324,6 @@ sg_ll_inquiry_com(struct sg_pt_base * ptvp, bool cmddt, bool evpd, int pg_op, uint8_t sense_b[SENSE_BUFF_LEN]; uint8_t * up; - if (resp == NULL) { - if (verbose) - pr2ws("Got NULL `resp` pointer"); - return SG_LIB_CAT_MALFORMED; - } - - if (cmddt) inq_cdb[1] |= 0x2; if (evpd) diff --git a/lib/sg_lib.c b/lib/sg_lib.c index a691b02..c2c5891 100644 --- a/lib/sg_lib.c +++ b/lib/sg_lib.c @@ -545,6 +545,7 @@ sg_decode_transportid_str(const char * lip, uint8_t * bp, int bplen, } if (NULL == lip) lip = ""; + bump = TRANSPORT_ID_MIN_LEN; /* should be overwritten in all loop paths */ for (k = 0, n = 0; bplen > 0; ++k, bp += bump, bplen -= bump) { if ((k > 0) && only_one) break; @@ -1845,6 +1846,9 @@ sg_get_sense_str(const char * lip, const uint8_t * sbp, int sb_len, sg_scnpr(b + r, blen - r, "%s lba=0x%x\n", lip, sg_get_unaligned_be24(sbp + 1) & 0x1fffff); n += sg_scnpr(cbp + n, cblen - n, "%s\n", b); + len = sb_len; + if (len > 32) + len = 32; /* trim in case there is a lot of rubbish */ } check_raw: if (raw_sinfo) { @@ -2119,11 +2123,14 @@ sg_get_command_size(uint8_t opcode) switch ((opcode >> 5) & 0x7) { case 0: return 6; + case 1: case 2: case 6: case 7: + return 10; case 3: case 5: return 12; + break; case 4: return 16; - default: /* 1, 2, 6, 7 */ + default: return 10; } } @@ -2260,6 +2267,9 @@ sg_get_opcode_name(uint8_t cmd_byte0, int peri_type, int buff_len, case 7: sg_scnpr(buff, buff_len, "Vendor specific [0x%x]", (int)cmd_byte0); break; + default: + sg_scnpr(buff, buff_len, "Opcode=0x%x", (int)cmd_byte0); + break; } } @@ -2575,9 +2585,6 @@ sg_nvme_status2scsi(uint16_t sct_sc, uint8_t * status_p, uint8_t * sk_p, return false; } else if (ind >= k) return false; - /* Check whether `ind` is out of index of sg_lib_scsi_status_sense_arr */ - if (ind >= (int) sg_lib_scsi_status_sense_arr_len()) - return false; mp = sg_lib_scsi_status_sense_arr + ind; if (status_p) *status_p = mp->t1; diff --git a/lib/sg_lib_data.c b/lib/sg_lib_data.c index 3a898e5..d5ca380 100644 --- a/lib/sg_lib_data.c +++ b/lib/sg_lib_data.c @@ -1850,9 +1850,3 @@ struct sg_value_2names_t sg_exit_str_arr[] = { }; #endif /* (SG_SCSI_STRINGS && HAVE_NVME && (! IGNORE_NVME)) */ - -size_t sg_lib_scsi_status_sense_arr_len(void) -{ - return sizeof(sg_lib_scsi_status_sense_arr)/ - sizeof(struct sg_lib_4tuple_u8) - 1; -} diff --git a/lib/sg_pt_linux_nvme.c b/lib/sg_pt_linux_nvme.c index 98feaef..18b1374 100644 --- a/lib/sg_pt_linux_nvme.c +++ b/lib/sg_pt_linux_nvme.c @@ -899,6 +899,11 @@ sntl_senddiag(struct sg_pt_linux_scsi * ptp, const uint8_t * cdbp, return 0; } else return 0; /* nothing to do */ + if (dout_len > 0) { + if (vb) + pr2ws("%s: dout given but PF clear\n", __func__); + return SCSI_PT_DO_BAD_PARAMS; + } } if (dout_len < 4) { if (vb) diff --git a/scripts/fc_wwpn_id b/scripts/fc_wwpn_id index b05c5e8..c8d0189 100644 --- a/scripts/fc_wwpn_id +++ b/scripts/fc_wwpn_id @@ -38,9 +38,7 @@ while [ -n "$d" ] ; do esac done -if [ -n "$rport_wwpn" ] || [ -n "$host_wwpn" ] ; then - echo "FC_TARGET_LUN=$target_lun" -fi +echo "FC_TARGET_LUN=$target_lun" if [ -n "$rport_wwpn" ] ; then echo "FC_TARGET_WWPN=$rport_wwpn" diff --git a/scripts/rescan-scsi-bus.sh b/scripts/rescan-scsi-bus.sh index ed3cf49..6989208 100755 --- a/scripts/rescan-scsi-bus.sh +++ b/scripts/rescan-scsi-bus.sh @@ -235,7 +235,7 @@ is_removable () p=/sys/class/scsi_device/${host}:${channel}:${id}:${lun}/device/inquiry # Extract the second byte of the INQUIRY response and check bit 7 (mask 0x80). b=$(od -tx1 -j1 -N1 "$p" 2>/dev/null | - { read -r _ byte rest; echo -n "$byte"; }) + { read -r offset byte rest; echo -n "$byte"; }) if [ -n "$b" ]; then echo $(((0x$b & 0x80) != 0)) else @@ -314,10 +314,8 @@ testonline () fi else # Ignore disk revision change - local old_str_no_rev - old_str_no_rev=`echo "$TMPSTR" | sed -e 's/.\{4\}$//'` - local new_str_no_rev - new_str_no_rev=`echo "$STR" | sed -e 's/.\{4\}$//'` + local old_str_no_rev=`echo "$TMPSTR" | sed -e 's/.\{4\}$//'` + local new_str_no_rev=`echo "$STR" | sed -e 's/.\{4\}$//'` if [ "$old_str_no_rev" != "$new_str_no_rev" ]; then echo -e "\e[A\e[A\e[A\e[A${red}$SGDEV changed: ${bold}\nfrom:${SCSISTR#* } \nto: $STR ${norm} \n\n\n" return 1 @@ -548,7 +546,7 @@ dolunscan() printf "\r\e[A"; # Optimization: if lun==0, stop here (only if in non-remove mode) if test $lun = 0 -a -z "$remove" -a $optscan = 1; then - return; + break; fi else if test "$remappedlun0" != "2" ; then @@ -698,8 +696,7 @@ searchexisting() local tmpch; local tmpid local match=0 - local targets - targets=`ls -d /sys/class/scsi_device/$host:* 2> /dev/null | egrep -o $host:[0-9]+:[0-9]+ | sort | uniq` + local targets=`ls -d /sys/class/scsi_device/$host:* 2> /dev/null | egrep -o $host:[0-9]+:[0-9]+ | sort | uniq` # Nothing came back on this host, so we should skip it test -z "$targets" && return @@ -745,15 +742,13 @@ searchexisting() findremapped() { local hctl=; - local devs - devs=`ls /sys/class/scsi_device/` + local devs=`ls /sys/class/scsi_device/` local sddev= local id_serial= local id_serial_old= local remapped= mpaths="" - local tmpfile - tmpfile=$(mktemp /tmp/rescan-scsi-bus.XXXXXXXX 2> /dev/null) + local tmpfile=$(mktemp /tmp/rescan-scsi-bus.XXXXXXXX 2> /dev/null) if [ -z "$tmpfile" ] ; then tmpfile="/tmp/rescan-scsi-bus.$$" @@ -840,8 +835,7 @@ incrchgd() fi if test -n "$mp_enable" ; then - local sdev - sdev="`findsddev \"$hctl\"`" + local sdev="`findsddev \"$hctl\"`" if test -n "$sdev" ; then findmultipath "$sdev" fi @@ -859,8 +853,7 @@ incrrmvd() fi if test -n "$mp_enable" ; then - local sdev - sdev="`findsddev \"$hctl\"`" + local sdev="`findsddev \"$hctl\"`" if test -n "$sdev" ; then findmultipath "$sdev" fi @@ -909,8 +902,7 @@ findmultipath() return 1 fi - local maj_min - maj_min=`cat /sys/block/$dev/dev` + local maj_min=`cat /sys/block/$dev/dev` for mp in $($DMSETUP ls --target=multipath | cut -f 1) ; do [ "$mp" = "No" ] && break; if $DMSETUP status $mp | grep -q " $maj_min "; then diff --git a/src/misc.h b/src/misc.h deleted file mode 100644 index 6289eae..0000000 --- a/src/misc.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018 Red Hat, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * Author: Gris Ge - */ -#ifndef __SG_UTILS_MISC_H__ -#define __SG_UTILS_MISC_H__ - -/* Just make coverity scan happy. */ -#define _ignore_return(x) if (x) {} - -#endif /* End of __SG_UTILS_MISC_H__ */ diff --git a/src/sg_dd.c b/src/sg_dd.c index aa544c7..edd8f9c 100644 --- a/src/sg_dd.c +++ b/src/sg_dd.c @@ -976,7 +976,7 @@ err_out: } return may_coe ? 0 : ret; } else - return ret; + return ret ? ret : -1; } @@ -1276,7 +1276,6 @@ open_if(const char * inf, int64_t skip, int bpt, struct flags_t * ifp, perror(ME "SG_SET_RESERVED_SIZE error"); res = ioctl(infd, SG_GET_VERSION_NUM, &t); if ((res < 0) || (t < 30000)) { - close(infd); if (FT_BLOCK & *in_typep) pr2serr(ME "SG_IO unsupported on this block device\n"); else @@ -1309,7 +1308,6 @@ open_if(const char * inf, int64_t skip, int bpt, struct flags_t * ifp, snprintf(ebuff, EBUFF_SZ, ME "couldn't skip to " "required position on %s", inf); perror(ebuff); - close(infd); goto file_err; } if (vb) @@ -1343,7 +1341,6 @@ open_if(const char * inf, int64_t skip, int bpt, struct flags_t * ifp, file_err: return -SG_LIB_FILE_ERROR; other_err: - close(infd); return -SG_LIB_CAT_OTHER; } @@ -1401,7 +1398,6 @@ open_of(const char * outf, int64_t seek, int bpt, struct flags_t * ofp, perror(ME "SG_SET_RESERVED_SIZE error"); res = ioctl(outfd, SG_GET_VERSION_NUM, &t); if ((res < 0) || (t < 30000)) { - close(outfd); pr2serr(ME "sg driver prior to 3.x.y\n"); goto file_err; } @@ -1451,7 +1447,6 @@ open_of(const char * outf, int64_t seek, int bpt, struct flags_t * ofp, snprintf(ebuff, EBUFF_SZ, ME "couldn't seek to required position on %s", outf); perror(ebuff); - close(outfd); goto file_err; } if (vb) @@ -1459,7 +1454,7 @@ open_of(const char * outf, int64_t seek, int bpt, struct flags_t * ofp, "\n", (uint64_t)offset); } } - if ((ofp->flock) && (outfd >= 0)) { + if (ofp->flock) { res = flock(outfd, LOCK_EX | LOCK_NB); if (res < 0) { close(outfd); @@ -1474,7 +1469,6 @@ open_of(const char * outf, int64_t seek, int bpt, struct flags_t * ofp, file_err: return -SG_LIB_FILE_ERROR; other_err: - close(outfd); return -SG_LIB_CAT_OTHER; } diff --git a/src/sg_format.c b/src/sg_format.c index 61ee77f..af1a033 100644 --- a/src/sg_format.c +++ b/src/sg_format.c @@ -700,6 +700,12 @@ print_dev_id(int fd, uint8_t * sinq_resp, int max_rlen, n = (SAFE_STD_INQ_RESP_LEN - 4); for (k = 0, has_sn = 0, has_di = 0; k < n; ++k) { if (VPD_UNIT_SERIAL_NUM == b[4 + k]) { + if (has_di) { + if (op->verbose) + pr2serr("VPD_SUPPORTED_VPDS " + "dis-ordered\n"); + goto out; + } ++has_sn; } else if (VPD_DEVICE_ID == b[4 + k]) { ++has_di; diff --git a/src/sg_get_config.c b/src/sg_get_config.c index 4d2cc9b..28af720 100644 --- a/src/sg_get_config.c +++ b/src/sg_get_config.c @@ -24,8 +24,6 @@ #include "sg_unaligned.h" #include "sg_pr2serr.h" -#include "misc.h" - /* A utility program originally written for the Linux OS SCSI subsystem. * * This program outputs information provided by a SCSI "Get Configuration" @@ -1093,7 +1091,7 @@ main(int argc, char * argv[]) pr2serr(ME "%s doesn't respond to a SCSI INQUIRY\n", device_name); return SG_LIB_CAT_OTHER; } - _ignore_return(sg_cmds_close_device(sg_fd)); + sg_cmds_close_device(sg_fd); sg_fd = sg_cmds_open_device(device_name, readonly, verbose); if (sg_fd < 0) { @@ -1124,7 +1122,7 @@ main(int argc, char * argv[]) } else { char b[80]; - _ignore_return(sg_get_category_sense_str(res, sizeof(b), b, verbose)); + sg_get_category_sense_str(res, sizeof(b), b, verbose); pr2serr("Get Configuration command: %s\n", b); if (0 == verbose) pr2serr(" try '-v' option for more information\n"); diff --git a/src/sg_get_lba_status.c b/src/sg_get_lba_status.c index 61a823b..91c7a96 100644 --- a/src/sg_get_lba_status.c +++ b/src/sg_get_lba_status.c @@ -340,7 +340,7 @@ main(int argc, char * argv[]) res = sg_ll_get_lba_status16(sg_fd, lba, rt, glbasBuffp, maxlen, true, verbose); else if (do_32) /* keep analyser happy since do_32 must be true */ - res = sg_ll_get_lba_status32(sg_fd, lba, scan_len, element_id, rt, + res = sg_ll_get_lba_status32(sg_fd, lba, element_id, scan_len, rt, glbasBuffp, maxlen, true, verbose); ret = res; diff --git a/src/sg_inq.c b/src/sg_inq.c index 1664345..b32ab87 100644 --- a/src/sg_inq.c +++ b/src/sg_inq.c @@ -3428,6 +3428,7 @@ cmddt_process(int sg_fd, const struct opts_t * op) break; case 6: desc_p = "vendor specific (6)"; break; case 7: desc_p = "reserved (7)"; break; + default: desc_p = "impossible value > 7"; break; } if (prnt_cmd) { printf(" Support field: %s [", desc_p); diff --git a/src/sg_logs.c b/src/sg_logs.c index 7001ee4..61443ff 100644 --- a/src/sg_logs.c +++ b/src/sg_logs.c @@ -34,8 +34,6 @@ #include "sg_unaligned.h" #include "sg_pr2serr.h" -#include "misc.h" - static const char * version_str = "1.69 20180911"; /* spc5r19 + sbc4r11 */ #define MX_ALLOC_LEN (0xfffc) @@ -6778,7 +6776,7 @@ fetchTemperature(int sg_fd, uint8_t * resp, int max_len, struct opts_t * op) pr2serr("Unable to find temperature in either Temperature or " "IE log page\n"); } - _ignore_return(sg_cmds_close_device(sg_fd)); + sg_cmds_close_device(sg_fd); return (res >= 0) ? res : SG_LIB_CAT_OTHER; } @@ -7109,7 +7107,7 @@ main(int argc, char * argv[]) if (k) { if (SG_LIB_CAT_NOT_READY == k) pr2serr("log_select: device not ready\n"); - else if (SG_LIB_CAT_ILLEGAL_REQ == k) + else if (SG_LIB_CAT_ILLEGAL_REQ == res) pr2serr("log_select: field in cdb illegal\n"); else if (SG_LIB_CAT_INVALID_OP == k) pr2serr("log_select: not supported\n"); @@ -7248,7 +7246,7 @@ err_out: if (free_parr) free(free_parr); if (sg_fd >= 0) - _ignore_return(sg_cmds_close_device(sg_fd)); + sg_cmds_close_device(sg_fd); if (0 == vb) { if (! sg_if_can2stderr("sg_logs failed: ", ret)) pr2serr("Some error occurred, try again with '-v' or '-vv' for " diff --git a/src/sg_luns.c b/src/sg_luns.c index 9115070..904b2ce 100644 --- a/src/sg_luns.c +++ b/src/sg_luns.c @@ -306,6 +306,9 @@ decode_lun(const char * leadin, const uint8_t * lunp, bool lu_cong, } } break; + default: + printf("%s<<%s: faulty logic>>\n", l_leadin, __func__); + break; } if (next_level) continue; diff --git a/src/sg_opcodes.c b/src/sg_opcodes.c index a8cf762..21897c4 100644 --- a/src/sg_opcodes.c +++ b/src/sg_opcodes.c @@ -799,8 +799,7 @@ list_all_codes(uint8_t * rsoc_buff, int rsoc_len, struct opts_t * op, printf(" usage: "); else printf(" cdb usage: "); - for (m = 0; (m < cdb_sz) && ((size_t) (4 + m) < sizeof(b)); - ++m) + for (m = 0; m < cdb_sz; ++m) printf("%.2x ", b[4 + m]); printf("\n"); } diff --git a/src/sg_persist.c b/src/sg_persist.c index 2e10aff..f582d32 100644 --- a/src/sg_persist.c +++ b/src/sg_persist.c @@ -33,8 +33,6 @@ #include "sg_unaligned.h" #include "sg_pr2serr.h" -#include "misc.h" - static const char * version_str = "0.66 20180615"; @@ -305,8 +303,7 @@ prin_work(int sg_fd, const struct opts_t * op) pr2serr("PR in (%s): bad field in cdb or parameter list (perhaps " "unsupported service action)\n", b); else { - _ignore_return(sg_get_category_sense_str(res, sizeof(bb), bb, - op->verbose)); + sg_get_category_sense_str(res, sizeof(bb), bb, op->verbose); pr2serr("PR in (%s): %s\n", b, bb); } goto fini; @@ -522,8 +519,7 @@ prout_work(int sg_fd, struct opts_t * op) pr2serr("PR out (%s): bad field in cdb or parameter list " "(perhaps unsupported service action)\n", b); else { - _ignore_return(sg_get_category_sense_str(res, sizeof(bb), bb, - op->verbose)); + sg_get_category_sense_str(res, sizeof(bb), bb, op->verbose); pr2serr("PR out (%s): %s\n", b, bb); } goto fini; @@ -577,8 +573,7 @@ prout_reg_move_work(int sg_fd, struct opts_t * op) else { char bb[80]; - _ignore_return(sg_get_category_sense_str(res, sizeof(bb), bb, - op->verbose)); + sg_get_category_sense_str(res, sizeof(bb), bb, op->verbose); pr2serr("PR out (register and move): %s\n", bb); } goto fini; @@ -829,7 +824,7 @@ decode_file_tids(const char * fnp, struct opts_t * op) pr2serr("%s: array length exceeded\n", __func__); goto bad; } - op->transportid_arr[off + k] = h; + tid_arr[off + k] = h; lcp = strpbrk(lcp, " ,\t"); if (NULL == lcp) break; @@ -1282,7 +1277,7 @@ main(int argc, char * argv[]) flagged = true; goto fini; } - _ignore_return(sg_cmds_close_device(sg_fd)); + sg_cmds_close_device(sg_fd); } if (! op->readwrite_force) { diff --git a/src/sg_raw.c b/src/sg_raw.c index 64b8574..92c2287 100644 --- a/src/sg_raw.c +++ b/src/sg_raw.c @@ -438,13 +438,6 @@ parse_cmd_line(struct opts_t * op, int argc, char *argv[]) } } - if (op->version_given -#ifdef DEBUG - && ! op->verbose_given -#endif - ) - return 0; - if (optind >= argc) { pr2serr("No device specified\n\n"); return SG_LIB_SYNTAX_ERROR; @@ -461,7 +454,7 @@ parse_cmd_line(struct opts_t * op, int argc, char *argv[]) return SG_LIB_SYNTAX_ERROR; } - if (op->cdb_length >= MAX_SCSI_CDBSZ) { + if (op->cdb_length > MAX_SCSI_CDBSZ) { pr2serr("CDB too long (max. %d bytes)\n", MAX_SCSI_CDBSZ); return SG_LIB_SYNTAX_ERROR; } diff --git a/src/sg_rbuf.c b/src/sg_rbuf.c index 6b74436..61604d3 100644 --- a/src/sg_rbuf.c +++ b/src/sg_rbuf.c @@ -681,5 +681,5 @@ main(int argc, char * argv[]) else printf("read buffer non-zero\n"); #endif - return res; + return (res >= 0) ? res : SG_LIB_CAT_OTHER; } diff --git a/src/sg_sanitize.c b/src/sg_sanitize.c index b810128..b45462f 100644 --- a/src/sg_sanitize.c +++ b/src/sg_sanitize.c @@ -388,6 +388,11 @@ print_dev_id(int fd, uint8_t * sinq_resp, int max_rlen, int verbose) n = (SAFE_STD_INQ_RESP_LEN - 4); for (k = 0, has_sn = 0, has_di = 0; k < n; ++k) { if (VPD_UNIT_SERIAL_NUM == b[4 + k]) { + if (has_di) { + if (verbose) + pr2serr("VPD_SUPPORTED_VPDS dis-ordered\n"); + return 0; + } ++has_sn; } else if (VPD_DEVICE_ID == b[4 + k]) { ++has_di; diff --git a/src/sg_ses.c b/src/sg_ses.c index 9c4b0c0..abb1fea 100644 --- a/src/sg_ses.c +++ b/src/sg_ses.c @@ -1405,6 +1405,9 @@ parse_cmd_line(struct opts_t *op, int argc, char *argv[]) else if (1 == n) { op->page_code_given = true; op->page_code = pc; + } else { + pr2serr("No dpage found --data= argument\n"); + goto err_help; } if (op->verbose > 3) { int k; @@ -2428,6 +2431,9 @@ find_sas_connector_type(int conn_type, bool abridged, char * buff, else if (conn_type < 0x20) snprintf(buff, buff_len, "unknown internal wide connector type: " "0x%x", conn_type); + else if (conn_type < 0x30) + snprintf(buff, buff_len, "unknown internal connector to end " + "device, type: 0x%x", conn_type); else if (conn_type < 0x3f) snprintf(buff, buff_len, "reserved for internal connector, " "type: 0x%x", conn_type); @@ -2631,6 +2637,8 @@ enc_status_helper(const char * pad, const uint8_t * statp, int etype, printf("%slast 3 bytes (hex): %02x %02x %02x\n", pad, statp[1], statp[2], statp[3]); break; + default: + break; } break; case UI_POWER_SUPPLY_ETC: /* Uninterruptible power supply */ @@ -4252,7 +4260,8 @@ process_status_dpage(struct sg_pt_base * ptvp, int page_code, uint8_t * resp, subenc_nickname_sdg(resp, resp_len); break; default: - printf("Cannot decode response from diagnostic page: %s\n", cp); + printf("Cannot decode response from diagnostic " + "page: %s\n", (cp ? cp : "")); hex2stdout(resp, resp_len, 0); } @@ -5301,7 +5310,7 @@ ses_cgs(struct sg_pt_base * ptvp, const struct tuple_acronym_val * tavp, if (op->ind_indiv_last <= op->ind_indiv) break; } /* end of loop over join array */ - if ((k >= MX_JOIN_ROWS) || (NULL == jrp->enc_statp)) { + if ((NULL == jrp->enc_statp) || (k >= MX_JOIN_ROWS)) { if (op->desc_name) pr2serr("descriptor name: %s not found (check the 'ed' page " "[0x7])\n", op->desc_name); diff --git a/src/sg_test_rwbuf.c b/src/sg_test_rwbuf.c index 52b7e81..f187ba0 100644 --- a/src/sg_test_rwbuf.c +++ b/src/sg_test_rwbuf.c @@ -386,8 +386,8 @@ void usage () int main (int argc, char * argv[]) { - bool verbose_given = false; - bool version_given = false; + bool verbose_given = true; + bool version_given = true; int sg_fd, res; const char * device_name = NULL; int times = 1; diff --git a/src/sg_turs.c b/src/sg_turs.c index c5ea723..b68f1a4 100644 --- a/src/sg_turs.c +++ b/src/sg_turs.c @@ -251,7 +251,7 @@ old_parse_cmd_line(struct opts_t * op, int argc, char * argv[]) op->version_given = true; break; case '?': - ++op->do_help; + usage_old(); return 0; default: jmp_out = true; diff --git a/src/sg_vpd.c b/src/sg_vpd.c index 2865af4..a15ed74 100644 --- a/src/sg_vpd.c +++ b/src/sg_vpd.c @@ -1233,6 +1233,9 @@ decode_x_inq_vpd(uint8_t * b, int len, int do_hex, bool do_long, case 7: printf(" [protection types 1, 2 and 3 supported]\n"); break; + default: + printf("\n"); + break; } } else printf("\n"); @@ -1929,9 +1932,9 @@ decode_3party_copy_vpd(uint8_t * buff, int len, int do_hex, int pdt, printf(" Maximum identified concurrent copies: %u\n", u); u = sg_get_unaligned_be32(bp + 12); printf(" Maximum segment length: %u\n", u); - ull = (1 << bp[16]) & UINT64_MAX; /* field is power of 2 */ + ull = (1 << bp[16]); /* field is power of 2 */ printf(" Data segment granularity: %" PRIu64 "\n", ull); - ull = (1 << bp[17]) & UINT64_MAX; + ull = (1 << bp[17]); printf(" Inline data granularity: %" PRIu64 "\n", ull); break; case 0x9101: @@ -1943,7 +1946,7 @@ decode_3party_copy_vpd(uint8_t * buff, int len, int do_hex, int pdt, printf(" Held data:\n"); u = sg_get_unaligned_be32(bp + 4); printf(" Held data limit: %u\n", u); - ull = (1 << bp[8]) & UINT64_MAX; + ull = (1 << bp[8]); printf(" Held data granularity: %" PRIu64 "\n", ull); break; default: @@ -1988,6 +1991,8 @@ decode_proto_lu_vpd(uint8_t * buff, int len, int do_hex) continue; if (2 == do_hex) hex2stdout(bp + 8, desc_len, 1); + else if (do_hex > 2) + hex2stdout(bp, bump, 1); else { switch (proto) { case TPROTO_SAS: @@ -2037,6 +2042,8 @@ decode_proto_port_vpd(uint8_t * buff, int len, int do_hex) continue; if (2 == do_hex) hex2stdout(bp + 8, desc_len, 1); + else if (do_hex > 2) + hex2stdout(bp, bump, 1); else { switch (proto) { case TPROTO_SAS: /* page added in spl3r02 */ diff --git a/src/sg_vpd_vendor.c b/src/sg_vpd_vendor.c index 9a73748..3c75177 100644 --- a/src/sg_vpd_vendor.c +++ b/src/sg_vpd_vendor.c @@ -1420,7 +1420,7 @@ svpd_decode_vendor(int sg_fd, struct opts_t * op, int off) if (0 == res) { vnp = svpd_get_v_detail(op->vpd_pn, op->vend_prod_num, 0xf & rp[0]); if (vnp && vnp->name) - snprintf(name, sizeof(name)/sizeof(char), "%s", vnp->name); + strcpy(name, vnp->name); else snprintf(name, sizeof(name) - 1, "Vendor VPD page=0x%x", op->vpd_pn); diff --git a/src/sg_write_x.c b/src/sg_write_x.c index d6949ed..3b8f091 100644 --- a/src/sg_write_x.c +++ b/src/sg_write_x.c @@ -671,10 +671,8 @@ parse_scat_pi_line(const char * lcp, uint8_t * up, uint32_t * sum_num) if (cp) { /* copy from first non whitespace ... */ memcpy(c, lcp, cp - lcp); /* ... to just prior to first '#' */ c[cp - lcp] = '\0'; - } else { - /* ... to end of line, including null */ - snprintf(c, sizeof(c)/sizeof(char), "%s", lcp); - } + } else + strcpy(c, lcp); /* ... to end of line, including null */ ll = sg_get_llnum(bp); ok = ((-1 != ll) || all_ascii_f_s(bp, 16)); if (! ok) { @@ -750,6 +748,10 @@ parse_scat_pi_line(const char * lcp, uint8_t * up, uint32_t * sum_num) } else if (up) sg_put_unaligned_be16((uint16_t)ll, up + 18); break; + default: + pr2serr("%s: k=%d should not be >= 3\n", __func__, k); + ok = false; + break; } if (! ok) break; @@ -770,9 +772,13 @@ parse_scat_pi_line(const char * lcp, uint8_t * up, uint32_t * sum_num) if (up) sg_put_unaligned_be16((uint16_t)DEF_TM, up + 18); break; + default: + pr2serr("%s: k=%d should not be >= 3\n", __func__, k); + ok = false; + break; } } - return 0; + return ok ? 0 : SG_LIB_SYNTAX_ERROR; } /* Read pairs or quintets from a scat_file and places them in a T10 scatter diff --git a/src/sg_xcopy.c b/src/sg_xcopy.c index 6230685..5facfc8 100644 --- a/src/sg_xcopy.c +++ b/src/sg_xcopy.c @@ -67,8 +67,6 @@ #include "sg_unaligned.h" #include "sg_pr2serr.h" -#include "misc.h" - static const char * version_str = "0.68 20180811"; #define ME "sg_xcopy: " @@ -343,7 +341,7 @@ open_sg(struct xcopy_fp_t * fp, int vb) } if (sg_simple_inquiry(fp->sg_fd, &sir, false, vb)) { pr2serr("INQUIRY failed on %s\n", ebuff); - _ignore_return(sg_cmds_close_device(fp->sg_fd)); + sg_cmds_close_device(fp->sg_fd); fp->sg_fd = -1; return -1; } @@ -417,7 +415,7 @@ dd_filetype_str(int ft, char * buff) if (FT_OTHER & ft) off += sg_scnpr(buff + off, 32, "other (perhaps ordinary file) "); if (FT_ERROR & ft) - _ignore_return(sg_scnpr(buff + off, 32, "unable to 'stat' file ")); + sg_scnpr(buff + off, 32, "unable to 'stat' file "); return buff; } @@ -642,7 +640,7 @@ scsi_extended_copy(int sg_fd, uint8_t list_id, DEF_GROUP_NUM, DEF_3PC_OUT_TIMEOUT, xcopyBuff, desc_offset, true, verb); if (res) { - _ignore_return(sg_get_category_sense_str(res, sizeof(b), b, verb)); + sg_get_category_sense_str(res, sizeof(b), b, verb); pr2serr("Xcopy(LID1): %s\n", b); } return res; @@ -662,7 +660,7 @@ scsi_read_capacity(struct xcopy_fp_t *xfp) res = sg_ll_readcap_10(xfp->sg_fd, false /* pmi */, 0, rcBuff, READ_CAP_REPLY_LEN, true, verb); if (0 != res) { - _ignore_return(sg_get_category_sense_str(res, sizeof(b), b, verb)); + sg_get_category_sense_str(res, sizeof(b), b, verb); pr2serr("Read capacity(10): %s\n", b); return res; } @@ -674,7 +672,7 @@ scsi_read_capacity(struct xcopy_fp_t *xfp) res = sg_ll_readcap_16(xfp->sg_fd, false /* pmi */, 0, rcBuff, RCAP16_REPLY_LEN, true, verb); if (0 != res) { - _ignore_return(sg_get_category_sense_str(res, sizeof(b), b, verb)); + sg_get_category_sense_str(res, sizeof(b), b, verb); pr2serr("Read capacity(16): %s\n", b); return res; } @@ -716,7 +714,7 @@ scsi_operating_parameter(struct xcopy_fp_t *xfp, int is_target) res = sg_ll_receive_copy_results(xfp->sg_fd, SA_COPY_OP_PARAMS, 0, rcBuff, rcBuffLen, true, verb); if (0 != res) { - _ignore_return(sg_get_category_sense_str(res, sizeof(b), b, verb)); + sg_get_category_sense_str(res, sizeof(b), b, verb); pr2serr("Xcopy operating parameters: %s\n", b); return -res; } @@ -1008,8 +1006,8 @@ decode_designation_descriptor(const uint8_t * bp, int i_len) { char c[2048]; - _ignore_return(sg_get_designation_descriptor_str(NULL, bp, i_len, 1, - verbose, sizeof(c), c)); + sg_get_designation_descriptor_str(NULL, bp, i_len, 1, verbose, + sizeof(c), c); pr2serr("%s", c); } @@ -1031,8 +1029,7 @@ desc_from_vpd_id(int sg_fd, uint8_t *desc, int desc_len, if (SG_LIB_CAT_ILLEGAL_REQ == res) pr2serr("Device identification VPD page not found\n"); else { - _ignore_return(sg_get_category_sense_str(res, sizeof(b), b, - verbose)); + sg_get_category_sense_str(res, sizeof(b), b, verbose); pr2serr("VPD inquiry (Device ID): %s\n", b); pr2serr(" try again with '-vv'\n"); } @@ -1045,7 +1042,7 @@ desc_from_vpd_id(int sg_fd, uint8_t *desc, int desc_len, res = sg_ll_inquiry(sg_fd, false, true, VPD_DEVICE_ID, rcBuff, len, true, verb); if (0 != res) { - _ignore_return(sg_get_category_sense_str(res, sizeof(b), b, verbose)); + sg_get_category_sense_str(res, sizeof(b), b, verbose); pr2serr("VPD inquiry (Device ID): %s\n", b); return res; } else if (rcBuff[1] != VPD_DEVICE_ID) { diff --git a/src/sginfo.c b/src/sginfo.c index 9c626ee..bddc964 100644 --- a/src/sginfo.c +++ b/src/sginfo.c @@ -1757,7 +1757,6 @@ trytenbyte: } else if (!sorthead) printf("|"); } - /* fall through */ case 5: /* physical sector */ while (len > 0) { snprintf((char *)cbuffer1, 40, "%6d:%2u:%5d", @@ -1776,7 +1775,6 @@ trytenbyte: } else if (!sorthead) printf("|"); } - /* fall through */ case 0: /* lba (32 bit) */ while (len > 0) { printf("%10d", getnbyte(df, 4)); @@ -1790,7 +1788,6 @@ trytenbyte: else printf("|"); } - /* fall through */ case 3: /* lba (64 bit) */ while (len > 0) { printf("%15" PRId64 , getnbyte_ll(df, 8)); @@ -1828,7 +1825,6 @@ trytenbyte: } } printf("\n"); - free(headsp); return status; }