From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 7644536165E for ; Fri, 8 May 2026 19:13:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778267598; cv=none; b=f4H0ozCPRIhMLKPYLtPMOKUZybgnuClukbed9GZpDnNwkR2Pq4ZS38/DgPRNBJBiIxTaxPmQn2GFJfXbS/E55f1asb6cgSBIBS9XzcX7IEQoIUrMwPTSl+k0SWpGJesYm5a1eP3Dy053z9nmomY2ZDQX0iZVCia2t9Q/6xCHqUA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778267598; c=relaxed/simple; bh=m+PNYt/eWysm9k+FR9iBvcdxWi6AKRQIzayYMpLkT6k=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Gca0o/zU8fsRiAozY1lyjeys0bCcLBj99uoJY5EvvYroQBPD7ogR61CaCspBrod3lFIQmKz5GGjQLVloyVexK0/+loi18b75Oaz5SU1GWRm7iUYm4Wqs0vgOQkjiOP6a7/Doh8Aj4+QsO/N38b+yjg4O7F6ThhKYmsnYOzjeO/8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=pKDjQX5+; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pKDjQX5+" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-4832c8f9d87so2553325e9.3 for ; Fri, 08 May 2026 12:13:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778267596; x=1778872396; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Ss2dNfL6Ott2JQyZMGJaHzME4Ht5awruV2D2eXagSaA=; b=pKDjQX5+qWTk26476bUO0x2YWtQLxK2f0Qfo9Ds42eZPIiX8I/5JzH6XYtR4pVhHda vxbDGQhI1Rtjju2stU4SrKxoisQDn+pES3dvYCM0+WNFjsx/MY3GnHvo+LDniVRZswq0 MEnWCkY6EwIns5s0Fo9p5zNyJ0UGDnjndJNGolccCDn/7Kt+K3M5Hg6oC+d4B5mB1PJV +ibi9kfHGO61F37k2fGtMJ43m6iDdOjTdk3l6nNlQxe011S6k7VGoJHi6ivOU20iDaOx ZG3alHfEmVkWuh+bGA/5eCnN5nLLSlFens11Obk+BG0gCpEFAoa9e2LEe3dUTdsr02+E /U2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778267596; x=1778872396; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Ss2dNfL6Ott2JQyZMGJaHzME4Ht5awruV2D2eXagSaA=; b=A2ZeSrN3WspBIg+DyN6ODp9kibOcIQC+iiNoIe5kKtjO0g4xxxqfkJFfe1gxS3CKsi IZXVhAjAL9hkxON/2yCGhfD+vA7AfPovP/eV2iTbzTitVOPAlX3kKT+KCNBQWrmONTSY QMHXJXhWTrm+hifEO+JYCf+uC4NLucX87NE78ea6oEGDv/I9o5jPkyoZUw6I+6rZC96o C5Mg8+awZN2HRBgMECKaEDl8N8LMlovz5XcbEYxbx15m6WaS1NYz/pMLyYHfqsj5PVA1 q2UUy3z77r53nb30fKoLnYnlAyD0dcFNSpFJ7A580PYiWQ0WwC5mmUoPOAFjJHuE78PV ybIg== X-Forwarded-Encrypted: i=1; AFNElJ9ymFlD6PLfrde9F/Wv2WeOXC0CDMWOom0ujogHwV97f5Y5sXmqf+jyyMgEIP/QIPBrVZLDHtLcSZblzSI=@vger.kernel.org X-Gm-Message-State: AOJu0Ywq7njK4QV2AE4RRaZPNr+aCUzoi0GTyAl/IQteSpT0YwyvvIhO 1lOhy/w15B2xGdJz7EyBV8S+IV8bjr/ZoI3Dl6/OAKON3fSbbbHMF5D2 X-Gm-Gg: AeBDietcIYI2Pn1sbVEKCEfNAk5m8hUJCt59rtYAE1wZYzfz4Ir3BQUIk2Nrc+Kt3Hs Rc35tgW1A/EOlp/V5Ex/AfUZmc2LSSuKVpXG6c3bC/hJcGRudee5PTSQzorwe3N2ojk/5BsJRho coFi8hX0viE1IgJD+U8NWJax+blxe4JPzGVgow4/5pD4lhACkCQQ5KgeWMoY5vQiXZ3dk8z0yg6 UAdYGITb4uRp1qlMh8PweZSpjS8PZEtd1wUi8vYZM9Z4DchDkoDTJ21FAPebs2KlcbXg7OwPMfL IHsO4aHjaXICh8mRhqhbdcnu0hIYqclcbix7v0qnton9LjTYJGzNxbYy6ncSTyOfia79HK+yyoS CIuHcn+S/8JlymI5GNZ6Ovq6RbYR9P4oaN0pu9eSD0ST0BbXWDYPseU92s8uZKBAldt6g8Ez9yh WnQw7NcJ5FysauJ24PxLIzNDBJeJod28HobmE/vxnY/fs= X-Received: by 2002:a05:600c:46d2:b0:488:7e7b:dbc2 with SMTP id 5b1f17b1804b1-48e51f4539cmr107036435e9.3.1778267595629; Fri, 08 May 2026 12:13:15 -0700 (PDT) Received: from localhost.localdomain ([94.158.58.43]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e6d8946a5sm13333695e9.0.2026.05.08.12.13.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 May 2026 12:13:15 -0700 (PDT) From: Stepan Ionichev To: gregkh@linuxfoundation.org Cc: jirislaby@kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Stepan Ionichev Subject: [PATCH] tty: serial: 8250: protect against NULL uart->port.dev in register Date: Fri, 8 May 2026 23:12:37 +0500 Message-Id: <20260508181237.11146-1-sozdayvek@gmail.com> X-Mailer: git-send-email 2.33.0.windows.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit serial8250_register_8250_port() conditionally copies uart->port.dev from up->port.dev only when up->port.dev is non-NULL: if (up->port.dev) { uart->port.dev = up->port.dev; ... } So if both the existing uart slot and up have a NULL ->dev, uart->port.dev remains NULL. The very next ACPI companion check then dereferences it unconditionally: if (!has_acpi_companion(uart->port.dev)) { has_acpi_companion() reads dev->fwnode without a NULL guard (include/linux/acpi.h), so this NULL-derefs the kernel for the remaining no-dev case rather than just skipping the mctrl_gpio_init() initialisation as intended. smatch flags the inconsistency: drivers/tty/serial/8250/8250_core.c:767 serial8250_register_8250_port() error: 'uart->port.dev' could be null (see line 719) Guard the call with a NULL check so register continues to work for callers that legitimately have no parent device (legacy non-OF/non-ACPI registrations). No functional change for callers that pass a non-NULL ->dev. Signed-off-by: Stepan Ionichev --- drivers/tty/serial/8250/8250_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c index a428e8893..e136cec0c 100644 --- a/drivers/tty/serial/8250/8250_core.c +++ b/drivers/tty/serial/8250/8250_core.c @@ -764,7 +764,7 @@ int serial8250_register_8250_port(const struct uart_8250_port *up) * Only call mctrl_gpio_init(), if the device has no ACPI * companion device */ - if (!has_acpi_companion(uart->port.dev)) { + if (uart->port.dev && !has_acpi_companion(uart->port.dev)) { struct mctrl_gpios *gpios = mctrl_gpio_init(&uart->port, 0); if (IS_ERR(gpios)) { ret = PTR_ERR(gpios); -- 2.43.0