Message ID | 20231216173409.1264655-1-michael@amarulasolutions.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-2295-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp343594dyi; Sat, 16 Dec 2023 09:34:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IGLLTAvV3DSqANtvDC9lyyX8iawVvbvo275O/fXbrb4Dxhkh1wPcGBMAaMfd4J0GpB1qp9r X-Received: by 2002:a17:906:c105:b0:a0c:5bf7:c675 with SMTP id do5-20020a170906c10500b00a0c5bf7c675mr8441717ejc.40.1702748074758; Sat, 16 Dec 2023 09:34:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702748074; cv=none; d=google.com; s=arc-20160816; b=IfUvLyInphGLA24xqPbwdSyIFcIk2wPO+roJPp3IOB6wsViNXnpifOnftMWhqTmW5/ ARUjo4WEDfS6ttDx9B/igDPiong+36D/Ky05/0O0hxLQ/SKfnyEJqLchVzGlhXyhOWT6 wjK1trn2vlQsgpe5kwwvUXHRNK7t/PDZj4lI1LEFgwqUIC0UtOBlZjeBZA8HV3ORzTqS lQUjgk31CwOt+eUWCDk2YQ3+sFblnFA3uEoTx4moo7QF6VW8DdrDpVcgjZAhI7xUzwYn 6+jInQ9gxSU+TuI+LMoV+WL9glud6WEawEhzWnhiqFlx7+WfELUMx2p/41O6icN9EPl2 dzhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=LcNKbo+ErH20rVL2cPgRZ8ez+d9bV/DiPHkp7E+gUxc=; fh=Lx141xXmGInNxjfD5gasYDNKWbbveTWfFwwzpxhFf8Y=; b=uC+o029mgzrv5+GZGlHkYMZtk6bx8OdY6XxWSOQCj9JCIgBF2HUf7NnxU2gub/d+l7 t6Yp+r6wVDdRUbkGcu71CWOcjdmoR5GLL2mDoynpe4b7/x6bsQk72NAp3T1/6LgZB3yr y5dz2TnDM3zsPAQoD2VMbC8YXUdMSWTjN+L1yxbKe/SStidt3TbyqYGkmc4oCpxK5sb2 SvM8L0sOyvfAKKrb8io3h9dZM5dBrWm9X9+QNHFDe9R1Q81pxrp+TvVUU4B3BqHCczjE QfmxkOdA/7ROtfNJemyckKEV4a+/I/U7V/jRHQdk79F5JAEY9n+xmay1PAZ/zK2+s7wV fl6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="ZugbDB4/"; spf=pass (google.com: domain of linux-kernel+bounces-2295-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2295-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id jt24-20020a170906dfd800b00a2311d38e4bsi2442364ejc.197.2023.12.16.09.34.34 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Dec 2023 09:34:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-2295-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="ZugbDB4/"; spf=pass (google.com: domain of linux-kernel+bounces-2295-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2295-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 369951F23E85 for <ouuuleilei@gmail.com>; Sat, 16 Dec 2023 17:34:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6F4CC30FBF; Sat, 16 Dec 2023 17:34:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b="ZugbDB4/" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DC3A30CFA for <linux-kernel@vger.kernel.org>; Sat, 16 Dec 2023 17:34:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amarulasolutions.com Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-336445a2749so1330572f8f.0 for <linux-kernel@vger.kernel.org>; Sat, 16 Dec 2023 09:34:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1702748054; x=1703352854; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LcNKbo+ErH20rVL2cPgRZ8ez+d9bV/DiPHkp7E+gUxc=; b=ZugbDB4/bxYHVvtkuVu7xvBaxs642sz4xxaeUCwWKO3BvvhwIPNbHhRjBWjxqsNyYP Yzvrl9M+fUarGq4WYmkfMDoTD+npFt+uby4unl6yV98K+wv0Qj9ks/3YlbAkAqLN9BTL ycEWOjrIueaBKuLIhdzzo6oaYAf0W+u+wJkR8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702748054; x=1703352854; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LcNKbo+ErH20rVL2cPgRZ8ez+d9bV/DiPHkp7E+gUxc=; b=ofSY+a9eB7JMUWVM/Fe/3YL1audqzue3M4fyK68MgBiq94mbDXBcX1/w8Fhvg5fBWJ BZkTPuSdvm1efE1IlBNK4IWmdzFiC51Zi0j+ss0HHEbfbsiH8qtGIVIDQwEXPjOJvNEs 54+i+mP6sheJkncoKe3IYMV+iW926gSFDNXO3+ab4ouFbu+qovolPATnCH15PB/P79lJ YgXNwKQ6gDiq4xPgB8q9dJkzXQv5qjxE/4v7jzpuhGmCP+6olyl7JOKoeH5aTTXeGuFy tgssj6nhXSWNp831enhxUkT3rsHlzMPqoL3uAb4coFWlnMinvoogyX7R3HYye4vtzABj qfMw== X-Gm-Message-State: AOJu0YysMCst9KsuJNQ4mbZoHZ1fNYQHbkSkAR073KwDY5fsOFtXoEv0 SCmn1Xjb980O4Ys28+jdwrErpvdgHhY5IoLeZnzbgq9U X-Received: by 2002:adf:f551:0:b0:336:5e1d:bac0 with SMTP id j17-20020adff551000000b003365e1dbac0mr723165wrp.4.1702748053546; Sat, 16 Dec 2023 09:34:13 -0800 (PST) Received: from panicking.QSD (net-91-81-8-146.cust.vodafonedsl.it. [91.81.8.146]) by smtp.gmail.com with ESMTPSA id u17-20020a5d5151000000b003365e685102sm2082491wrt.29.2023.12.16.09.34.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Dec 2023 09:34:13 -0800 (PST) From: Michael Trimarchi <michael@amarulasolutions.com> To: michael@amarulasolutions.com Cc: daniel.thompson@linaro.org, dianders@chromium.org, gregkh@linuxfoundation.org, jason.wessel@windriver.com, jirislaby@kernel.org, kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: [PATCH] tty: serial: kgdboc: Fix 8250_* kgd over serial Date: Sat, 16 Dec 2023 18:34:09 +0100 Message-Id: <20231216173409.1264655-1-michael@amarulasolutions.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231208212845.1679621-1-michael@amarulasolutions.com> References: <20231208212845.1679621-1-michael@amarulasolutions.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784750734923849303 X-GMAIL-MSGID: 1785460765321418420 |
Series |
tty: serial: kgdboc: Fix 8250_* kgd over serial
|
|
Commit Message
Michael Nazzareno Trimarchi
Dec. 16, 2023, 5:34 p.m. UTC
Check if port type is not PORT_UNKNOWN in the serial driver.
The kgdboc calls the tty_find_polling_driver that check
if the serial is able to use poll_init. The poll_init calls
the uart uart_poll_init that try to configure the uart with the
selected parameters. The uart must be ready and we can check it
using type as in other tty_io functions.
The crash happen for instance in am62x architecture where the 8250
register the platform driver after the 8250 core is initialized.
As shown by kdbg the iobase and membase is not configured
Thread 2 received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1]
_outb (addr=<optimized out>, value=<optimized out>) at ./include/asm-generic/io.h:584
584 __raw_writeb(value, PCI_IOBASE + addr);
(gdb) bt
This section of the code is too early because in this case
the omap serial is not probed
Thread 2 received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1]
_outb (addr=<optimized out>, value=<optimized out>) at ./include/asm-generic/io.h:584
584 __raw_writeb(value, PCI_IOBASE + addr);
(gdb) bt
Thread 2 received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1]
_outb (addr=<optimized out>, value=<optimized out>) at ./include/asm-generic/io.h:584
584 __raw_writeb(value, PCI_IOBASE + addr);
(gdb) bt
0 _outb (addr=<optimized out>, value=<optimized out>) at ./include/asm-generic/io.h:584
1 logic_outb (value=0 '\000', addr=18446739675637874689) at lib/logic_pio.c:299
2 0xffff80008082dfcc in io_serial_out (p=0x0, offset=16760830, value=0) at drivers/tty/serial/8250/8250_port.c:416
3 0xffff80008082fe34 in serial_port_out (value=<optimized out>, offset=<optimized out>, up=<optimized out>)
at ./include/linux/serial_core.h:677
4 serial8250_do_set_termios (port=0xffff8000828ee940 <serial8250_ports+1568>, termios=0xffff80008292b93c, old=0x0)
at drivers/tty/serial/8250/8250_port.c:2860
5 0xffff800080830064 in serial8250_set_termios (port=0xfffffbfffe800000, termios=0xffbffe, old=0x0)
at drivers/tty/serial/8250/8250_port.c:2912
6 0xffff80008082571c in uart_set_options (port=0xffff8000828ee940 <serial8250_ports+1568>, co=0x0, baud=115200, parity=110, bits=8, flow=110)
at drivers/tty/serial/serial_core.c:2285
7 0xffff800080828434 in uart_poll_init (driver=0xfffffbfffe800000, line=16760830, options=0xffff8000828f7506 <config+6> "115200n8")
at drivers/tty/serial/serial_core.c:2656
8 0xffff800080801690 in tty_find_polling_driver (name=0xffff8000828f7500 <config> "ttyS2,115200n8", line=0xffff80008292ba90)
at drivers/tty/tty_io.c:410
9 0xffff80008086c0b0 in configure_kgdboc () at drivers/tty/serial/kgdboc.c:194
10 0xffff80008086c1ec in kgdboc_probe (pdev=0xfffffbfffe800000) at drivers/tty/serial/kgdboc.c:249
11 0xffff8000808b399c in platform_probe (_dev=0xffff000000ebb810) at drivers/base/platform.c:1404
12 0xffff8000808b0b44 in call_driver_probe (drv=<optimized out>, dev=<optimized out>) at drivers/base/dd.c:579
13 really_probe (dev=0xffff000000ebb810, drv=0xffff80008277f138 <kgdboc_platform_driver+48>) at drivers/base/dd.c:658
14 0xffff8000808b0d2c in __driver_probe_device (drv=0xffff80008277f138 <kgdboc_platform_driver+48>, dev=0xffff000000ebb810)
at drivers/base/dd.c:800
15 0xffff8000808b0eb8 in driver_probe_device (drv=0xfffffbfffe800000, dev=0xffff000000ebb810) at drivers/base/dd.c:830
16 0xffff8000808b0ff4 in __device_attach_driver (drv=0xffff80008277f138 <kgdboc_platform_driver+48>, _data=0xffff80008292bc48)
at drivers/base/dd.c:958
17 0xffff8000808ae970 in bus_for_each_drv (bus=0xfffffbfffe800000, start=0x0, data=0xffff80008292bc48,
fn=0xffff8000808b0f3c <__device_attach_driver>) at drivers/base/bus.c:457
18 0xffff8000808b1408 in __device_attach (dev=0xffff000000ebb810, allow_async=true) at drivers/base/dd.c:1030
19 0xffff8000808b16d8 in device_initial_probe (dev=0xfffffbfffe800000) at drivers/base/dd.c:1079
20 0xffff8000808af9f4 in bus_probe_device (dev=0xffff000000ebb810) at drivers/base/bus.c:532
21 0xffff8000808ac77c in device_add (dev=0xfffffbfffe800000) at drivers/base/core.c:3625
22 0xffff8000808b3428 in platform_device_add (pdev=0xffff000000ebb800) at drivers/base/platform.c:716
23 0xffff800081b5dc0c in init_kgdboc () at drivers/tty/serial/kgdboc.c:292
24 0xffff800080014db0 in do_one_initcall (fn=0xffff800081b5dba4 <init_kgdboc>) at init/main.c:1236
25 0xffff800081b0114c in do_initcall_level (command_line=<optimized out>, level=<optimized out>) at init/main.c:1298
26 do_initcalls () at init/main.c:1314
27 do_basic_setup () at init/main.c:1333
28 kernel_init_freeable () at init/main.c:1551
29 0xffff8000810271ec in kernel_init (unused=0xfffffbfffe800000) at init/main.c:1441
30 0xffff800080015e80 in ret_from_fork () at arch/arm64/kernel/entry.S:857
Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
---
RFC -> v1:
- refuse uart that has type PORT_UNKNOWN
---
drivers/tty/serial/serial_core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
Hi Michael, kernel test robot noticed the following build errors: [auto build test ERROR on tty/tty-testing] [also build test ERROR on tty/tty-next tty/tty-linus linus/master v6.7-rc5 next-20231215] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Michael-Trimarchi/tty-serial-kgdboc-Fix-8250_-kgd-over-serial/20231217-013726 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git tty-testing patch link: https://lore.kernel.org/r/20231216173409.1264655-1-michael%40amarulasolutions.com patch subject: [PATCH] tty: serial: kgdboc: Fix 8250_* kgd over serial config: i386-buildonly-randconfig-003-20231217 (https://download.01.org/0day-ci/archive/20231217/202312171302.vjOAqLOI-lkp@intel.com/config) compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231217/202312171302.vjOAqLOI-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202312171302.vjOAqLOI-lkp@intel.com/ All errors (new ones prefixed by >>): >> drivers/tty/serial/serial_core.c:2636:26: error: expression is not assignable if (!port || port->type = PORT_UNKNOWN || !(port->ops->poll_get_char && port->ops->poll_put_char)) { ~~~~~~~~~~~~~~~~~~~ ^ 1 error generated. vim +2636 drivers/tty/serial/serial_core.c 2618 2619 static int uart_poll_init(struct tty_driver *driver, int line, char *options) 2620 { 2621 struct uart_driver *drv = driver->driver_state; 2622 struct uart_state *state = drv->state + line; 2623 enum uart_pm_state pm_state; 2624 struct tty_port *tport; 2625 struct uart_port *port; 2626 int baud = 9600; 2627 int bits = 8; 2628 int parity = 'n'; 2629 int flow = 'n'; 2630 int ret = 0; 2631 2632 tport = &state->port; 2633 mutex_lock(&tport->mutex); 2634 2635 port = uart_port_check(state); > 2636 if (!port || port->type = PORT_UNKNOWN || !(port->ops->poll_get_char && port->ops->poll_put_char)) { 2637 ret = -1; 2638 goto out; 2639 } 2640 2641 pm_state = state->pm_state; 2642 uart_change_pm(state, UART_PM_STATE_ON); 2643 2644 if (port->ops->poll_init) { 2645 /* 2646 * We don't set initialized as we only initialized the hw, 2647 * e.g. state->xmit is still uninitialized. 2648 */ 2649 if (!tty_port_initialized(tport)) 2650 ret = port->ops->poll_init(port); 2651 } 2652 2653 if (!ret && options) { 2654 uart_parse_options(options, &baud, &parity, &bits, &flow); 2655 console_list_lock(); 2656 ret = uart_set_options(port, NULL, baud, parity, bits, flow); 2657 console_list_unlock(); 2658 } 2659 out: 2660 if (ret) 2661 uart_change_pm(state, pm_state); 2662 mutex_unlock(&tport->mutex); 2663 return ret; 2664 } 2665
Hi Michael, kernel test robot noticed the following build errors: [auto build test ERROR on tty/tty-testing] [also build test ERROR on tty/tty-next tty/tty-linus linus/master v6.7-rc5 next-20231215] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Michael-Trimarchi/tty-serial-kgdboc-Fix-8250_-kgd-over-serial/20231217-013726 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git tty-testing patch link: https://lore.kernel.org/r/20231216173409.1264655-1-michael%40amarulasolutions.com patch subject: [PATCH] tty: serial: kgdboc: Fix 8250_* kgd over serial config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20231217/202312171453.mT4pH4uH-lkp@intel.com/config) compiler: sh4-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231217/202312171453.mT4pH4uH-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202312171453.mT4pH4uH-lkp@intel.com/ All errors (new ones prefixed by >>): drivers/tty/serial/serial_core.c: In function 'uart_poll_init': >> drivers/tty/serial/serial_core.c:2636:33: error: lvalue required as left operand of assignment 2636 | if (!port || port->type = PORT_UNKNOWN || !(port->ops->poll_get_char && port->ops->poll_put_char)) { | ^ vim +2636 drivers/tty/serial/serial_core.c 2618 2619 static int uart_poll_init(struct tty_driver *driver, int line, char *options) 2620 { 2621 struct uart_driver *drv = driver->driver_state; 2622 struct uart_state *state = drv->state + line; 2623 enum uart_pm_state pm_state; 2624 struct tty_port *tport; 2625 struct uart_port *port; 2626 int baud = 9600; 2627 int bits = 8; 2628 int parity = 'n'; 2629 int flow = 'n'; 2630 int ret = 0; 2631 2632 tport = &state->port; 2633 mutex_lock(&tport->mutex); 2634 2635 port = uart_port_check(state); > 2636 if (!port || port->type = PORT_UNKNOWN || !(port->ops->poll_get_char && port->ops->poll_put_char)) { 2637 ret = -1; 2638 goto out; 2639 } 2640 2641 pm_state = state->pm_state; 2642 uart_change_pm(state, UART_PM_STATE_ON); 2643 2644 if (port->ops->poll_init) { 2645 /* 2646 * We don't set initialized as we only initialized the hw, 2647 * e.g. state->xmit is still uninitialized. 2648 */ 2649 if (!tty_port_initialized(tport)) 2650 ret = port->ops->poll_init(port); 2651 } 2652 2653 if (!ret && options) { 2654 uart_parse_options(options, &baud, &parity, &bits, &flow); 2655 console_list_lock(); 2656 ret = uart_set_options(port, NULL, baud, parity, bits, flow); 2657 console_list_unlock(); 2658 } 2659 out: 2660 if (ret) 2661 uart_change_pm(state, pm_state); 2662 mutex_unlock(&tport->mutex); 2663 return ret; 2664 } 2665
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index f1348a509552..aa07eb894a6e 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -2633,7 +2633,7 @@ static int uart_poll_init(struct tty_driver *driver, int line, char *options) mutex_lock(&tport->mutex); port = uart_port_check(state); - if (!port || !(port->ops->poll_get_char && port->ops->poll_put_char)) { + if (!port || port->type = PORT_UNKNOWN || !(port->ops->poll_get_char && port->ops->poll_put_char)) { ret = -1; goto out; }