From nobody Mon Sep 28 19:24:41 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 785D239D3EB; Tue, 18 Aug 2026 09:39:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787045976; cv=none; b=UDKqeUuBx9dF8wfWQb5byW5nW6Xi7glub8Myhna6u9r+njo8H6ScAV7meFapNy4UiCYLSIgrSHWC30tpNYVHXvoT1zXeUK2MJMTY7llcpXbPlQAxu0u5RR8w354P9bVP4xzFc7jBVTf2BTMMo0zsca9cQl1oCpaeLfSMk4CWsj8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787045976; c=relaxed/simple; bh=+EFe0PfFIAlIFxAaTH6NmDRVqhin9Q4iwJ6PVYc4UQk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Pn/BO8KTwrUaJVTs7+8UYttrKmhtuXbnnbv1Oc7EcBmoCHaBByXQnChTs9y07LGDTrTZLvmvUbIBmfb6UEbSPwGJONOgpFFWtG0e7GQVAPPjmosyGFD/H7iywHxFsSDXWnDlKqF5WrLHUEVymXV/FoTbT1X0NSks5ceh+58xZmw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: b3ce71a49ae811f19a56ed5b684f684d-20260818 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.19,REQID:09ef6b78-c2dc-46bc-871b-87190dfd182e,IP:0,U RL:0,TC:0,Content:-25,EDM:25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:0 X-CID-META: VersionHash:7db8b62,CLOUDID:02c3d268a92bb0d2ddc7d265a9d315e0,BulkI D:nil,BulkQuantity:0,SF:81|82|102|850|865|898,TC:nil,Content:0|15|50,EDM:5 ,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV :0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: b3ce71a49ae811f19a56ed5b684f684d-20260818 X-User: lilinmao@kylinos.cn Received: from localhost.localdomain [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 1530558210; Tue, 18 Aug 2026 17:39:26 +0800 From: Linmao Li To: Greg Kroah-Hartman , Jiri Slaby Cc: Crescent Hsieh , Andy Shevchenko , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Linmao Li Subject: [PATCH 1/3] serial: 8250_mxpcie: set the driver data before registering ports Date: Tue, 18 Aug 2026 17:39:16 +0800 Message-Id: <20260818093918.3190686-2-lilinmao@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260818093918.3190686-1-lilinmao@kylinos.cn> References: <20260818093918.3190686-1-lilinmao@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" mxpcie8250_rs485_config() looks the board up with dev_get_drvdata() on the PCI device, but pci_set_drvdata() only runs after the registration loop. Where mxpcie8250_setup_port() presets rs485.flags to SER_RS485_ENABLED, uart_configure_port() calls ->rs485_config() from inside serial8250_register_8250_port(), and the callback dereferences a NULL board pointer. Publish the driver data before the first port is registered. Fixes: d21a1509c623 ("serial: 8250_mxpcie: support serial interface mode sw= itching") Signed-off-by: Linmao Li --- drivers/tty/serial/8250/8250_mxpcie.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/8250/8250_mxpcie.c b/drivers/tty/serial/825= 0/8250_mxpcie.c index ce873fbd62e93..c0e3517d4e4ec 100644 --- a/drivers/tty/serial/8250/8250_mxpcie.c +++ b/drivers/tty/serial/8250/8250_mxpcie.c @@ -542,6 +542,8 @@ static int mxpcie8250_probe(struct pci_dev *pdev, const= struct pci_device_id *id =20 mxpcie8250_init_board(pdev, priv); =20 + pci_set_drvdata(pdev, priv); + up.port.dev =3D dev; up.port.irq =3D pdev->irq; up.port.uartclk =3D MOXA_PUART_BASE_BAUD * 16; @@ -578,7 +580,6 @@ static int mxpcie8250_probe(struct pci_dev *pdev, const= struct pci_device_id *id } priv->port[i].rx_trig_level =3D MOXA_PUART_RX_TRIG_DEFAULT; } - pci_set_drvdata(pdev, priv); =20 return 0; } --=20 2.25.1 From nobody Mon Sep 28 19:24:41 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1BF81448CE8; Tue, 18 Aug 2026 09:39:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787045981; cv=none; b=sMHGpOVyB7T7rDNxS2d/CLSEXm9214TbGzh+dwiowaExG3ROIqoZE/xlG8CjD2E+7vMms9BY1PvOPMHBiitxR/mK7oJlC3xbPmGVb71FV61sOs/pdbSXeDrBJT/Xq2ntPupWbLgYm1ELzl1KKAqgzwOKfzIXyfnxEG1TLiXqTdk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787045981; c=relaxed/simple; bh=YGGvLyjuVFKbu53Y/AZ7U+kAxE9qdfPgxuWYZTi0KCM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PHg9DV07+NcWlr0G2uSosp0yItvPR1AcdiUPHsrH6G1FMoKfPtYFN0k/wpO/Yx7UPxnIF9Q9l/hPRldbpGfKDFbXCKwAtod6pGhcFn5c9/00rFAMVbPOsH3JnVSLtya++p2NPes3WS5F679mbsgWi3XleroHjVqpx6f4RZyCFC4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: b58856d69ae811f19a56ed5b684f684d-20260818 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.19,REQID:656a1af8-8724-4de2-89ca-c1063ce96e8f,IP:0,U RL:0,TC:0,Content:-5,EDM:25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:20 X-CID-META: VersionHash:7db8b62,CLOUDID:d4173447bc66701c8e009505c14829aa,BulkI D:nil,BulkQuantity:0,SF:81|82|102|850|865|898,TC:nil,Content:0|15|50,EDM:5 ,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV :0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: b58856d69ae811f19a56ed5b684f684d-20260818 X-User: lilinmao@kylinos.cn Received: from localhost.localdomain [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 529868187; Tue, 18 Aug 2026 17:39:29 +0800 From: Linmao Li To: Greg Kroah-Hartman , Jiri Slaby Cc: Crescent Hsieh , Andy Shevchenko , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Linmao Li Subject: [PATCH 2/3] serial: 8250_mxpcie: fail the probe when a port cannot be registered Date: Tue, 18 Aug 2026 17:39:17 +0800 Message-Id: <20260818093918.3190686-3-lilinmao@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260818093918.3190686-1-lilinmao@kylinos.cn> References: <20260818093918.3190686-1-lilinmao@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When serial8250_register_8250_port() fails the loop only breaks out and the probe still returns success. The entries it did not reach keep the zero devm_kzalloc() left there, and the entry that failed keeps a negative error code. mxpcie8250_remove() then feeds all of them to serial8250_unregister_port(), which checks neither: line 0 unregisters a port this driver does not own, and the negative line indexes serial8250_ports[] out of bounds. Fail the probe instead, unregistering the ports registered so far. Fixes: 0481a041e956 ("serial: 8250: split Moxa PCIe serial board support ou= t of 8250_pci") Signed-off-by: Linmao Li --- drivers/tty/serial/8250/8250_mxpcie.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/8250/8250_mxpcie.c b/drivers/tty/serial/825= 0/8250_mxpcie.c index c0e3517d4e4ec..ddd02d5622ec4 100644 --- a/drivers/tty/serial/8250/8250_mxpcie.c +++ b/drivers/tty/serial/8250/8250_mxpcie.c @@ -570,14 +570,18 @@ static int mxpcie8250_probe(struct pci_dev *pdev, con= st struct pci_device_id *id dev_dbg(dev, "Setup PCI port: port %lx, irq %d, type %d\n", up.port.iobase, up.port.irq, up.port.iotype); =20 - priv->port[i].line =3D serial8250_register_8250_port(&up); - if (priv->port[i].line < 0) { + ret =3D serial8250_register_8250_port(&up); + if (ret < 0) { dev_err(dev, "Couldn't register serial port %lx, irq %d, type %d, error %d\n", up.port.iobase, up.port.irq, - up.port.iotype, priv->port[i].line); - break; + up.port.iotype, ret); + while (i--) + serial8250_unregister_port(priv->port[i].line); + + return ret; } + priv->port[i].line =3D ret; priv->port[i].rx_trig_level =3D MOXA_PUART_RX_TRIG_DEFAULT; } =20 --=20 2.25.1 From nobody Mon Sep 28 19:24:41 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F0A3449EA4; Tue, 18 Aug 2026 09:39:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787045980; cv=none; b=P+MqEM1MqdGvCVH2OPd4QnP/oMb95gOBa32N4w+MhI7Mq3DU0QoaDsMQhRHm+m5Ovb/KxDdKwozUW3MhxnbpInQNQ5TlhppAdh0huoh8ZyVIt/sR2oYNpblKPLSsQOvvPPoPr4eV/mYbn6UyfCLMIUnk+46utG07AF0OVTIcX4c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787045980; c=relaxed/simple; bh=4IoK/wKy91VljtjS/W0D5fC8iTeqrp3TDCvEjBk7mMw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jNTwirCQpCRus+z0asiYeHD/XiFjxkHuzLvvA5+0FOj48OWLpDTgZSGIV5lx1ngSy5Z0fSANcHCCE8knPsqN8mpjqSkSPC0x44scLfL3nJmrRk0UsdWJYxRjjO3dxteeXCm96zrw6zgCawEzAK/sYxJTXHgHg8h9kXrg1wwcmhU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: b6a6e79e9ae811f19a56ed5b684f684d-20260818 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.19,REQID:b539aa13-20c0-4179-88c9-9d355da0251d,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:7db8b62,CLOUDID:de7f13e3d55880741d133f6f2f557bbd,BulkI D:nil,BulkQuantity:0,SF:81|82|102|850|865|898,TC:nil,Content:0|15|50,EDM:- 3,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,A V:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: b6a6e79e9ae811f19a56ed5b684f684d-20260818 X-User: lilinmao@kylinos.cn Received: from localhost.localdomain [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 1524043102; Tue, 18 Aug 2026 17:39:31 +0800 From: Linmao Li To: Greg Kroah-Hartman , Jiri Slaby Cc: Crescent Hsieh , Andy Shevchenko , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Linmao Li Subject: [PATCH 3/3] serial: 8250_mxpcie: take the line settings from the new termios Date: Tue, 18 Aug 2026 17:39:18 +0800 Message-Id: <20260818093918.3190686-4-lilinmao@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260818093918.3190686-1-lilinmao@kylinos.cn> References: <20260818093918.3190686-1-lilinmao@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" mxpcie8250_set_termios() reads the line settings out of port->state->port.tty, which is only set once the port has been opened. uart_set_options() builds a termios of its own and calls ->set_termios() with no tty behind it, so using such a board as the console (console=3DttyS) dereferences a NULL tty during console setup, as does attaching kgdboc to it and resuming a suspended console from uart_resume_port(). Read the settings from the termios the serial core passes in instead. It holds the same values on the normal path - uart_change_line_settings() passes &tty->termios - and it is what serial8250_do_set_termios() right above already uses. Fixes: 55edf8511f47 ("serial: 8250_mxpcie: enable automatic RTS/CTS flow co= ntrol") Signed-off-by: Linmao Li Tested-by: Crescent Hsieh --- drivers/tty/serial/8250/8250_mxpcie.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/tty/serial/8250/8250_mxpcie.c b/drivers/tty/serial/825= 0/8250_mxpcie.c index ddd02d5622ec4..eba59f1724b78 100644 --- a/drivers/tty/serial/8250/8250_mxpcie.c +++ b/drivers/tty/serial/8250/8250_mxpcie.c @@ -217,8 +217,7 @@ static void mxpcie8250_set_termios(struct uart_port *po= rt, const struct ktermios *old) { struct uart_8250_port *up =3D up_to_u8250p(port); - struct tty_struct *tty =3D port->state->port.tty; - unsigned int cflag =3D tty->termios.c_cflag; + unsigned int cflag =3D new->c_cflag; u8 efr, val; =20 serial8250_do_set_termios(port, new, old); @@ -233,18 +232,20 @@ static void mxpcie8250_set_termios(struct uart_port *= port, up->port.status |=3D (UPSTAT_AUTORTS | UPSTAT_AUTOCTS); } /* Set on-chip software flow control character */ - serial_out(up, MOXA_PUART_XON1, START_CHAR(tty)); - serial_out(up, MOXA_PUART_XON2, START_CHAR(tty)); - serial_out(up, MOXA_PUART_XOFF1, STOP_CHAR(tty)); - serial_out(up, MOXA_PUART_XOFF2, STOP_CHAR(tty)); + serial_out(up, MOXA_PUART_XON1, new->c_cc[VSTART]); + serial_out(up, MOXA_PUART_XON2, new->c_cc[VSTART]); + serial_out(up, MOXA_PUART_XOFF1, new->c_cc[VSTOP]); + serial_out(up, MOXA_PUART_XOFF2, new->c_cc[VSTOP]); =20 - val =3D I_IXON(tty) ? MOXA_PUART_EFR_RX_FLOW_XON1_XOFF1 : MOXA_PUART_EFR_= RX_FLOW_DISABLED; + val =3D (new->c_iflag & IXON) ? MOXA_PUART_EFR_RX_FLOW_XON1_XOFF1 : + MOXA_PUART_EFR_RX_FLOW_DISABLED; FIELD_MODIFY(MOXA_PUART_EFR_RX_FLOW_MASK, &efr, val); =20 - val =3D I_IXOFF(tty) ? MOXA_PUART_EFR_TX_FLOW_XON1_XOFF1 : MOXA_PUART_EFR= _TX_FLOW_DISABLED; + val =3D (new->c_iflag & IXOFF) ? MOXA_PUART_EFR_TX_FLOW_XON1_XOFF1 : + MOXA_PUART_EFR_TX_FLOW_DISABLED; FIELD_MODIFY(MOXA_PUART_EFR_TX_FLOW_MASK, &efr, val); =20 - if (I_IXOFF(tty)) + if (new->c_iflag & IXOFF) up->port.status |=3D UPSTAT_AUTOXOFF; =20 serial_out(up, MOXA_PUART_EFR, efr); --=20 2.25.1