提交 099165d5 编写于 作者: I Ilpo Järvinen 提交者: Laibin Qiu

serial: 8250_fintek: Check SER_RS485_RTS_* only with RS485

stable inclusion
from stable-4.19.247
commit e78a321c14ad4e96f3d215aad8bcb6cb55ddc442
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5FNPY
CVE: NA

--------------------------------

[ Upstream commit af017927 ]

SER_RS485_RTS_ON_SEND and SER_RS485_RTS_AFTER_SEND relate to behavior
within RS485 operation. The driver checks if they have the same value
which is not possible to realize with the hardware. The check is taken
regardless of SER_RS485_ENABLED flag and -EINVAL is returned when the
check fails, which creates problems.

This check makes it unnecessarily complicated to turn RS485 mode off as
simple zeroed serial_rs485 struct will trigger that equal values check.
In addition, the driver itself memsets its rs485 structure to zero when
RS485 is disabled but if userspace would try to make an TIOCSRS485
ioctl() call with the very same struct, it would end up failing with
-EINVAL which doesn't make much sense.

Resolve the problem by moving the check inside SER_RS485_ENABLED block.

Fixes: 7ecc7701 ("serial: 8250_fintek: Return -EINVAL on invalid configuration")
Cc: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Signed-off-by: NIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://lore.kernel.org/r/035c738-8ea5-8b17-b1d7-84a7b3aeaa51@linux.intel.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NYongqiang Liu <liuyongqiang13@huawei.com>
Signed-off-by: NLaibin Qiu <qiulaibin@huawei.com>
上级 f99eddb9
...@@ -197,12 +197,12 @@ static int fintek_8250_rs485_config(struct uart_port *port, ...@@ -197,12 +197,12 @@ static int fintek_8250_rs485_config(struct uart_port *port,
if (!pdata) if (!pdata)
return -EINVAL; return -EINVAL;
if (rs485->flags & SER_RS485_ENABLED) {
/* Hardware do not support same RTS level on send and receive */ /* Hardware do not support same RTS level on send and receive */
if (!(rs485->flags & SER_RS485_RTS_ON_SEND) == if (!(rs485->flags & SER_RS485_RTS_ON_SEND) ==
!(rs485->flags & SER_RS485_RTS_AFTER_SEND)) !(rs485->flags & SER_RS485_RTS_AFTER_SEND))
return -EINVAL; return -EINVAL;
if (rs485->flags & SER_RS485_ENABLED) {
memset(rs485->padding, 0, sizeof(rs485->padding)); memset(rs485->padding, 0, sizeof(rs485->padding));
config |= RS485_URA; config |= RS485_URA;
} else { } else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册