git: 169c76b9b65f - stable/14 - camcontrol: Use nitems(foo) instead of sizeof(foo)/sizeof(foo[0])

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Tue, 27 Aug 2024 18:07:14 UTC
The branch stable/14 has been updated by jhb:

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

commit 169c76b9b65f97043af32058a86ceda8da4375fe
Author:     Elyes Haouas <ehaouas@noos.fr>
AuthorDate: 2023-11-07 17:37:33 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2024-08-27 16:35:34 +0000

    camcontrol: Use nitems(foo) instead of sizeof(foo)/sizeof(foo[0])
    
    Pull Request: https://github.com/freebsd/freebsd-src/pull/888
    Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
    (cherry picked from commit 7028e630d6110789502cfc0f17b36b6f513ec297)
---
 sbin/camcontrol/attrib.c |  4 ++--
 sbin/camcontrol/epc.c    | 11 +++++------
 sbin/camcontrol/zone.c   |  7 +++----
 3 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/sbin/camcontrol/attrib.c b/sbin/camcontrol/attrib.c
index 7e89dbc3d48e..4cf9832756b4 100644
--- a/sbin/camcontrol/attrib.c
+++ b/sbin/camcontrol/attrib.c
@@ -36,7 +36,7 @@
 #include <sys/cdefs.h>
 #include <sys/ioctl.h>
 #include <sys/stdint.h>
-#include <sys/types.h>
+#include <sys/param.h>
 #include <sys/endian.h>
 #include <sys/sbuf.h>
 #include <sys/queue.h>
@@ -265,7 +265,7 @@ scsiattrib(struct cam_device *device, int argc, char **argv, char *combinedopt,
 			int entry_num = 0;
 
 			status = scsi_get_nv(elem_type_map,
-			    sizeof(elem_type_map) / sizeof(elem_type_map[0]),
+			    nitems(elem_type_map),
 			    optarg, &entry_num, SCSI_NV_FLAG_IG_CASE);
 			if (status == SCSI_NV_FOUND)
 				element_type = elem_type_map[entry_num].value;
diff --git a/sbin/camcontrol/epc.c b/sbin/camcontrol/epc.c
index 206b34594f4f..4273ad19047c 100644
--- a/sbin/camcontrol/epc.c
+++ b/sbin/camcontrol/epc.c
@@ -33,10 +33,9 @@
  * ATA Extended Power Conditions (EPC) support
  */
 
-#include <sys/cdefs.h>
+#include <sys/param.h>
 #include <sys/ioctl.h>
 #include <sys/stdint.h>
-#include <sys/types.h>
 #include <sys/endian.h>
 #include <sys/sbuf.h>
 #include <sys/queue.h>
@@ -151,7 +150,7 @@ epc_print_pcl_desc(struct ata_power_cond_log_desc *desc, const char *prefix)
 	max_chars = 75;
 
 	num_printed = printf("%sFlags: ", prefix);
-	for (i = 0; i < (sizeof(epc_flags) / sizeof(epc_flags[0])); i++) {
+	for (i = 0; i < nitems(epc_flags); i++) {
 		if ((desc->flags & epc_flags[i].value) == 0)
 			continue;
 		if (first == 0) {
@@ -466,7 +465,7 @@ check_power_mode:
 	}
 
 	mode_name = scsi_nv_to_str(epc_power_cond_map,
-	    sizeof(epc_power_cond_map) / sizeof(epc_power_cond_map[0]), count);
+	    nitems(epc_power_cond_map), count);
 	printf("Current power state: ");
 	/* Note: ident can be null in power_only mode */
 	if ((ident == NULL)
@@ -638,7 +637,7 @@ epc(struct cam_device *device, int argc, char **argv, char *combinedopt,
 			int entry_num;
 
 			status = scsi_get_nv(epc_cmd_map,
-			    (sizeof(epc_cmd_map) / sizeof(epc_cmd_map[0])),
+			    nitems(epc_cmd_map),
 			    optarg, &entry_num, SCSI_NV_FLAG_IG_CASE);
 			if (status == SCSI_NV_FOUND)
 				action = epc_cmd_map[entry_num].value;
@@ -715,7 +714,7 @@ epc(struct cam_device *device, int argc, char **argv, char *combinedopt,
 			int entry_num;
 			
 			status = scsi_get_nv(epc_ps_map,
-			    (sizeof(epc_ps_map) / sizeof(epc_ps_map[0])),
+			    nitems(epc_ps_map),
 			    optarg, &entry_num, SCSI_NV_FLAG_IG_CASE);
 			if (status == SCSI_NV_FOUND)
 				power_src = epc_ps_map[entry_num].value;
diff --git a/sbin/camcontrol/zone.c b/sbin/camcontrol/zone.c
index d651ca0e2acf..dc87cd9a9570 100644
--- a/sbin/camcontrol/zone.c
+++ b/sbin/camcontrol/zone.c
@@ -34,10 +34,9 @@
  * This is an implementation of the SCSI ZBC and ATA ZAC specs.
  */
 
-#include <sys/cdefs.h>
+#include <sys/param.h>
 #include <sys/ioctl.h>
 #include <sys/stdint.h>
-#include <sys/types.h>
 #include <sys/endian.h>
 #include <sys/sbuf.h>
 #include <sys/queue.h>
@@ -353,7 +352,7 @@ zone(struct cam_device *device, int argc, char **argv, char *combinedopt,
 			int entry_num;
 
 			status = scsi_get_nv(zone_cmd_map,
-			    (sizeof(zone_cmd_map) / sizeof(zone_cmd_map[0])),
+			    nitems(zone_cmd_map),
 			    optarg, &entry_num, SCSI_NV_FLAG_IG_CASE);
 			if (status == SCSI_NV_FOUND)
 				action = zone_cmd_map[entry_num].value;
@@ -387,7 +386,7 @@ zone(struct cam_device *device, int argc, char **argv, char *combinedopt,
 			int entry_num;
 
 			status = scsi_get_nv(zone_rep_opts,
-			    (sizeof(zone_rep_opts) /sizeof(zone_rep_opts[0])),
+			    nitems(zone_rep_opts),
 			    optarg, &entry_num, SCSI_NV_FLAG_IG_CASE);
 			if (status == SCSI_NV_FOUND)
 				rep_option = zone_rep_opts[entry_num].value;