git: f20d86e17143 - main - camcontrol: No need to set CAM_ARG_[PG]LIST in defects

From: Warner Losh <imp_at_FreeBSD.org>
Date: Mon, 19 Jun 2023 20:47:07 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=f20d86e1714365ae4d098d101aac302a3572eb1d

commit f20d86e1714365ae4d098d101aac302a3572eb1d
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2023-06-19 20:43:12 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2023-06-19 20:45:43 +0000

    camcontrol: No need to set CAM_ARG_[PG]LIST in defects
    
    We can or in the the list_format bits directly if we or in the
    list_format when we look it up the first time. Free up CAM_ARG_[PG]LIST
    from the CAM_ARG_xxx enum.
    
    Sponsored by:           Netflix
    Reviewed by:            mav (I made his suggested change)
    Differential Revision:  https://reviews.freebsd.org/D40523
---
 sbin/camcontrol/camcontrol.c | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)

diff --git a/sbin/camcontrol/camcontrol.c b/sbin/camcontrol/camcontrol.c
index c059d64652c5..487d0d64a969 100644
--- a/sbin/camcontrol/camcontrol.c
+++ b/sbin/camcontrol/camcontrol.c
@@ -126,8 +126,8 @@ typedef enum {
 			/* unused 0x00000080 */
 			/* unused 0x00000100 */
 			/* unused 0x00000200 */
-	CAM_ARG_PLIST		= 0x00000400,
-	CAM_ARG_GLIST		= 0x00000800,
+			/* unused 0x00000400 */
+			/* unused 0x00000800 */
 	CAM_ARG_GET_SERIAL	= 0x00001000,
 	CAM_ARG_GET_STDINQ	= 0x00002000,
 	CAM_ARG_GET_XFERRATE	= 0x00004000,
@@ -3849,13 +3849,19 @@ readdefects(struct cam_device *device, int argc, char **argv,
 			scsi_nv_status status;
 			int entry_num = 0;
 
+			if (list_type_set) {
+				warnx("%s: -f specified twice", __func__);
+				error = 1;
+				goto defect_bailout;
+			}
+
 			status = scsi_get_nv(defect_list_type_map,
 			    sizeof(defect_list_type_map) /
 			    sizeof(defect_list_type_map[0]), optarg,
 			    &entry_num, SCSI_NV_FLAG_IG_CASE);
 
 			if (status == SCSI_NV_FOUND) {
-				list_format = defect_list_type_map[
+				list_format |= defect_list_type_map[
 				    entry_num].value;
 				list_type_set = true;
 			} else {
@@ -3869,10 +3875,12 @@ readdefects(struct cam_device *device, int argc, char **argv,
 			break;
 		}
 		case 'G':
-			arglist |= CAM_ARG_GLIST;
+			list_format |= SRDD10_GLIST;
+			lists_specified++;
 			break;
 		case 'P':
-			arglist |= CAM_ARG_PLIST;
+			list_format |= SRDD10_PLIST;
+			lists_specified++;
 			break;
 		case 'q':
 			quiet = true;
@@ -3905,16 +3913,6 @@ readdefects(struct cam_device *device, int argc, char **argv,
 		goto defect_bailout;
 	}
 
-	if (arglist & CAM_ARG_PLIST) {
-		list_format |= SRDD10_PLIST;
-		lists_specified++;
-	}
-
-	if (arglist & CAM_ARG_GLIST) {
-		list_format |= SRDD10_GLIST;
-		lists_specified++;
-	}
-
 	/*
 	 * This implies a summary, and was the previous behavior.
 	 */