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
This commit is contained in:
Warner Losh 2023-06-19 14:43:30 -06:00
parent f20d86e171
commit 2e105b61e9

View File

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