diff options
Diffstat (limited to 'drivers/tty/serdev/serdev-ttyport.c')
-rw-r--r-- | drivers/tty/serdev/serdev-ttyport.c | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/drivers/tty/serdev/serdev-ttyport.c b/drivers/tty/serdev/serdev-ttyport.c index 302018d67efa..ce7ad0acee7a 100644 --- a/drivers/tty/serdev/serdev-ttyport.c +++ b/drivers/tty/serdev/serdev-ttyport.c | |||
@@ -1,14 +1,6 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0 | ||
1 | /* | 2 | /* |
2 | * Copyright (C) 2016-2017 Linaro Ltd., Rob Herring <robh@kernel.org> | 3 | * Copyright (C) 2016-2017 Linaro Ltd., Rob Herring <robh@kernel.org> |
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License version 2 and | ||
6 | * only version 2 as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | */ | 4 | */ |
13 | #include <linux/kernel.h> | 5 | #include <linux/kernel.h> |
14 | #include <linux/serdev.h> | 6 | #include <linux/serdev.h> |
@@ -96,16 +88,21 @@ static int ttyport_open(struct serdev_controller *ctrl) | |||
96 | struct serport *serport = serdev_controller_get_drvdata(ctrl); | 88 | struct serport *serport = serdev_controller_get_drvdata(ctrl); |
97 | struct tty_struct *tty; | 89 | struct tty_struct *tty; |
98 | struct ktermios ktermios; | 90 | struct ktermios ktermios; |
91 | int ret; | ||
99 | 92 | ||
100 | tty = tty_init_dev(serport->tty_drv, serport->tty_idx); | 93 | tty = tty_init_dev(serport->tty_drv, serport->tty_idx); |
101 | if (IS_ERR(tty)) | 94 | if (IS_ERR(tty)) |
102 | return PTR_ERR(tty); | 95 | return PTR_ERR(tty); |
103 | serport->tty = tty; | 96 | serport->tty = tty; |
104 | 97 | ||
105 | if (tty->ops->open) | 98 | if (!tty->ops->open || !tty->ops->close) { |
106 | tty->ops->open(serport->tty, NULL); | 99 | ret = -ENODEV; |
107 | else | 100 | goto err_unlock; |
108 | tty_port_open(serport->port, tty, NULL); | 101 | } |
102 | |||
103 | ret = tty->ops->open(serport->tty, NULL); | ||
104 | if (ret) | ||
105 | goto err_close; | ||
109 | 106 | ||
110 | /* Bring the UART into a known 8 bits no parity hw fc state */ | 107 | /* Bring the UART into a known 8 bits no parity hw fc state */ |
111 | ktermios = tty->termios; | 108 | ktermios = tty->termios; |
@@ -122,6 +119,14 @@ static int ttyport_open(struct serdev_controller *ctrl) | |||
122 | 119 | ||
123 | tty_unlock(serport->tty); | 120 | tty_unlock(serport->tty); |
124 | return 0; | 121 | return 0; |
122 | |||
123 | err_close: | ||
124 | tty->ops->close(tty, NULL); | ||
125 | err_unlock: | ||
126 | tty_unlock(tty); | ||
127 | tty_release_struct(tty, serport->tty_idx); | ||
128 | |||
129 | return ret; | ||
125 | } | 130 | } |
126 | 131 | ||
127 | static void ttyport_close(struct serdev_controller *ctrl) | 132 | static void ttyport_close(struct serdev_controller *ctrl) |