n_hdlc: simplify freeing of buffer list
n_hdlc_release contains four loops to free each buffer list. Create a helper (n_hdlc_free_buf_list) and call it for every list instead. It makes n_hdlc_release more readable. We are switching from "for (;;)" to "do {} while (buf)" which avoids the "if (buf)" completely -- kfree is a nop for NULL pointers. Signed-off-by: Jiri Slaby <jslaby@suse.cz> Link: https://lore.kernel.org/r/20200219084118.26491-7-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
c549725ff8
commit
30fafd92c2
|
@ -215,6 +215,16 @@ static struct tty_ldisc_ops n_hdlc_ldisc = {
|
||||||
.flush_buffer = flush_rx_queue,
|
.flush_buffer = flush_rx_queue,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void n_hdlc_free_buf_list(struct n_hdlc_buf_list *list)
|
||||||
|
{
|
||||||
|
struct n_hdlc_buf *buf;
|
||||||
|
|
||||||
|
do {
|
||||||
|
buf = n_hdlc_buf_get(list);
|
||||||
|
kfree(buf);
|
||||||
|
} while (buf);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* n_hdlc_release - release an n_hdlc per device line discipline info structure
|
* n_hdlc_release - release an n_hdlc per device line discipline info structure
|
||||||
* @n_hdlc - per device line discipline info structure
|
* @n_hdlc - per device line discipline info structure
|
||||||
|
@ -222,7 +232,6 @@ static struct tty_ldisc_ops n_hdlc_ldisc = {
|
||||||
static void n_hdlc_release(struct n_hdlc *n_hdlc)
|
static void n_hdlc_release(struct n_hdlc *n_hdlc)
|
||||||
{
|
{
|
||||||
struct tty_struct *tty = n_hdlc2tty (n_hdlc);
|
struct tty_struct *tty = n_hdlc2tty (n_hdlc);
|
||||||
struct n_hdlc_buf *buf;
|
|
||||||
|
|
||||||
/* Ensure that the n_hdlcd process is not hanging on select()/poll() */
|
/* Ensure that the n_hdlcd process is not hanging on select()/poll() */
|
||||||
wake_up_interruptible (&tty->read_wait);
|
wake_up_interruptible (&tty->read_wait);
|
||||||
|
@ -231,37 +240,11 @@ static void n_hdlc_release(struct n_hdlc *n_hdlc)
|
||||||
if (tty->disc_data == n_hdlc)
|
if (tty->disc_data == n_hdlc)
|
||||||
tty->disc_data = NULL; /* Break the tty->n_hdlc link */
|
tty->disc_data = NULL; /* Break the tty->n_hdlc link */
|
||||||
|
|
||||||
/* Release transmit and receive buffers */
|
n_hdlc_free_buf_list(&n_hdlc->rx_free_buf_list);
|
||||||
for(;;) {
|
n_hdlc_free_buf_list(&n_hdlc->tx_free_buf_list);
|
||||||
buf = n_hdlc_buf_get(&n_hdlc->rx_free_buf_list);
|
n_hdlc_free_buf_list(&n_hdlc->rx_buf_list);
|
||||||
if (buf) {
|
n_hdlc_free_buf_list(&n_hdlc->tx_buf_list);
|
||||||
kfree(buf);
|
|
||||||
} else
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
for(;;) {
|
|
||||||
buf = n_hdlc_buf_get(&n_hdlc->tx_free_buf_list);
|
|
||||||
if (buf) {
|
|
||||||
kfree(buf);
|
|
||||||
} else
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
for(;;) {
|
|
||||||
buf = n_hdlc_buf_get(&n_hdlc->rx_buf_list);
|
|
||||||
if (buf) {
|
|
||||||
kfree(buf);
|
|
||||||
} else
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
for(;;) {
|
|
||||||
buf = n_hdlc_buf_get(&n_hdlc->tx_buf_list);
|
|
||||||
if (buf) {
|
|
||||||
kfree(buf);
|
|
||||||
} else
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
kfree(n_hdlc);
|
kfree(n_hdlc);
|
||||||
|
|
||||||
} /* end of n_hdlc_release() */
|
} /* end of n_hdlc_release() */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue