diff options
author | Jiri Slaby <jslaby@suse.cz> | 2020-02-19 11:41:09 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2020-02-21 12:24:33 +0300 |
commit | 740708abbba281480f2986418c8acf2b540f0e98 (patch) | |
tree | 6f9ac5292a651c4ac2055d49f360f4775e6e64bd /drivers/tty/n_hdlc.c | |
parent | 844cc5f9e530da7502b0de69f0268b1fb0dd7ce3 (diff) | |
download | linux-740708abbba281480f2986418c8acf2b540f0e98.tar.xz |
n_hdlc: add helper for buffers allocation
Given both rx and tx allocations do the same, add a new helper
(n_hdlc_alloc_buf) and use it for both of them. This cleans up
n_hdlc_alloc slightly.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20200219084118.26491-15-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/n_hdlc.c')
-rw-r--r-- | drivers/tty/n_hdlc.c | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c index 2709d18364eb..4276931fd071 100644 --- a/drivers/tty/n_hdlc.c +++ b/drivers/tty/n_hdlc.c @@ -699,6 +699,23 @@ static __poll_t n_hdlc_tty_poll(struct tty_struct *tty, struct file *filp, return mask; } /* end of n_hdlc_tty_poll() */ +static void n_hdlc_alloc_buf(struct n_hdlc_buf_list *list, unsigned int count, + const char *name) +{ + struct n_hdlc_buf *buf; + unsigned int i; + + for (i = 0; i < count; i++) { + buf = kmalloc(struct_size(buf, buf, maxframe), GFP_KERNEL); + if (!buf) { + pr_debug("%s(%d)%s(), kmalloc() failed for %s buffer %u\n", + __FILE__, __LINE__, __func__, name, i); + return; + } + n_hdlc_buf_put(list, buf); + } +} + /** * n_hdlc_alloc - allocate an n_hdlc instance data structure * @@ -706,8 +723,6 @@ static __poll_t n_hdlc_tty_poll(struct tty_struct *tty, struct file *filp, */ static struct n_hdlc *n_hdlc_alloc(void) { - struct n_hdlc_buf *buf; - int i; struct n_hdlc *n_hdlc = kzalloc(sizeof(*n_hdlc), GFP_KERNEL); if (!n_hdlc) @@ -723,26 +738,9 @@ static struct n_hdlc *n_hdlc_alloc(void) INIT_LIST_HEAD(&n_hdlc->rx_buf_list.list); INIT_LIST_HEAD(&n_hdlc->tx_buf_list.list); - /* allocate free rx buffer list */ - for(i=0;i<DEFAULT_RX_BUF_COUNT;i++) { - buf = kmalloc(struct_size(buf, buf, maxframe), GFP_KERNEL); - if (buf) - n_hdlc_buf_put(&n_hdlc->rx_free_buf_list,buf); - else - pr_debug("%s(%d)%s(), kmalloc() failed for rx buffer %d\n", - __FILE__, __LINE__, __func__, i); - } - - /* allocate free tx buffer list */ - for(i=0;i<DEFAULT_TX_BUF_COUNT;i++) { - buf = kmalloc(struct_size(buf, buf, maxframe), GFP_KERNEL); - if (buf) - n_hdlc_buf_put(&n_hdlc->tx_free_buf_list,buf); - else - pr_debug("%s(%d)%s(), kmalloc() failed for tx buffer %d\n", - __FILE__, __LINE__, __func__, i); - } - + n_hdlc_alloc_buf(&n_hdlc->rx_free_buf_list, DEFAULT_RX_BUF_COUNT, "rx"); + n_hdlc_alloc_buf(&n_hdlc->tx_free_buf_list, DEFAULT_TX_BUF_COUNT, "tx"); + /* Initialize the control block */ n_hdlc->magic = HDLC_MAGIC; |