Skip to contentSkip to conversation

net: null check after pointer dereference

PATCH New Vishwas Srivastava 2 participants 3 messages Jan 29, 2016 – Feb 6, 2016 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: null check after pointer dereference

Author: Vishwas Srivastava <[email protected]>
Date:   Tue Jan 26 12:46:42 2016 +0530

null check after pointer dereference

NULL check is made after the pointer dereference in davinci-emac driver. This patch fixes this issue.

Changes for v2:
-cleaned up the style format
-addressed various comments given by Joe <[email protected]> on the first version of the patch.

drivers/net/davinci_emac.c +0 -0
index 3f54a3f..a61374d 100644
@@ -692,8 +692,10 @@ static int davinci_eth_rcv_packet (struct eth_device

*dev)

        davinci_invalidate_rx_descs();

        rx_curr_desc = emac_rx_active_head;
+       if (!rx_curr_desc)
+               return 0;
        status = rx_curr_desc->pkt_flag_len;
-       if ((rx_curr_desc) && ((status & EMAC_CPPI_OWNERSHIP_BIT) == 0)) {
+       if ((status & EMAC_CPPI_OWNERSHIP_BIT) == 0) {
                if (status & EMAC_CPPI_RX_ERROR_FRAME) {
                        /* Error in packet - discard it and requeue desc */
                        printf ("WARN: emac_rcv_pkt: Error in packet\n");
Quoted 55 lines · Joe Hershberger
Quoted 2 lines · Vishwas Srivastava
Author: Vishwas Srivastava <[email protected]>
Date:   Tue Jan 26 12:46:42 2016 +0530

Please fix the subject of this patch. No space in the "net :".

Quoted 2 lines

null check after pointer dereference

All of your commit logs should not have spaces in them (at the start of lines).

Quoted 6 lines

NULL check is made after the pointer dereference is davinci- emac driver. This patch fixes this issue.

CC: Sergey Kubushyn <[email protected]>;Joe Hershberger <
joe.hershberger at ni.com>

Fix this format. One "Cc:" per line.

Quoted 1 line

This belongs first... before the Cc:

drivers/net/davinci_emac.c static int davinci_eth_rcv_packet (struct eth_device · line 695

Quoted 10 lines
drivers/net/davinci_emac.c +0 -0
index 3f54a3f..1966eb9 100644
@@ -692,8 +692,10 @@ static int davinci_eth_rcv_packet (struct eth_device
 *dev)
        davinci_invalidate_rx_descs();
 
        rx_curr_desc = emac_rx_active_head;

You need to run your patches through scripts/checkpatch.pl.

drivers/net/davinci_emac.c static int davinci_eth_rcv_packet (struct eth_device · line 697

Quoted 4 lines
drivers/net/davinci_emac.c +2 -1
+       if (!rx_curr_desc)
+           return 0;
        status = rx_curr_desc->pkt_flag_len;
-       if ((rx_curr_desc) && ((status & EMAC_CPPI_OWNERSHIP_BIT) == 0))

{

drivers/net/davinci_emac.c static int davinci_eth_rcv_packet (struct eth_device · line 701

Quoted 3 lines
drivers/net/davinci_emac.c +1 -0
+       if ((status & EMAC_CPPI_OWNERSHIP_BIT) == 0) {
                if (status & EMAC_CPPI_RX_ERROR_FRAME) {
                        /* Error in packet - discard it and requeue desc

*/

Quoted 1 line
                        printf ("WARN: emac_rcv_pkt: Error in packet\n");

Consider using tools/patman.

Thanks,
-Joe

#1 lore raw

PATCH v3 1/1 net: davinci_emac: fix NULL check after pointer dereference

From: Vishwas Srivastava <[email protected]>

NULL check is made after the pointer dereference. This patch fixes this issue.

---
Changes in v3:
- slightly edit subject and commit message
- format patch properly

 drivers/net/davinci_emac.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/davinci_emac.c +3 -1
index 6f2dc8d..b030498 100644
@@ -692,8 +692,10 @@ static int davinci_eth_rcv_packet (struct eth_device *dev)
 	davinci_invalidate_rx_descs();
 
 	rx_curr_desc = emac_rx_active_head;
+	if (!rx_curr_desc)
+		return 0;
 	status = rx_curr_desc->pkt_flag_len;
-	if ((rx_curr_desc) && ((status & EMAC_CPPI_OWNERSHIP_BIT) == 0)) {
+	if ((status & EMAC_CPPI_OWNERSHIP_BIT) == 0) {
 		if (status & EMAC_CPPI_RX_ERROR_FRAME) {
 			/* Error in packet - discard it and requeue desc */
 			printf ("WARN: emac_rcv_pkt: Error in packet\n");
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v3 1/1 net: davinci_emac: fix NULL check after pointer dereference

Quoted 10 lines · On Sat, 6 Feb 2016 16:40:59 +0100 Anatolij Gustschin agust at denx.de wrote:

From: Vishwas Srivastava <[email protected]>

NULL check is made after the pointer dereference. This patch fixes this issue.

Quoted 7 lines

---
Changes in v3:
- slightly edit subject and commit message
- format patch properly

 drivers/net/davinci_emac.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Applied to u-boot-staging, thanks!

--
Anatolij