drivers/serial/mpc52xx_uart.c: fix array overindexing check
[sfrench/cifs-2.6.git] / drivers / serial / mpc52xx_uart.c
index 0c3a2ab1612c25b38b1b9a8f40d933e51792bbc4..b3feb6198d57171b30edcf4d3a51cada259af29b 100644 (file)
@@ -50,8 +50,8 @@
 /* OF Platform device Usage :
  *
  * This driver is only used for PSCs configured in uart mode.  The device
- * tree will have a node for each PSC in uart mode w/ device_type = "serial"
- * and "mpc52xx-psc-uart" in the compatible string
+ * tree will have a node for each PSC with "mpc52xx-psc-uart" in the compatible
+ * list.
  *
  * By default, PSC devices are enumerated in the order they are found.  However
  * a particular PSC number can be forces by adding 'device_no = <port#>'
@@ -522,7 +522,7 @@ mpc52xx_uart_startup(struct uart_port *port)
 
        /* Request IRQ */
        ret = request_irq(port->irq, mpc52xx_uart_int,
-               IRQF_DISABLED | IRQF_SAMPLE_RANDOM | IRQF_SHARED,
+               IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
                "mpc52xx_psc_uart", port);
        if (ret)
                return ret;
@@ -988,7 +988,7 @@ mpc52xx_console_setup(struct console *co, char *options)
        pr_debug("mpc52xx_console_setup co=%p, co->index=%i, options=%s\n",
                 co, co->index, options);
 
-       if ((co->index < 0) || (co->index > MPC52xx_PSC_MAXNUM)) {
+       if ((co->index < 0) || (co->index >= MPC52xx_PSC_MAXNUM)) {
                pr_debug("PSC%x out of range\n", co->index);
                return -EINVAL;
        }
@@ -1212,30 +1212,18 @@ mpc52xx_uart_of_resume(struct of_device *op)
 #endif
 
 static void
-mpc52xx_uart_of_assign(struct device_node *np, int idx)
+mpc52xx_uart_of_assign(struct device_node *np)
 {
-       int free_idx = -1;
        int i;
 
-       /* Find the first free node */
+       /* Find the first free PSC number */
        for (i = 0; i < MPC52xx_PSC_MAXNUM; i++) {
                if (mpc52xx_uart_nodes[i] == NULL) {
-                       free_idx = i;
-                       break;
+                       of_node_get(np);
+                       mpc52xx_uart_nodes[i] = np;
+                       return;
                }
        }
-
-       if ((idx < 0) || (idx >= MPC52xx_PSC_MAXNUM))
-               idx = free_idx;
-
-       if (idx < 0)
-               return; /* No free slot; abort */
-
-       of_node_get(np);
-       /* If the slot is already occupied, then swap slots */
-       if (mpc52xx_uart_nodes[idx] && (free_idx != -1))
-               mpc52xx_uart_nodes[free_idx] = mpc52xx_uart_nodes[idx];
-       mpc52xx_uart_nodes[idx] = np;
 }
 
 static void
@@ -1243,23 +1231,17 @@ mpc52xx_uart_of_enumerate(void)
 {
        static int enum_done;
        struct device_node *np;
-       const unsigned int *devno;
        const struct  of_device_id *match;
        int i;
 
        if (enum_done)
                return;
 
-       for_each_node_by_type(np, "serial") {
+       /* Assign index to each PSC in device tree */
+       for_each_matching_node(np, mpc52xx_uart_of_match) {
                match = of_match_node(mpc52xx_uart_of_match, np);
-               if (!match)
-                       continue;
-
                psc_ops = match->data;
-
-               /* Is a particular device number requested? */
-               devno = of_get_property(np, "port-number", NULL);
-               mpc52xx_uart_of_assign(np, devno ? *devno : -1);
+               mpc52xx_uart_of_assign(np);
        }
 
        enum_done = 1;