net/fm: call fm_port_to_index() with proper checks
authorRotariu Marian-Cristian <marian.rotariu@freescale.com>
Mon, 19 May 2014 07:59:52 +0000 (10:59 +0300)
committerYork Sun <yorksun@freescale.com>
Tue, 22 Jul 2014 23:25:53 +0000 (16:25 -0700)
Some of the fm_port_to_index() callers did not check for -1 return value and
used -1 as an array index.

Signed-off-by: Marian Rotariu <marian.rotariu@freescale.com>
Reviewed-by: York Sun <yorksun@freescale.com>
drivers/net/fm/fm.h
drivers/net/fm/init.c

index 43de114b529c09397238623fc91cfe90be998654..316e06e17e4db68f49ba33395d78e6e885e94bc5 100644 (file)
@@ -143,6 +143,7 @@ struct fm_eth {
 #define MAX_RXBUF_LOG2         11
 #define MAX_RXBUF_LEN          (1 << MAX_RXBUF_LOG2)
 
-#define PORT_IS_ENABLED(port)  fm_info[fm_port_to_index(port)].enabled
+#define PORT_IS_ENABLED(port)  (fm_port_to_index(port) == -1 ? \
+       0 : fm_info[fm_port_to_index(port)].enabled)
 
 #endif /* __FM_H__ */
index cd787f4eedabf13d091a1fc05577a7cde1b9102b..ff04695c323553dfd9589d15cb5dc70210869054 100644 (file)
@@ -147,6 +147,9 @@ void fm_disable_port(enum fm_port port)
 {
        int i = fm_port_to_index(port);
 
+       if (i == -1)
+               return;
+
        fm_info[i].enabled = 0;
        fman_disable_port(port);
 }
@@ -155,6 +158,9 @@ void fm_enable_port(enum fm_port port)
 {
        int i = fm_port_to_index(port);
 
+       if (i == -1)
+               return;
+
        fm_info[i].enabled = 1;
        fman_enable_port(port);
 }