All of lore.kernel.org
 help / color / mirror / Atom feed
* [KJ] [PATCH] Use standard min/max macros [1/3]
@ 2006-07-31 22:13 Clément Stenac
  2006-07-31 22:25 ` [KJ] [PATCH] Use standard min/max macros [2/3] Clément Stenac
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Clément Stenac @ 2006-07-31 22:13 UTC (permalink / raw)
  To: kernel-janitors

Remove some custom type-unsafe MIN/MAX macros in favor of type-checking
min/max from kernel.h

Signed-off-by: Clément Stenac <zorglub@diwi.org>
--- 

This is my very first patch submission, reviews are welcome.

As this patch switches to type-checking macros, it reveals a number of
warnings due to bogus comparisons (mostly signed/unsigned). I plan to do
another set of patches for some of these.

diff --git a/drivers/isdn/hardware/eicon/debug.c b/drivers/isdn/hardware/eicon/debug.c
index 6851c62..f55d679 100644
--- a/drivers/isdn/hardware/eicon/debug.c
+++ b/drivers/isdn/hardware/eicon/debug.c
@@ -756,14 +756,14 @@ int diva_get_driver_info (dword id, byte
 
     data_length -= 9;
 
-    if ((to_copy = MIN(strlen(clients[id].drvName), data_length-1))) {
+    if ((to_copy = min(strlen(clients[id].drvName), data_length-1))) {
       memcpy (p, clients[id].drvName, to_copy);
       p += to_copy;
       data_length -= to_copy;
       if ((data_length >= 4) && clients[id].hDbg->drvTag[0]) {
         *p++ = '(';
         data_length -= 1;
-        if ((to_copy = MIN(strlen(clients[id].hDbg->drvTag), data_length-2))) {
+        if ((to_copy = min(strlen(clients[id].hDbg->drvTag), data_length-2))) {
           memcpy (p, clients[id].hDbg->drvTag, to_copy);
           p += to_copy;
           data_length -= to_copy;
diff --git a/drivers/isdn/hardware/eicon/di.c b/drivers/isdn/hardware/eicon/di.c
index 0617d7c..6e65d2c 100644
--- a/drivers/isdn/hardware/eicon/di.c
+++ b/drivers/isdn/hardware/eicon/di.c
@@ -133,7 +133,7 @@ #endif
     i = this->XCurrent;
     X = PTR_X(a,this);
     while(i<this->XNum && length<270) {
-      clength = MIN((word)(270-length),X[i].PLength-this->XOffset);
+      clength = min((word)(270-length),X[i].PLength-this->XOffset);
       a->ram_out_buffer(a,
                         &ReqOut->XBuffer.P[length],
                         PTR_P(a,this,&X[i].P[this->XOffset]),
@@ -622,7 +622,7 @@ #endif
                                                      sizeof(a->stream_buffer),
                                                      &final, NULL, NULL);
         }
-        IoAdapter->RBuffer.length = MIN(MLength, 270);
+        IoAdapter->RBuffer.length = min(MLength, 270);
         if (IoAdapter->RBuffer.length != MLength) {
           this->complete = 0;
         } else {
@@ -676,9 +676,9 @@ #endif
         this->RCurrent++;
       }
       if (cma) {
-        clength = MIN(MLength, R[this->RCurrent].PLength-this->ROffset);
+        clength = min(MLength, R[this->RCurrent].PLength-this->ROffset);
       } else {
-        clength = MIN(a->ram_inw(a, &RBuffer->length)-offset,
+        clength = min(a->ram_inw(a, &RBuffer->length)-offset,
                       R[this->RCurrent].PLength-this->ROffset);
       }
       if(R[this->RCurrent].P) {
diff --git a/drivers/isdn/hardware/eicon/io.c b/drivers/isdn/hardware/eicon/io.c
index 4a27e23..7e197c7 100644
--- a/drivers/isdn/hardware/eicon/io.c
+++ b/drivers/isdn/hardware/eicon/io.c
@@ -262,7 +262,7 @@ #endif
     case IDI_SYNC_REQ_XDI_GET_CAPI_PARAMS: {
        diva_xdi_get_capi_parameters_t prms, *pI = &syncReq->xdi_capi_prms.info;
        memset (&prms, 0x00, sizeof(prms));
-       prms.structure_length = MIN(sizeof(prms), pI->structure_length);
+       prms.structure_length = min(sizeof(prms), pI->structure_length);
        memset (pI, 0x00, pI->structure_length);
        prms.flag_dynamic_l1_down    = (IoAdapter->capi_cfg.cfg_1 & \
          DIVA_XDI_CAPI_CFG_1_DYNAMIC_L1_ON) ? 1 : 0;
diff --git a/drivers/isdn/hardware/eicon/istream.c b/drivers/isdn/hardware/eicon/istream.c
index 2313966..87133db 100644
--- a/drivers/isdn/hardware/eicon/istream.c
+++ b/drivers/isdn/hardware/eicon/istream.c
@@ -92,7 +92,7 @@ #endif
     return (-1); /* was not able to write       */
    break;     /* only part of message was written */
   }
-  to_write = MIN(length, DIVA_DFIFO_DATA_SZ);
+  to_write = min(length, DIVA_DFIFO_DATA_SZ);
   if (to_write) {
    a->ram_out_buffer (a,
 #ifdef PLATFORM_GT_32BIT
@@ -176,7 +176,7 @@ #endif
     return (-1); /* was not able to read */
    break;
   }
-  to_read = MIN(max_length, tmp[1]);
+  to_read = min(max_length, tmp[1]);
   if (to_read) {
    a->ram_in_buffer(a,
 #ifdef PLATFORM_GT_32BIT
diff --git a/drivers/isdn/hardware/eicon/platform.h b/drivers/isdn/hardware/eicon/platform.h
index a66836c..2444811 100644
--- a/drivers/isdn/hardware/eicon/platform.h
+++ b/drivers/isdn/hardware/eicon/platform.h
@@ -83,14 +83,6 @@ #ifndef	NULL
 #define	NULL	((void *) 0)
 #endif
 
-#ifndef	MIN
-#define MIN(a,b)	((a)>(b) ? (b) : (a))
-#endif
-
-#ifndef	MAX
-#define MAX(a,b)	((a)>(b) ? (a) : (b))
-#endif
-
 #ifndef	far
 #define far
 #endif
diff --git a/drivers/net/wan/pc300_drv.c b/drivers/net/wan/pc300_drv.c
index 567efff..6d943df 100644
--- a/drivers/net/wan/pc300_drv.c
+++ b/drivers/net/wan/pc300_drv.c
@@ -270,13 +270,6 @@ static struct pci_device_id cpc_pci_dev_
 };
 MODULE_DEVICE_TABLE(pci, cpc_pci_dev_id);
 
-#ifndef cpc_min
-#define	cpc_min(a,b)	(((a)<(b))?(a):(b))
-#endif
-#ifndef cpc_max
-#define	cpc_max(a,b)	(((a)>(b))?(a):(b))
-#endif
-
 /* prototypes */
 static void tx_dma_buf_pt_init(pc300_t *, int);
 static void tx_dma_buf_init(pc300_t *, int);
@@ -477,7 +470,7 @@ static int dma_buf_write(pc300_t * card,
 	for (i = 0; i < nbuf; i++) {
 		ptdescr = (card->hw.rambase +
 					  TX_BD_ADDR(ch, card->chan[ch].tx_next_bd));
-		nchar = cpc_min(BD_DEF_LEN, tosend);
+		nchar = min(BD_DEF_LEN, tosend);
 		if (cpc_readb(&ptdescr->status) & DST_OSB) {
 			memcpy_toio((card->hw.rambase + cpc_readl(&ptdescr->ptbuf)),
 				    &ptdata[len - tosend], nchar);
diff --git a/include/net/irda/irda.h b/include/net/irda/irda.h
index 1cb0607..35918be 100644
--- a/include/net/irda/irda.h
+++ b/include/net/irda/irda.h
@@ -46,10 +46,6 @@ #ifndef SMALL
 #define SMALL 5
 #endif
 
-#ifndef IRDA_MIN /* Lets not mix this MIN with other header files */
-#define IRDA_MIN(a, b) (((a) < (b)) ? (a) : (b))
-#endif
-
 #ifndef IRDA_ALIGN
 #  define IRDA_ALIGN __attribute__((aligned))
 #endif
diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
index 3bcdb46..584752d 100644
--- a/net/irda/ircomm/ircomm_tty.c
+++ b/net/irda/ircomm/ircomm_tty.c
@@ -854,7 +854,7 @@ static void ircomm_tty_wait_until_sent(s
 	orig_jiffies = jiffies;
 
 	/* Set poll time to 200 ms */
-	poll_time = IRDA_MIN(timeout, msecs_to_jiffies(200));
+	poll_time = min(timeout, msecs_to_jiffies(200));
 
 	spin_lock_irqsave(&self->spinlock, flags);
 	while (self->tx_skb && self->tx_skb->len) {
@@ -1201,7 +1201,7 @@ static int ircomm_tty_control_indication
 
 	clen = skb->data[0];
 
-	irda_param_extract_all(self, skb->data+1, IRDA_MIN(skb->len-1, clen), 
+	irda_param_extract_all(self, skb->data+1, min(skb->len-1, clen), 
 			       &ircomm_param_info);
 
 	/* No need to kfree_skb - see ircomm_control_indication() */
diff --git a/net/irda/ircomm/ircomm_tty_attach.c b/net/irda/ircomm/ircomm_tty_attach.c
index 99f5edd..539293e 100644
--- a/net/irda/ircomm/ircomm_tty_attach.c
+++ b/net/irda/ircomm/ircomm_tty_attach.c
@@ -543,7 +543,7 @@ void ircomm_tty_connect_indication(void 
 	clen = skb->data[0];
 	if (clen)
 		irda_param_extract_all(self, skb->data+1, 
-				       IRDA_MIN(skb->len, clen), 
+				       min(skb->len, clen), 
 				       &ircomm_param_info);
 
 	ircomm_tty_do_event(self, IRCOMM_TTY_CONNECT_INDICATION, NULL, NULL);
diff --git a/net/irda/irlap_frame.c b/net/irda/irlap_frame.c
index ccb983b..73cfd18 100644
--- a/net/irda/irlap_frame.c
+++ b/net/irda/irlap_frame.c
@@ -378,7 +378,7 @@ void irlap_send_discovery_xid_frame(stru
 		info = skb_put(tx_skb, 1);
 		info[0] = discovery->data.charset;
 
-		len = IRDA_MIN(discovery->name_len, skb_tailroom(tx_skb));
+		len = min(discovery->name_len, skb_tailroom(tx_skb));
 		info = skb_put(tx_skb, len);
 		memcpy(info, discovery->data.info, len);
 	}
diff --git a/net/irda/irttp.c b/net/irda/irttp.c
index 42acf1c..3a2480e 100644
--- a/net/irda/irttp.c
+++ b/net/irda/irttp.c
@@ -1216,7 +1216,7 @@ static void irttp_connect_confirm(void *
 		plen = skb->data[0];
 
 		ret = irda_param_extract_all(self, skb->data+1,
-					     IRDA_MIN(skb->len-1, plen),
+					     min(skb->len-1, plen),
 					     &param_info);
 
 		/* Any errors in the parameter list? */
@@ -1229,7 +1229,7 @@ static void irttp_connect_confirm(void *
 			return;
 		}
 		/* Remove parameters */
-		skb_pull(skb, IRDA_MIN(skb->len, plen+1));
+		skb_pull(skb, min(skb->len, plen+1));
 	}
 
 	IRDA_DEBUG(4, "%s() send=%d,avail=%d,remote=%d\n", __FUNCTION__,
@@ -1293,7 +1293,7 @@ void irttp_connect_indication(void *inst
 		plen = skb->data[0];
 
 		ret = irda_param_extract_all(self, skb->data+1,
-					     IRDA_MIN(skb->len-1, plen),
+					     min(skb->len-1, plen),
 					     &param_info);
 
 		/* Any errors in the parameter list? */
@@ -1307,7 +1307,7 @@ void irttp_connect_indication(void *inst
 		}
 
 		/* Remove parameters */
-		skb_pull(skb, IRDA_MIN(skb->len, plen+1));
+		skb_pull(skb, min(skb->len, plen+1));
 	}
 
 	if (self->notify.connect_indication) {
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-08-02 19:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-31 22:13 [KJ] [PATCH] Use standard min/max macros [1/3] Clément Stenac
2006-07-31 22:25 ` [KJ] [PATCH] Use standard min/max macros [2/3] Clément Stenac
2006-07-31 22:26 ` [KJ] [PATCH] Use standard min/max macros [3/3] Clément Stenac
2006-08-01  1:55 ` Alexey Dobriyan
2006-08-02 19:57 ` Clément Stenac

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.