git: 2e105b61e98d - main - camcontrol: simplify summary logic for defects

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

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

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

    camcontrol: simplify summary logic for defects
    
    We don't need to count the number of lists requested. Instead, use the
    more general form of checking to see if any of the non-defect format
    bits are set. Also, check summary boolean to control summary reporting
    behavior.
    
    Sponsored by:           Netflix
    Reviewed by:            mav
    Differential Revision:  https://reviews.freebsd.org/D40524
---
 sbin/camcontrol/camcontrol.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/sbin/camcontrol/camcontrol.c b/sbin/camcontrol/camcontrol.c
index 487d0d64a969..45b769589da8 100644
--- a/sbin/camcontrol/camcontrol.c
+++ b/sbin/camcontrol/camcontrol.c
@@ -3837,7 +3837,7 @@ readdefects(struct cam_device *device, int argc, char **argv,
 	u_int8_t returned_format, returned_type;
 	unsigned int i;
 	int c, error = 0;
-	int mads = 0, lists_specified = 0;
+	int mads = 0;
 	bool summary = false, quiet = false, list_type_set = false;
 	bool get_length = true, use_12byte = false, first_pass = true;
 	bool hex_format = false;
@@ -3876,11 +3876,9 @@ readdefects(struct cam_device *device, int argc, char **argv,
 		}
 		case 'G':
 			list_format |= SRDD10_GLIST;
-			lists_specified++;
 			break;
 		case 'P':
 			list_format |= SRDD10_PLIST;
-			lists_specified++;
 			break;
 		case 'q':
 			quiet = true;
@@ -3916,7 +3914,7 @@ readdefects(struct cam_device *device, int argc, char **argv,
 	/*
 	 * This implies a summary, and was the previous behavior.
 	 */
-	if (lists_specified == 0)
+	if ((list_format & ~SRDD10_DLIST_FORMAT_MASK) == 0)
 		summary = true;
 
 	ccb = cam_getccb(device);
@@ -4215,7 +4213,7 @@ next_batch:
 	if (first_pass) {
 		fprintf(stderr, "Got %d defect", num_returned);
 
-		if ((lists_specified == 0) || (num_returned == 0)) {
+		if (!summary || (num_returned == 0)) {
 			fprintf(stderr, "s.\n");
 			goto defect_bailout;
 		} else if (num_returned == 1)