Skip to contentSkip to conversation

(1/5) aic7xyz: use kernel.h min/max/ARRAY_SIZE

janitor Randy.Dunlap 3 participants 4 messages Apr 27, 2004 – May 3, 2004

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

From: Michael Veeck <[email protected]>
Subject: [Kernel-janitors] [PATCH] drivers/scsi/aic7xxxx MIN/MAX/NUM_ELEMENTS
removal

Patch (against 2.6.6-rc1) removes unnecessary min/max/num_elements macros and changes calls to use kernel.h macros instead.

 drivers/scsi/aic7xxx/aic7770.c      |    2 +-
 drivers/scsi/aic7xxx/aic79xx.h      |   10 ----------
 drivers/scsi/aic7xxx/aic79xx_core.c |   30 +++++++++++++++---------------
 drivers/scsi/aic7xxx/aic79xx_osm.c  |   32 ++++++++++++++++----------------
 drivers/scsi/aic7xxx/aic79xx_pci.c  |    2 +-
 drivers/scsi/aic7xxx/aic7xxx.h      |   10 ----------
 drivers/scsi/aic7xxx/aic7xxx_core.c |   24 ++++++++++++------------
 drivers/scsi/aic7xxx/aic7xxx_osm.c  |   22 +++++++++++-----------
 drivers/scsi/aic7xxx/aic7xxx_pci.c  |    2 +-
 9 files changed, 57 insertions(+), 77 deletions(-)
drivers/scsi/aic7xxx/aic7770.c +1 -1
Index: linux-266-rc2-kj1/drivers/scsi/aic7xxx/aic7770.c
===================================================================
@@ -107,7 +107,7 @@ struct aic7770_identity aic7770_ident_ta
 		ahc_aic7770_EISA_setup
 	}
 };
-const int ahc_num_aic7770_devs = NUM_ELEMENTS(aic7770_ident_table);
+const int ahc_num_aic7770_devs = ARRAY_SIZE(aic7770_ident_table);
 
 struct aic7770_identity *
 aic7770_find_device(uint32_t id)
drivers/scsi/aic7xxx/aic79xx_core.c +15 -15
Index: linux-266-rc2-kj1/drivers/scsi/aic7xxx/aic79xx_core.c
===================================================================
@@ -63,7 +63,7 @@ char *ahd_chip_names[] =
 	"aic7902",
 	"aic7901A"
 };
-static const u_int num_chip_names = NUM_ELEMENTS(ahd_chip_names);
+static const u_int num_chip_names = ARRAY_SIZE(ahd_chip_names);
 
 /*
  * Hardware error codes.
@@ -81,7 +81,7 @@ static struct ahd_hard_error_entry ahd_h
 	{ MPARERR,	"Scratch or SCB Memory Parity Error" },
 	{ CIOPARERR,	"CIOBUS Parity Error" },
 };
-static const u_int num_errors = NUM_ELEMENTS(ahd_hard_errors);
+static const u_int num_errors = ARRAY_SIZE(ahd_hard_errors);
 
 static struct ahd_phase_table_entry ahd_phase_table[] =
 {
@@ -101,7 +101,7 @@ static struct ahd_phase_table_entry ahd_
  * In most cases we only wish to itterate over real phases, so
  * exclude the last element from the count.
  */
-static const u_int num_phases = NUM_ELEMENTS(ahd_phase_table) - 1;
+static const u_int num_phases = ARRAY_SIZE(ahd_phase_table) - 1;
 
 /* Our Sequencer Program */
 #include "aic79xx_seq.h"
@@ -2769,14 +2769,14 @@ ahd_devlimited_syncrate(struct ahd_softc
 		transinfo = &tinfo->goal;
 	*ppr_options &= (transinfo->ppr_options|MSG_EXT_PPR_PCOMP_EN);
 	if (transinfo->width == MSG_EXT_WDTR_BUS_8_BIT) {
-		maxsync = MAX(maxsync, AHD_SYNCRATE_ULTRA2);
+		maxsync = max_t(u_int, maxsync, AHD_SYNCRATE_ULTRA2);
 		*ppr_options &= ~MSG_EXT_PPR_DT_REQ;
 	}
 	if (transinfo->period == 0) {
 		*period = 0;
 		*ppr_options = 0;
 	} else {
-		*period = MAX(*period, transinfo->period);
+		*period = max_t(u_int, *period, transinfo->period);
 		ahd_find_syncrate(ahd, period, ppr_options, maxsync);
 	}
 }
