Staging: dgnc: Use goto for error handling

This patch introduces goto statments for error handling
and in cases where a lock needs to be released.

A simplified version of the semantic patch that finds this problem is as
follows: (http://coccinelle.lip6.fr)

@candidates exists@
identifier f, label;
statement s;
position p1, p2, p3;
@@

  f@p1(...) {
  ...when any

    if@p2(...) {
    ...when any
      s

      return@p3 ...;
    }
  ...when any
  }

@good1 exists@
identifier candidates.f, candidates.label;
statement candidates.s;
position candidates.p1, candidates.p2;
@@

  f@p1(...) {
  ...when any

    if(...) {
    ...when any
      s
      return ...;
    }
    ...when any

    if@p2(...) {...}
  ...when any
 }

@depends on good1@
identifier candidates.f, candidates.label;
position candidates.p1, candidates.p3;
@@

   f@p1(...) {
   ...when any
*  return@p3 ...;
  }

Signed-off-by: Quentin Lambert <lambert.quentin@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Quentin Lambert 2015-03-11 15:22:00 +01:00 committed by Greg Kroah-Hartman
parent 64e784c457
commit f6a14cf04f
3 changed files with 22 additions and 41 deletions

View file

@ -988,22 +988,16 @@ static void cls_copy_data_from_queue_to_uart(struct channel_t *ch)
spin_lock_irqsave(&ch->ch_lock, flags); spin_lock_irqsave(&ch->ch_lock, flags);
/* No data to write to the UART */ /* No data to write to the UART */
if (ch->ch_w_tail == ch->ch_w_head) { if (ch->ch_w_tail == ch->ch_w_head)
spin_unlock_irqrestore(&ch->ch_lock, flags); goto exit_unlock;
return;
}
/* If port is "stopped", don't send any data to the UART */ /* If port is "stopped", don't send any data to the UART */
if ((ch->ch_flags & CH_FORCED_STOP) || if ((ch->ch_flags & CH_FORCED_STOP) ||
(ch->ch_flags & CH_BREAK_SENDING)) { (ch->ch_flags & CH_BREAK_SENDING))
spin_unlock_irqrestore(&ch->ch_lock, flags); goto exit_unlock;
return;
}
if (!(ch->ch_flags & (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM))) { if (!(ch->ch_flags & (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM)))
spin_unlock_irqrestore(&ch->ch_lock, flags); goto exit_unlock;
return;
}
n = 32; n = 32;
@ -1053,6 +1047,7 @@ static void cls_copy_data_from_queue_to_uart(struct channel_t *ch)
if (len_written > 0) if (len_written > 0)
ch->ch_flags &= ~(CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM); ch->ch_flags &= ~(CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
exit_unlock:
spin_unlock_irqrestore(&ch->ch_lock, flags); spin_unlock_irqrestore(&ch->ch_lock, flags);
} }

View file

@ -549,30 +549,19 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
rc = dgnc_tty_register(brd); rc = dgnc_tty_register(brd);
if (rc < 0) { if (rc < 0) {
dgnc_tty_uninit(brd);
pr_err(DRVSTR ": Can't register tty devices (%d)\n", rc); pr_err(DRVSTR ": Can't register tty devices (%d)\n", rc);
brd->state = BOARD_FAILED;
brd->dpastatus = BD_NOFEP;
goto failed; goto failed;
} }
rc = dgnc_finalize_board_init(brd); rc = dgnc_finalize_board_init(brd);
if (rc < 0) { if (rc < 0) {
dgnc_tty_uninit(brd);
pr_err(DRVSTR ": Can't finalize board init (%d)\n", rc); pr_err(DRVSTR ": Can't finalize board init (%d)\n", rc);
brd->state = BOARD_FAILED;
brd->dpastatus = BD_NOFEP;
goto failed; goto failed;
} }
rc = dgnc_tty_init(brd); rc = dgnc_tty_init(brd);
if (rc < 0) { if (rc < 0) {
dgnc_tty_uninit(brd);
pr_err(DRVSTR ": Can't init tty devices (%d)\n", rc); pr_err(DRVSTR ": Can't init tty devices (%d)\n", rc);
brd->state = BOARD_FAILED;
brd->dpastatus = BD_NOFEP;
goto failed; goto failed;
} }
@ -606,6 +595,9 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
return 0; return 0;
failed: failed:
dgnc_tty_uninit(brd);
brd->state = BOARD_FAILED;
brd->dpastatus = BD_NOFEP;
return -ENXIO; return -ENXIO;

View file

@ -1420,16 +1420,13 @@ static void neo_copy_data_from_queue_to_uart(struct channel_t *ch)
spin_lock_irqsave(&ch->ch_lock, flags); spin_lock_irqsave(&ch->ch_lock, flags);
/* No data to write to the UART */ /* No data to write to the UART */
if (ch->ch_w_tail == ch->ch_w_head) { if (ch->ch_w_tail == ch->ch_w_head)
spin_unlock_irqrestore(&ch->ch_lock, flags); goto exit_unlock;
return;
}
/* If port is "stopped", don't send any data to the UART */ /* If port is "stopped", don't send any data to the UART */
if ((ch->ch_flags & CH_FORCED_STOP) || (ch->ch_flags & CH_BREAK_SENDING)) { if ((ch->ch_flags & CH_FORCED_STOP) ||
spin_unlock_irqrestore(&ch->ch_lock, flags); (ch->ch_flags & CH_BREAK_SENDING))
return; goto exit_unlock;
}
/* /*
* If FIFOs are disabled. Send data directly to txrx register * If FIFOs are disabled. Send data directly to txrx register
@ -1470,27 +1467,23 @@ static void neo_copy_data_from_queue_to_uart(struct channel_t *ch)
ch->ch_w_tail &= WQUEUEMASK; ch->ch_w_tail &= WQUEUEMASK;
ch->ch_txcount++; ch->ch_txcount++;
} }
spin_unlock_irqrestore(&ch->ch_lock, flags);
return; goto exit_unlock;
} }
/* /*
* We have to do it this way, because of the EXAR TXFIFO count bug. * We have to do it this way, because of the EXAR TXFIFO count bug.
*/ */
if ((ch->ch_bd->dvid & 0xf0) < UART_XR17E158_DVID) { if ((ch->ch_bd->dvid & 0xf0) < UART_XR17E158_DVID) {
if (!(ch->ch_flags & (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM))) { if (!(ch->ch_flags & (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM)))
spin_unlock_irqrestore(&ch->ch_lock, flags); goto exit_unlock;
return;
}
len_written = 0; len_written = 0;
n = readb(&ch->ch_neo_uart->tfifo); n = readb(&ch->ch_neo_uart->tfifo);
if ((unsigned int) n > ch->ch_t_tlevel) { if ((unsigned int) n > ch->ch_t_tlevel)
spin_unlock_irqrestore(&ch->ch_lock, flags); goto exit_unlock;
return;
}
n = UART_17158_TX_FIFOSIZE - ch->ch_t_tlevel; n = UART_17158_TX_FIFOSIZE - ch->ch_t_tlevel;
} else { } else {
@ -1554,6 +1547,7 @@ static void neo_copy_data_from_queue_to_uart(struct channel_t *ch)
ch->ch_flags &= ~(CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM); ch->ch_flags &= ~(CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
} }
exit_unlock:
spin_unlock_irqrestore(&ch->ch_lock, flags); spin_unlock_irqrestore(&ch->ch_lock, flags);
} }