Skip to contentSkip to conversation

UCC Ether driver: kmalloc casting cleanups

PATCH In review Ahmed S. Darwish 2 participants 5 messages Jan 6, 2007 – Jan 9, 2007

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

PATCH 1/1 UCC Ether driver: kmalloc casting cleanups

[Please inform me if you are not the maintaner cause I'm not sure:)]

Hi,
A kmalloc casting cleanup patch.

I wasn't able to compile the file drivers/net/ucc_geth.c cause of some not found headers (asm/of_platform.h, asm/qe.h, and others )

drivers/net/ucc_geth.c +10 -13
index 8243150..001109e 100644
@@ -2864,8 +2864,8 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
 			if (UCC_GETH_TX_BD_RING_ALIGNMENT > 4)
 				align = UCC_GETH_TX_BD_RING_ALIGNMENT;
 			ugeth->tx_bd_ring_offset[j] =
-				(u32) (kmalloc((u32) (length + align),
-				GFP_KERNEL));
+				kmalloc((u32) (length + align), GFP_KERNEL);
+					 
 			if (ugeth->tx_bd_ring_offset[j] != 0)
 				ugeth->p_tx_bd_ring[j] =
 					(void*)((ugeth->tx_bd_ring_offset[j] +
@@ -2900,7 +2900,7 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
 			if (UCC_GETH_RX_BD_RING_ALIGNMENT > 4)
 				align = UCC_GETH_RX_BD_RING_ALIGNMENT;
 			ugeth->rx_bd_ring_offset[j] =
-			    (u32) (kmalloc((u32) (length + align), GFP_KERNEL));
+				kmalloc((u32) (length + align), GFP_KERNEL);
 			if (ugeth->rx_bd_ring_offset[j] != 0)
 				ugeth->p_rx_bd_ring[j] =
 					(void*)((ugeth->rx_bd_ring_offset[j] +
@@ -2926,10 +2926,9 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
 	/* Init Tx bds */
 	for (j = 0; j < ug_info->numQueuesTx; j++) {
 		/* Setup the skbuff rings */
-		ugeth->tx_skbuff[j] =
-		    (struct sk_buff **)kmalloc(sizeof(struct sk_buff *) *
-					       ugeth->ug_info->bdRingLenTx[j],
-					       GFP_KERNEL);
+		ugeth->tx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
+					      ugeth->ug_info->bdRingLenTx[j],
+					      GFP_KERNEL);
 
 		if (ugeth->tx_skbuff[j] == NULL) {
 			ugeth_err("%s: Could not allocate tx_skbuff",
@@ -2958,10 +2957,9 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
 	/* Init Rx bds */
 	for (j = 0; j < ug_info->numQueuesRx; j++) {
 		/* Setup the skbuff rings */
-		ugeth->rx_skbuff[j] =
-		    (struct sk_buff **)kmalloc(sizeof(struct sk_buff *) *
-					       ugeth->ug_info->bdRingLenRx[j],
-					       GFP_KERNEL);
+		ugeth->rx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
+					      ugeth->ug_info->bdRingLenRx[j],
+					      GFP_KERNEL);
 
 		if (ugeth->rx_skbuff[j] == NULL) {
 			ugeth_err("%s: Could not allocate rx_skbuff",
@@ -3452,8 +3450,7 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
 	 * allocated resources can be released when the channel is freed.
 	 */
 	if (!(ugeth->p_init_enet_param_shadow =
-	     (struct ucc_geth_init_pram *) kmalloc(sizeof(struct ucc_geth_init_pram),
-					      GFP_KERNEL))) {
+	      kmalloc(sizeof(struct ucc_geth_init_pram), GFP_KERNEL))) {
 		ugeth_err
 		    ("%s: Can not allocate memory for"
 			" p_UccInitEnetParamShadows.", __FUNCTION__);
Signature · 2 lines
Ahmed S. Darwish
http://darwish-07.blogspot.com
#1 lore raw
Quoted 7 lines

-----Original Message-----
From: Ahmed S. Darwish [mailto:[email protected]]
Sent: Saturday, January 06, 2007 9:19 PM
To: Li Yang-r58472
Cc: [email protected]
Subject: [PATCH 2.6.20-rc3] UCC Ether driver: kmalloc casting cleanups

Quoted 7 lines

[Please inform me if you are not the maintaner cause I'm not sure:)]

Hi,
A kmalloc casting cleanup patch.

I wasn't able to compile the file drivers/net/ucc_geth.c cause of some not found headers (asm/of_platform.h, asm/qe.h, and others )

You need to use ARCH=powerpc to compile this driver. I don't know how you could select this driver without using powerpc arch.

drivers/net/ucc_geth.c static int ucc_geth_startup(struct

Quoted 8 lines
drivers/net/ucc_geth.c +0 -0
index 8243150..001109e 100644
@@ -2864,8 +2864,8 @@ static int ucc_geth_startup(struct

ucc_geth_private *ugeth)

drivers/net/ucc_geth.c static int ucc_geth_startup(struct ucc_geth_private *ugeth)

Quoted 6 lines
drivers/net/ucc_geth.c +1 -2
 			if (UCC_GETH_TX_BD_RING_ALIGNMENT > 4)
 				align = UCC_GETH_TX_BD_RING_ALIGNMENT;
 			ugeth->tx_bd_ring_offset[j] =
-				(u32) (kmalloc((u32) (length + align),
-				GFP_KERNEL));
+				kmalloc((u32) (length + align),

GFP_KERNEL);

drivers/net/ucc_geth.c static int ucc_geth_startup(struct ucc_geth_private *ugeth)

Quoted 4 lines
drivers/net/ucc_geth.c +1 -0
+
 			if (ugeth->tx_bd_ring_offset[j] != 0)
 				ugeth->p_tx_bd_ring[j] =
 

(void*)((ugeth->tx_bd_ring_offset[j] +

drivers/net/ucc_geth.c static int ucc_geth_startup(struct

Quoted 1 line
drivers/net/ucc_geth.c +0 -0
@@ -2900,7 +2900,7 @@ static int ucc_geth_startup(struct

ucc_geth_private *ugeth)

drivers/net/ucc_geth.c static int ucc_geth_startup(struct ucc_geth_private *ugeth)

Quoted 4 lines
drivers/net/ucc_geth.c +0 -1
 			if (UCC_GETH_RX_BD_RING_ALIGNMENT > 4)
 				align = UCC_GETH_RX_BD_RING_ALIGNMENT;
 			ugeth->rx_bd_ring_offset[j] =
-			    (u32) (kmalloc((u32) (length + align),

GFP_KERNEL));

drivers/net/ucc_geth.c static int ucc_geth_startup(struct · line 2903

Quoted 1 line
drivers/net/ucc_geth.c +1 -0
+				kmalloc((u32) (length + align),

GFP_KERNEL);

NACK about the 2 clean-ups above. Cast from pointer to integer is required here.

drivers/net/ucc_geth.c static int ucc_geth_startup(struct ucc_geth_private *ugeth)

Quoted 3 lines
drivers/net/ucc_geth.c +0 -0
 			if (ugeth->rx_bd_ring_offset[j] != 0)
 				ugeth->p_rx_bd_ring[j] =
 

(void*)((ugeth->rx_bd_ring_offset[j] +

drivers/net/ucc_geth.c static int ucc_geth_startup(struct

Quoted 1 line
drivers/net/ucc_geth.c +0 -0
@@ -2926,10 +2926,9 @@ static int ucc_geth_startup(struct

ucc_geth_private *ugeth)

drivers/net/ucc_geth.c static int ucc_geth_startup(struct ucc_geth_private *ugeth)

Quoted 5 lines
drivers/net/ucc_geth.c +0 -2
 	/* Init Tx bds */
 	for (j = 0; j < ug_info->numQueuesTx; j++) {
 		/* Setup the skbuff rings */
-		ugeth->tx_skbuff[j] =
-		    (struct sk_buff **)kmalloc(sizeof(struct sk_buff *)

*

drivers/net/ucc_geth.c static int ucc_geth_startup(struct · line 2931

Quoted 1 line
drivers/net/ucc_geth.c +0 -1
-

ugeth->ug_info->bdRingLenTx[j],

drivers/net/ucc_geth.c static int ucc_geth_startup(struct ucc_geth_private *ugeth)

Quoted 3 lines
drivers/net/ucc_geth.c +2 -1
-					       GFP_KERNEL);
+		ugeth->tx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
+

ugeth->ug_info->bdRingLenTx[j],

drivers/net/ucc_geth.c static int ucc_geth_startup(struct

Quoted 5 lines
drivers/net/ucc_geth.c +1 -0
+					      GFP_KERNEL);
 
 		if (ugeth->tx_skbuff[j] == NULL) {
 			ugeth_err("%s: Could not allocate tx_skbuff",
@@ -2958,10 +2957,9 @@ static int ucc_geth_startup(struct

ucc_geth_private *ugeth)

drivers/net/ucc_geth.c static int ucc_geth_startup(struct ucc_geth_private *ugeth)

Quoted 5 lines
drivers/net/ucc_geth.c +0 -2
 	/* Init Rx bds */
 	for (j = 0; j < ug_info->numQueuesRx; j++) {
 		/* Setup the skbuff rings */
-		ugeth->rx_skbuff[j] =
-		    (struct sk_buff **)kmalloc(sizeof(struct sk_buff *)

*

drivers/net/ucc_geth.c static int ucc_geth_startup(struct · line 2963

Quoted 1 line
drivers/net/ucc_geth.c +0 -1
-

ugeth->ug_info->bdRingLenRx[j],

drivers/net/ucc_geth.c static int ucc_geth_startup(struct ucc_geth_private *ugeth)

Quoted 3 lines
drivers/net/ucc_geth.c +2 -1
-					       GFP_KERNEL);
+		ugeth->rx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
+

ugeth->ug_info->bdRingLenRx[j],

drivers/net/ucc_geth.c static int ucc_geth_startup(struct

Quoted 5 lines
drivers/net/ucc_geth.c +1 -0
+					      GFP_KERNEL);
 
 		if (ugeth->rx_skbuff[j] == NULL) {
 			ugeth_err("%s: Could not allocate rx_skbuff",
@@ -3452,8 +3450,7 @@ static int ucc_geth_startup(struct

ucc_geth_private *ugeth)

drivers/net/ucc_geth.c static int ucc_geth_startup(struct · line 3450

Quoted 1 line
drivers/net/ucc_geth.c +0 -0
 	 * allocated resources can be released when the channel is

freed.

Quoted 10 lines
drivers/net/ucc_geth.c +1 -2
 	 */
 	if (!(ugeth->p_init_enet_param_shadow =
-	     (struct ucc_geth_init_pram *) kmalloc(sizeof(struct
 ucc_geth_init_pram),
-					      GFP_KERNEL))) {
+	      kmalloc(sizeof(struct ucc_geth_init_pram), GFP_KERNEL))) {
 		ugeth_err
 		    ("%s: Can not allocate memory for"

" p_UccInitEnetParamShadows.", __FUNCTION__);

Quoted 3 lines

--
Ahmed S. Darwish
http://darwish-07.blogspot.com

- Leo

#2 lore raw
Quoted 5 lines · On Mon, Jan 08, 2007 at 11:12:28AM +0800, Li Yang-r58472 wrote:
Quoted 5 lines

From: Ahmed S. Darwish [mailto:[email protected]]

Hi,
A kmalloc casting cleanup patch.

[..]

Quoted 6 lines
Quoted 6 lines
drivers/net/ucc_geth.c +2 -2
-				(u32) (kmalloc((u32) (length + align),
-				GFP_KERNEL));
+				kmalloc((u32) (length + align), GFP_KERNEL);
+
 			if (ugeth->tx_bd_ring_offset[j] != 0)
 				ugeth->p_tx_bd_ring[j] =

[..]

Quoted 5 lines

drivers/net/ucc_geth.c static int ucc_geth_startup(struct ucc_geth_private *ugeth) · line 2903

Quoted 2 lines
drivers/net/ucc_geth.c +1 -1
-			    (u32) (kmalloc((u32) (length + align), GFP_KERNEL));
+				kmalloc((u32) (length + align), GFP_KERNEL);

NACK about the 2 clean-ups above. Cast from pointer to integer is required here.

Are the casts from pointer to integer just needed to suppress gcc warnings or there's something technically important about them ?

I'll send the modified patch without the NACKed parts in minutes ..

Signature · 2 lines
Ahmed S. Darwish
http://darwish-07.blogspot.com
#3 lore raw
Quoted 6 lines

-----Original Message-----
From: Ahmed S. Darwish [mailto:[email protected]]
Sent: Monday, January 08, 2007 12:27 PM
To: Li Yang-r58472
Cc: [email protected]; [email protected]
Subject: Re: [PATCH 2.6.20-rc3] UCC Ether driver: kmalloc casting

cleanups

Quoted 8 lines · On Mon, Jan 08, 2007 at 11:12:28AM +0800, Li Yang-r58472 wrote:
Quoted 5 lines
Quoted 5 lines

From: Ahmed S. Darwish [mailto:[email protected]]

Hi,
A kmalloc casting cleanup patch.

Quoted 5 lines

[..]

Quoted 3 lines

drivers/net/ucc_geth.c static int ucc_geth_startup(struct ucc_geth_private *ugeth)

Quoted 3 lines
drivers/net/ucc_geth.c +1 -2
-				(u32) (kmalloc((u32) (length + align),
-				GFP_KERNEL));
+				kmalloc((u32) (length + align),

GFP_KERNEL);

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/ucc_geth.c +1 -0
+
 			if (ugeth->tx_bd_ring_offset[j] != 0)
 				ugeth->p_tx_bd_ring[j] =

[..]

Quoted 1 line

drivers/net/ucc_geth.c static int ucc_geth_startup(struct ucc_geth_private *ugeth) · line 2867

Quoted 1 line
drivers/net/ucc_geth.c +0 -1
-			    (u32) (kmalloc((u32) (length + align),

GFP_KERNEL));

Quoted 1 line
Quoted 1 line

Review

Quoted 1 line
(quoted diff) +1 -0
+				kmalloc((u32) (length + align),

GFP_KERNEL);

Quoted 6 lines
Quoted 3 lines

NACK about the 2 clean-ups above. Cast from pointer to integer is required here.

Are the casts from pointer to integer just needed to suppress gcc warnings or there's something technically important about them ?

It is to suppress the warnings. IMHO, most type casts are not technically important but for sanity check.

- Leo

#4 lore raw
In reply to Li Yang-r58472
Quoted 4 lines · On Mon, Jan 08, 2007 at 11:12:28AM +0800, Li Yang-r58472 wrote:

NACK about the 2 clean-ups above. Cast from pointer to integer is required here.

Hi, here's the modified patch.

A patch to switch kmalloc to kzalloc and clean some redundant kmalloc casts.

---

drivers/net/ucc_geth.c +9 -14
index 8243150..0f58f5f 100644
@@ -2926,10 +2926,9 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
 	/* Init Tx bds */
 	for (j = 0; j < ug_info->numQueuesTx; j++) {
 		/* Setup the skbuff rings */
-		ugeth->tx_skbuff[j] =
-		    (struct sk_buff **)kmalloc(sizeof(struct sk_buff *) *
-					       ugeth->ug_info->bdRingLenTx[j],
-					       GFP_KERNEL);
+		ugeth->tx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
+					      ugeth->ug_info->bdRingLenTx[j],
+					      GFP_KERNEL);
 
 		if (ugeth->tx_skbuff[j] == NULL) {
 			ugeth_err("%s: Could not allocate tx_skbuff",
@@ -2958,10 +2957,9 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
 	/* Init Rx bds */
 	for (j = 0; j < ug_info->numQueuesRx; j++) {
 		/* Setup the skbuff rings */
-		ugeth->rx_skbuff[j] =
-		    (struct sk_buff **)kmalloc(sizeof(struct sk_buff *) *
-					       ugeth->ug_info->bdRingLenRx[j],
-					       GFP_KERNEL);
+		ugeth->rx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
+					      ugeth->ug_info->bdRingLenRx[j],
+					      GFP_KERNEL);
 
 		if (ugeth->rx_skbuff[j] == NULL) {
 			ugeth_err("%s: Could not allocate rx_skbuff",
@@ -3450,19 +3448,16 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
 	 * resource.
 	 * This shadow structure keeps a copy of what was done so that the
 	 * allocated resources can be released when the channel is freed.
+	 * *p_init_enet_param_shadow is zeroed by kzalloc
 	 */
-	if (!(ugeth->p_init_enet_param_shadow =
-	     (struct ucc_geth_init_pram *) kmalloc(sizeof(struct ucc_geth_init_pram),
-					      GFP_KERNEL))) {
+	if (!(ugeth->p_init_enet_param_shadow = 
+	      kzalloc(sizeof(struct ucc_geth_init_pram), GFP_KERNEL))) {
 		ugeth_err
 		    ("%s: Can not allocate memory for"
 			" p_UccInitEnetParamShadows.", __FUNCTION__);
 		ucc_geth_memclean(ugeth);
 		return -ENOMEM;
 	}
-	/* Zero out *p_init_enet_param_shadow */
-	memset((char *)ugeth->p_init_enet_param_shadow,
-	       0, sizeof(struct ucc_geth_init_pram));
 
 	/* Fill shadow InitEnet command parameter structure */
 
Signature · 2 lines
Ahmed S. Darwish
http://darwish-07.blogspot.com