@@ -2843,12 +2843,12 @@ ahd_validate_offset(struct ahd_softc *ah
 			maxoffset = MAX_OFFSET_PACED;
 	} else
 		maxoffset = MAX_OFFSET_NON_PACED;
-	*offset = MIN(*offset, maxoffset);
+	*offset = min(*offset, maxoffset);
 	if (tinfo != NULL) {
 		if (role == ROLE_TARGET)
-			*offset = MIN(*offset, tinfo->user.offset);
+			*offset = min_t(u_int, *offset, tinfo->user.offset);
 		else
-			*offset = MIN(*offset, tinfo->goal.offset);
+			*offset = min_t(u_int, *offset, tinfo->goal.offset);
 	}
 }
 
@@ -2874,9 +2874,9 @@ ahd_validate_width(struct ahd_softc *ahd
 	}
 	if (tinfo != NULL) {
 		if (role == ROLE_TARGET)
-			*bus_width = MIN(tinfo->user.width, *bus_width);
+			*bus_width = min_t(u_int, tinfo->user.width, *bus_width);
 		else
-			*bus_width = MIN(tinfo->goal.width, *bus_width);
+			*bus_width = min_t(u_int, tinfo->goal.width, *bus_width);
 	}
 }
 
@@ -6043,9 +6043,9 @@ ahd_alloc_scbs(struct ahd_softc *ahd)
 #endif
 	}
 
-	newcount = MIN(scb_data->sense_left, scb_data->scbs_left);
-	newcount = MIN(newcount, scb_data->sgs_left);
-	newcount = MIN(newcount, (AHD_SCB_MAX_ALLOC - scb_data->numscbs));
+	newcount = min(scb_data->sense_left, scb_data->scbs_left);
+	newcount = min(newcount, scb_data->sgs_left);
+	newcount = min(newcount, (AHD_SCB_MAX_ALLOC - scb_data->numscbs));
 	scb_data->sense_left -= newcount;
 	scb_data->scbs_left -= newcount;
 	scb_data->sgs_left -= newcount;
@@ -7256,7 +7256,7 @@ ahd_qinfifo_count(struct ahd_softc *ahd)
 		return (wrap_qinfifonext - wrap_qinpos);
 	else
 		return (wrap_qinfifonext
-		      + NUM_ELEMENTS(ahd->qinfifo) - wrap_qinpos);
+		      + ARRAY_SIZE(ahd->qinfifo) - wrap_qinpos);
 }
 
 void
