Skip to content

Commit

Permalink
camcontrol: Use nitems(foo) instead of sizeof(foo)/sizeof(foo[0])
Browse files Browse the repository at this point in the history
Pull Request: #888
Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
  • Loading branch information
ElyesH authored and bsdimp committed Apr 29, 2024
1 parent c3c8161 commit 7028e63
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions sbin/camcontrol/attrib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 5 additions & 6 deletions sbin/camcontrol/epc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions sbin/camcontrol/zone.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7028e63

Please sign in to comment.