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>
This commit is contained in:
Elyes Haouas 2023-11-07 18:37:33 +01:00 committed by Warner Losh
parent c3c816173d
commit 7028e630d6
3 changed files with 10 additions and 12 deletions

View file

@ -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;

View file

@ -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 @@ epc_getmode(struct cam_device *device, camcontrol_devtype devtype,
}
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;

View file

@ -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;