@@ -8632,7 +8632,7 @@ ahd_resolve_seqaddr(struct ahd_softc *ah
 		if (skip_addr > i) {
 			int end_addr;
 
-			end_addr = MIN(address, skip_addr);
+			end_addr = min(address, skip_addr);
 			address_offset += end_addr - i;
 			i = skip_addr;
 		} else {
drivers/scsi/aic7xxx/aic79xx.h +0 -10
Index: linux-266-rc2-kj1/drivers/scsi/aic7xxx/aic79xx.h
===================================================================
@@ -53,14 +53,6 @@ struct ahd_platform_data;
 struct scb_platform_data;
 
 /****************************** Useful Macros *********************************/
-#ifndef MAX
-#define MAX(a,b) (((a) > (b)) ? (a) : (b))
-#endif
-
-#ifndef MIN
-#define MIN(a,b) (((a) < (b)) ? (a) : (b))
-#endif
-
 #ifndef TRUE
 #define TRUE 1
 #endif
@@ -68,8 +60,6 @@ struct scb_platform_data;
 #define FALSE 0
 #endif
 
-#define NUM_ELEMENTS(array) (sizeof(array) / sizeof(*array))
-
 #define ALL_CHANNELS '\0'
 #define ALL_TARGETS_MASK 0xFFFF
 #define INITIATOR_WILDCARD	(~0)
drivers/scsi/aic7xxx/aic79xx_osm.c +16 -16
Index: linux-266-rc2-kj1/drivers/scsi/aic7xxx/aic79xx_osm.c
===================================================================
@@ -1914,7 +1914,7 @@ ahd_linux_setup_tag_info(u_long arg, int
 {
 
 	if ((instance >= 0) && (targ >= 0)
-	 && (instance < NUM_ELEMENTS(aic79xx_tag_info))
+	 && (instance < ARRAY_SIZE(aic79xx_tag_info))
 	 && (targ < AHD_NUM_TARGETS)) {
 		aic79xx_tag_info[instance].tag_commands[targ] = value & 0x1FF;
 		if (bootverbose)
@@ -1926,7 +1926,7 @@ static void
 ahd_linux_setup_rd_strm_info(u_long arg, int instance, int targ, int32_t value)
 {
 	if ((instance >= 0)
-	 && (instance < NUM_ELEMENTS(aic79xx_rd_strm_info))) {
+	 && (instance < ARRAY_SIZE(aic79xx_rd_strm_info))) {
 		aic79xx_rd_strm_info[instance] = value & 0xFFFF;
 		if (bootverbose)
 			printf("rd_strm[%d] = 0x%x\n", instance, value);
@@ -1937,7 +1937,7 @@ static void
 ahd_linux_setup_dv(u_long arg, int instance, int targ, int32_t value)
 {
 	if ((instance >= 0)
-	 && (instance < NUM_ELEMENTS(aic79xx_dv_settings))) {
+	 && (instance < ARRAY_SIZE(aic79xx_dv_settings))) {
 		aic79xx_dv_settings[instance] = value;
 		if (bootverbose)
 			printf("dv[%d] = %d\n", instance, value);
@@ -1949,7 +1949,7 @@ ahd_linux_setup_iocell_info(u_long index
 {
 
 	if ((instance >= 0)
-	 && (instance < NUM_ELEMENTS(aic79xx_iocell_info))) {
+	 && (instance < ARRAY_SIZE(aic79xx_iocell_info))) {
 		uint8_t *iocell_info;
 
 		iocell_info = (uint8_t*)&aic79xx_iocell_info[instance];
@@ -1967,7 +1967,7 @@ ahd_linux_setup_tag_info_global(char *p)
 	tags = simple_strtoul(p + 1, NULL, 0) & 0xff;
 	printf("Setting Global Tags= %d\n", tags);
 
-	for (i = 0; i < NUM_ELEMENTS(aic79xx_tag_info); i++) {
+	for (i = 0; i < ARRAY_SIZE(aic79xx_tag_info); i++) {
 		for (j = 0; j < AHD_NUM_TARGETS; j++) {
 			aic79xx_tag_info[i].tag_commands[j] = tags;
 		}
@@ -2013,7 +2013,7 @@ aic79xx_setup(char *s)
 	end = strchr(s, '\0');
 
 	/*
-	 * XXX ia64 gcc isn't smart enough to know that NUM_ELEMENTS
+	 * XXX ia64 gcc isn't smart enough to know that ARRAY_SIZE
 	 * will never be 0 in this case.
 	 */      
 	n = 0;  
@@ -2021,13 +2021,13 @@ aic79xx_setup(char *s)
 	while ((p = strsep(&s, ",.")) != NULL) {
 		if (*p == '\0')
 			continue;
-		for (i = 0; i < NUM_ELEMENTS(options); i++) {
+		for (i = 0; i < ARRAY_SIZE(options); i++) {
 
 			n = strlen(options[i].name);
 			if (strncmp(options[i].name, p, n) == 0)
 				break;
 		}
-		if (i == NUM_ELEMENTS(options))
+		if (i == ARRAY_SIZE(options))
 			continue;
 
 		if (strncmp(p, "global_tag_depth", n) == 0) {
@@ -2356,7 +2356,7 @@ ahd_platform_init(struct ahd_softc *ahd)
 	/*
 	 * Lookup and commit any modified IO Cell options.
 	 */
-	if (ahd->unit < NUM_ELEMENTS(aic79xx_iocell_info)) {
+	if (ahd->unit < ARRAY_SIZE(aic79xx_iocell_info)) {
 		struct ahd_linux_iocell_opts *iocell_opts;
 
 		iocell_opts = &aic79xx_iocell_info[ahd->unit];
@@ -3597,7 +3597,7 @@ ahd_linux_fallback(struct ahd_softc *ahd
 	if (offset == 0)
 		period = AHD_ASYNC_XFER_PERIOD;
 	if (targ->dv_next_narrow_period == 0)
-		targ->dv_next_narrow_period = MAX(period, AHD_SYNCRATE_ULTRA2);
+		targ->dv_next_narrow_period = max_t(uint8_t, period, AHD_SYNCRATE_ULTRA2);
 	if (targ->dv_next_wide_period == 0)
 		targ->dv_next_wide_period = period;
 	if (targ->dv_max_width == 0)
@@ -3879,7 +3879,7 @@ ahd_linux_user_tagdepth(struct ahd_softc
 
 	tags = 0;
 	if ((ahd->user_discenable & devinfo->target_mask) != 0) {
-		if (ahd->unit >= NUM_ELEMENTS(aic79xx_tag_info)) {
+		if (ahd->unit >= ARRAY_SIZE(aic79xx_tag_info)) {
 
 			if (warned_user == 0) {
 				printf(KERN_WARNING
@@ -3908,7 +3908,7 @@ ahd_linux_user_dv_setting(struct ahd_sof
 	static int warned_user;
 	int dv;
 
-	if (ahd->unit >= NUM_ELEMENTS(aic79xx_dv_settings)) {
+	if (ahd->unit >= ARRAY_SIZE(aic79xx_dv_settings)) {
 
 		if (warned_user == 0) {
 			printf(KERN_WARNING
@@ -3946,7 +3946,7 @@ ahd_linux_setup_user_rd_strm_settings(st
 	 * If we have specific read streaming info for this controller,
 	 * apply it.  Otherwise use the defaults.
 	 */
-	 if (ahd->unit >= NUM_ELEMENTS(aic79xx_rd_strm_info)) {
+	 if (ahd->unit >= ARRAY_SIZE(aic79xx_rd_strm_info)) {
 
 		if (warned_user == 0) {
 
@@ -4582,7 +4582,7 @@ ahd_linux_handle_scsi_status(struct ahd_
 			u_int sense_offset;
 
 			if (scb->flags & SCB_SENSE) {
-				sense_size = MIN(sizeof(struct scsi_sense_data)
+				sense_size = min_t(u_int, sizeof(struct scsi_sense_data)
 					       - ahd_get_sense_residual(scb),
 						 sizeof(cmd->sense_buffer));
 				sense_offset = 0;
@@ -4593,7 +4593,7 @@ ahd_linux_handle_scsi_status(struct ahd_
 				 */
 				siu = (struct scsi_status_iu_header *)
 				    scb->sense_data;
-				sense_size = MIN(scsi_4btoul(siu->sense_length),
+				sense_size = min(scsi_4btoul(siu->sense_length),
 						sizeof(cmd->sense_buffer));
 				sense_offset = SIU_SENSE_OFFSET(siu);
 			}
@@ -4914,7 +4914,7 @@ ahd_linux_filter_inquiry(struct ahd_soft
 	offset = user->offset;
 	ppr_options = user->ppr_options;
 	trans_version = user->transport_version;
-	prot_version = MIN(user->protocol_version, SID_ANSI_REV(sid));
+	prot_version = min_t(u_int, user->protocol_version, SID_ANSI_REV(sid));
 
 	/*
 	 * Only attempt SPI3/4 once we've verified that
drivers/scsi/aic7xxx/aic79xx_pci.c +1 -1
Index: linux-266-rc2-kj1/drivers/scsi/aic7xxx/aic79xx_pci.c
===================================================================
@@ -229,7 +229,7 @@ struct ahd_pci_identity ahd_pci_ident_ta
 	}
 };
 
-const u_int ahd_num_pci_devs = NUM_ELEMENTS(ahd_pci_ident_table);
+const u_int ahd_num_pci_devs = ARRAY_SIZE(ahd_pci_ident_table);
 		
 #define	DEVCONFIG		0x40
 #define		PCIXINITPAT	0x0000E000ul
drivers/scsi/aic7xxx/aic7xxx_core.c +12 -12
Index: linux-266-rc2-kj1/drivers/scsi/aic7xxx/aic7xxx_core.c
===================================================================
@@ -73,7 +73,7 @@ char *ahc_chip_names[] =
 	"aic7892",
 	"aic7899"
 };
-static const u_int num_chip_names = NUM_ELEMENTS(ahc_chip_names);
+static const u_int num_chip_names = ARRAY_SIZE(ahc_chip_names);
 
 /*
  * Hardware error codes.
@@ -93,7 +93,7 @@ static struct ahc_hard_error_entry ahc_h
 	{ PCIERRSTAT,	"PCI Error detected" },
 	{ CIOPARERR,	"CIOBUS Parity Error" },
 };
-static const u_int num_errors = NUM_ELEMENTS(ahc_hard_errors);
+static const u_int num_errors = ARRAY_SIZE(ahc_hard_errors);
 
 static struct ahc_phase_table_entry ahc_phase_table[] =
 {
@@ -113,7 +113,7 @@ static struct ahc_phase_table_entry ahc_
  * In most cases we only wish to itterate over real phases, so
  * exclude the last element from the count.
  */
-static const u_int num_phases = NUM_ELEMENTS(ahc_phase_table) - 1;
+static const u_int num_phases = ARRAY_SIZE(ahc_phase_table) - 1;
 
 /*
  * Valid SCSIRATE values.  (p. 3-17)
@@ -1666,7 +1666,7 @@ ahc_devlimited_syncrate(struct ahc_softc
 		transinfo = &tinfo->goal;
 	*ppr_options &= transinfo->ppr_options;
 	if (transinfo->width == MSG_EXT_WDTR_BUS_8_BIT) {
-		maxsync = MAX(maxsync, AHC_SYNCRATE_ULTRA2);
+		maxsync = max_t(u_int, maxsync, AHC_SYNCRATE_ULTRA2);
 		*ppr_options &= ~MSG_EXT_PPR_DT_REQ;
 	}
 	if (transinfo->period == 0) {
@@ -1674,7 +1674,7 @@ ahc_devlimited_syncrate(struct ahc_softc
 		*ppr_options = 0;
 		return (NULL);
 	}
-	*period = MAX(*period, transinfo->period);
+	*period = max_t(u_int, *period, transinfo->period);
 	return (ahc_find_syncrate(ahc, period, ppr_options, maxsync));
 }
 
@@ -1799,12 +1799,12 @@ ahc_validate_offset(struct ahc_softc *ah
 		else
 			maxoffset = MAX_OFFSET_8BIT;
 	}
-	*offset = MIN(*offset, maxoffset);
+	*offset = min(*offset, maxoffset);
 	if (tinfo != NULL) {
 		if (role == ROLE_TARGET)
-			*offset = MIN(*offset, tinfo->user.offset);
+			*offset = min_t(u_int, *offset, tinfo->user.offset);
 		else
-			*offset = MIN(*offset, tinfo->goal.offset);
+			*offset = min_t(u_int, *offset, tinfo->goal.offset);
 	}
 }
 
@@ -1830,9 +1830,9 @@ ahc_validate_width(struct ahc_softc *ahc
 	}
 	if (tinfo != NULL) {
 		if (role == ROLE_TARGET)
-			*bus_width = MIN(tinfo->user.width, *bus_width);
+			*bus_width = min_t(u_int, tinfo->user.width, *bus_width);
 		else
-			*bus_width = MIN(tinfo->goal.width, *bus_width);
+			*bus_width = min_t(u_int, tinfo->goal.width, *bus_width);
 	}
 }
 
@@ -4491,7 +4491,7 @@ ahc_alloc_scbs(struct ahc_softc *ahc)
 	physaddr = sg_map->sg_physaddr;
 
 	newcount = (PAGE_SIZE / (AHC_NSEG * sizeof(struct ahc_dma_seg)));
-	newcount = MIN(newcount, (AHC_SCB_MAX_ALLOC - scb_data->numscbs));
+	newcount = min(newcount, (AHC_SCB_MAX_ALLOC - scb_data->numscbs));
 	for (i = 0; i < newcount; i++) {
 		struct scb_platform_data *pdata;
 #ifndef __linux__
@@ -6518,7 +6518,7 @@ ahc_download_instr(struct ahc_softc *ahc
 			if (skip_addr > i) {
 				int end_addr;
 
-				end_addr = MIN(address, skip_addr);
+				end_addr = min(address, skip_addr);
 				address_offset += end_addr - i;
 				i = skip_addr;
 			} else {
drivers/scsi/aic7xxx/aic7xxx.h +0 -10
Index: linux-266-rc2-kj1/drivers/scsi/aic7xxx/aic7xxx.h
===================================================================
@@ -54,14 +54,6 @@ struct scb_platform_data;
 struct seeprom_descriptor;
 
 /****************************** Useful Macros *********************************/
-#ifndef MAX
-#define MAX(a,b) (((a) > (b)) ? (a) : (b))
-#endif
-
-#ifndef MIN
-#define MIN(a,b) (((a) < (b)) ? (a) : (b))
-#endif
-
 #ifndef TRUE
 #define TRUE 1
 #endif
@@ -69,8 +61,6 @@ struct seeprom_descriptor;
 #define FALSE 0
 #endif
 
-#define NUM_ELEMENTS(array) (sizeof(array) / sizeof(*array))
-
 #define ALL_CHANNELS '\0'
 #define ALL_TARGETS_MASK 0xFFFF
 #define INITIATOR_WILDCARD	(~0)
drivers/scsi/aic7xxx/aic7xxx_osm.c +11 -11
Index: linux-266-rc2-kj1/drivers/scsi/aic7xxx/aic7xxx_osm.c
===================================================================
@@ -1589,7 +1589,7 @@ ahc_linux_setup_tag_info_global(char *p)
 	tags = simple_strtoul(p + 1, NULL, 0) & 0xff;
 	printf("Setting Global Tags= %d\n", tags);
 
-	for (i = 0; i < NUM_ELEMENTS(aic7xxx_tag_info); i++) {
+	for (i = 0; i < ARRAY_SIZE(aic7xxx_tag_info); i++) {
 		for (j = 0; j < AHC_NUM_TARGETS; j++) {
 			aic7xxx_tag_info[i].tag_commands[j] = tags;
 		}
@@ -1601,7 +1601,7 @@ ahc_linux_setup_tag_info(u_long arg, int
 {
 
 	if ((instance >= 0) && (targ >= 0)
-	 && (instance < NUM_ELEMENTS(aic7xxx_tag_info))
+	 && (instance < ARRAY_SIZE(aic7xxx_tag_info))
 	 && (targ < AHC_NUM_TARGETS)) {
 		aic7xxx_tag_info[instance].tag_commands[targ] = value & 0xff;
 		if (bootverbose)
@@ -1614,7 +1614,7 @@ ahc_linux_setup_dv(u_long arg, int insta
 {
 
 	if ((instance >= 0)
-	 && (instance < NUM_ELEMENTS(aic7xxx_dv_settings))) {
+	 && (instance < ARRAY_SIZE(aic7xxx_dv_settings))) {
 		aic7xxx_dv_settings[instance] = value;
 		if (bootverbose)
 			printf("dv[%d] = %d\n", instance, value);
@@ -1658,7 +1658,7 @@ aic7xxx_setup(char *s)
 	end = strchr(s, '\0');
 
 	/*
-	 * XXX ia64 gcc isn't smart enough to know that NUM_ELEMENTS
+	 * XXX ia64 gcc isn't smart enough to know that ARRAY_SIZE
 	 * will never be 0 in this case.
 	 */
 	n = 0;
@@ -1666,13 +1666,13 @@ aic7xxx_setup(char *s)
 	while ((p = strsep(&s, ",.")) != NULL) {
 		if (*p == '\0')
 			continue;
-		for (i = 0; i < NUM_ELEMENTS(options); i++) {
+		for (i = 0; i < ARRAY_SIZE(options); i++) {
 
 			n = strlen(options[i].name);
 			if (strncmp(options[i].name, p, n) == 0)
 				break;
 		}
-		if (i == NUM_ELEMENTS(options))
+		if (i == ARRAY_SIZE(options))
 			continue;
 
 		if (strncmp(p, "global_tag_depth", n) == 0) {
@@ -3250,7 +3250,7 @@ ahc_linux_fallback(struct ahc_softc *ahc
 	if (offset == 0)
 		period = AHC_ASYNC_XFER_PERIOD;
 	if (targ->dv_next_narrow_period == 0)
-		targ->dv_next_narrow_period = MAX(period, AHC_SYNCRATE_ULTRA2);
+		targ->dv_next_narrow_period = max_t(uint8_t, period, AHC_SYNCRATE_ULTRA2);
 	if (targ->dv_next_wide_period == 0)
 		targ->dv_next_wide_period = period;
 	if (targ->dv_max_width == 0)
@@ -3536,7 +3536,7 @@ ahc_linux_user_tagdepth(struct ahc_softc
 
 	tags = 0;
 	if ((ahc->user_discenable & devinfo->target_mask) != 0) {
-		if (ahc->unit >= NUM_ELEMENTS(aic7xxx_tag_info)) {
+		if (ahc->unit >= ARRAY_SIZE(aic7xxx_tag_info)) {
 			if (warned_user == 0) {
 
 				printf(KERN_WARNING
@@ -3565,7 +3565,7 @@ ahc_linux_user_dv_setting(struct ahc_sof
 	static int warned_user;
 	int dv;
 
-	if (ahc->unit >= NUM_ELEMENTS(aic7xxx_dv_settings)) {
+	if (ahc->unit >= ARRAY_SIZE(aic7xxx_dv_settings)) {
 		if (warned_user == 0) {
 
 			printf(KERN_WARNING
@@ -4278,7 +4278,7 @@ ahc_linux_handle_scsi_status(struct ahc_
 		if (scb->flags & SCB_SENSE) {
 			u_int sense_size;
 
-			sense_size = MIN(sizeof(struct scsi_sense_data)
+			sense_size = min_t(u_int, sizeof(struct scsi_sense_data)
 				       - ahc_get_sense_residual(scb),
 					 sizeof(cmd->sense_buffer));
 			memcpy(cmd->sense_buffer,
@@ -4558,7 +4558,7 @@ ahc_linux_filter_inquiry(struct ahc_soft
 	offset = user->offset;
 	ppr_options = user->ppr_options;
 	trans_version = user->transport_version;
-	prot_version = MIN(user->protocol_version, SID_ANSI_REV(sid));
+	prot_version = min_t(u_int, user->protocol_version, SID_ANSI_REV(sid));
 
 	/*
 	 * Only attempt SPI3/4 once we've verified that
drivers/scsi/aic7xxx/aic7xxx_pci.c +1 -1
Index: linux-266-rc2-kj1/drivers/scsi/aic7xxx/aic7xxx_pci.c
===================================================================
@@ -626,7 +626,7 @@ struct ahc_pci_identity ahc_pci_ident_ta
 	}
 };
 
-const u_int ahc_num_pci_devs = NUM_ELEMENTS(ahc_pci_ident_table);
+const u_int ahc_num_pci_devs = ARRAY_SIZE(ahc_pci_ident_table);
 		
 #define AHC_394X_SLOT_CHANNEL_A	4
 #define AHC_394X_SLOT_CHANNEL_B	5

--

#1 lore raw
Quoted 6 lines

From: Michael Veeck <[email protected]>
Subject: [Kernel-janitors] [PATCH] drivers/scsi/aic7xxxx MIN/MAX/NUM_ELEMENTS
removal

Patch (against 2.6.6-rc1) removes unnecessary min/max/num_elements macros and changes calls to use kernel.h macros instead.

With the exception of two files, this patch changes the driver core. These files must compile on several different OSes and thus must not become dependent on Linux specific macros.

--
Justin

#2 lore raw
Quoted 4 lines

With the exception of two files, this patch changes the driver core. These files must compile on several different OSes and thus must not become dependent on Linux specific macros.

since when is min() linux specific? Maybe your other OS has it too.. if so I doubt it'll have any other semantics than the linux one, and if it doesn't have it, it's like REALLY easy to just add one in the compat layer for that OS.

#3 lore raw
Quoted 8 lines
Quoted 3 lines

With the exception of two files, this patch changes the driver core. These files must compile on several different OSes and thus must not become dependent on Linux specific macros.

since when is min() linux specific? Maybe your other OS has it too.. if so I doubt it'll have any other semantics than the linux one, and if it doesn't have it, it's like REALLY easy to just add one in the compat layer for that OS.

Actually, all of the other supported OSes call min(), MIN() since it is a macro and typical C convention is to use all caps for macros.

Anyway... The core is not supposed to "look like Linux". Its supposed to be (and is) portable. That's why it is implemented in terms of an API exported by the OSM. If the core has to be modified every-time Linux or any other supported OSes changes the name of something, there isn't much point in having a core layer to the driver. The changes proposed here will force 5 other OSM modules to change with *no* functional improvement to the driver.

Since the kernel.org drivers aren't the latest, and the trend has been toward ignoring the latest drivers and instead re-implementing the fixes already there (e.g. the pci registration stuff), I'm not going to fight you one way or the other. I just thought it was important to explain that these changes are an layering violation in the driver, not an enhancement.

--
Justin