NetBSD Problem Report #59834

From kre@munnari.OZ.AU  Sat Dec 13 10:14:37 2025
Return-Path: <kre@munnari.OZ.AU>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
	 client-signature RSA-PSS (2048 bits) client-digest SHA256)
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 813931A923A
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 13 Dec 2025 10:14:37 +0000 (UTC)
Message-Id: <202512131013.5BDADeGt006788@jacaranda.noi.kre.to>
Date: Sat, 13 Dec 2025 17:13:40 +0700 (+07)
From: kre@munnari.OZ.AU
To: gnats-bugs@NetBSD.org
Subject: ucomvar.h in x86/consinit.c needs termios.h - not guaranteed
X-Send-Pr-Version: 3.95

>Number:         59834
>Category:       kern
>Synopsis:       ucomvar.h in x86/consinit.c needs termios.h - not guaranteed
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Dec 13 10:15:00 +0000 2025
>Closed-Date:    Sat Dec 13 12:00:01 +0000 2025
>Last-Modified:  Sat Dec 13 12:00:01 +0000 2025
>Originator:     Robert Elz
>Release:        NetBSD 11.99.4
>Organization:
>Environment:


System: NetBSD jacaranda.noi.kre.to 11.99.4 NetBSD 11.99.4 (JACARANDA:1.1-20251124) #231: Mon Nov 24 20:19:24 +07 2025 kre@jacaranda.noi.kre.to:/usr/obj/testing/kernels/amd64/JACARANDA amd64
Architecture: x86_64
Machine: amd64
>Description:
	When the new ucom code was added, to allow USB devices to be
	the console (back at the end of last month - Nov 2025) an
	include of <dev/usb/ucomvar.h> was added to arch/x86/x86/consinit.c
	(& maybe to other places that don't affect me).

	ucomvar.h declares a function which takes a struct termios * as
	a parameter, but does not #include <sys/termios.h> - which can
	lead to x86/x86/consinit.c failing to compile.

	That isn't observed on most kernel builds, as x86/consinit.c
	includes <sys/termios.h> before including <dev/usb/ucomvar.h>
	in most builds - that is any which configure a com device.

	None of my recent hardware have any com devices at all, so
	I have deleted all "com* at <everything>" from my kernel
	config files.   That is, my (relevant) builds have NCOM==0

	In that case, <sys/termios.h> is not included in x86/consinit.c
	but (as I might one day plug in a USB com port device) I have
	ucom configured in (hence NUCOM > 0).

	gcc barfs:

In file included from .../src/sys/arch/x86/x86/consinit.c: 92:
 .../src/sys/dev/usb/ucomvar.h:83:47: error: 'struct termios' declared inside parameter list will not be visible outside of this definition or declaration [-Werror]
   83 |         int (*ucom_param)(void *, int, struct termios *);
      |                                               ^~~~~~~
cc1: all warnings being treated as errors

	Note that the undefined use of struct termios * in
	<dev/usb/ucomvar.h> is not new - that has been there since
	the file was created, but obviously, until the end of last month,
	that file has only been included in contexts where <sys/termios.h>
	had already been included.

>How-To-Repeat:
	Configure an x86 kernel without any com devices, but with ucom.
	(As best I can tell, that's all it takes).

>Fix:
	First, for this particular case, on x86 where NCOM==0 and NUCOM>0
	I am testing a fix as I am typing this PR, so there is no need for
	anyone to do anything.

	There are several ways this could be fixed.

	1) The #include of <sys/termios.h> in consinit.c could be made
	   unconditional - clearly it is safe to include there, as it
	   almost always happens anyway.   However, consinit.c only uses
	   anything from that header if NCOM>0 (not struct termios, it
	   uses some of the symbols defined in <sys/termios.h> like CSIZE
	   SDTOPB PARENB ...) so fixing this that way doesn't seem like
	   the right solution to me.

	2) A second #include of <sys/termios.h> could be added to
	   consinit.c in the #if NUCOM>0 case, immediately before
	   the #include of <dev/usb/ucomvar.h>.   That would solve the
	   problem, and work (<sys/termios.h> has double-include protection,
	   so including it twice in the case where NCOM>0 and NUCOM>0
	   would be harmless).   However, to me this seems even worse than
	   possible solution #1 - in the case where it makes a difference,
	   absolutely nothing in consinit.c needs anything from termios.h
	   at all, so I don't think this one is the right solution either.

	3) <dev/usb/ucomvar.h> could have a #include <sys/termios.h>
	   added to it - after all, it is referencing struct termios,
	   so arguably that should have been done when the reference
	   was added, back in January 2000, when ucomvar.h was added
	   (the reference to struct termios was in rev 1.1).
	   However, all the header uses "struct termios" for is to
	   declare a parameter of one function as being a "struct termios *"
	   so this, while perhaps the technically correct solution,
	   looks to be rather heavyweight to me.

	4) <dev/usb/ucomvar.h> could have an incomplete type definition of
	   struct termios added to it - that allows the declaration of a
	   pointer to the struct, which is all that ucomvar.h needs.
	   This is the solution I prefer, and the one I have implemented
	   (and doing this allows my kernels to build, which is, of
	   course, what matters ... I expect doing any of the previous 3
	   methods would have accomplished the same goal, but I didn't
	   test them.

	I will (immediately after this PR has cycled through gnats -
	my test builds succeeded while I have been typing this)
	be committing the fix I have used (#4 above).   If anyone has
	the desire (and energy to test) any other solution (one of
	the others above, or something different), please go ahead.

	If there is any possibility of something similar affecting
	any of the other ports, someone else is going to need to
	go and fix it (though unless something very odd has happened,
	it is likely that the fix about to be committed should work
	everywhere - anything that needs to actually use a struct termios
	should already be including <sys/termios.h> - the incomplete
	type definition in <dev/usb/ucomvar.h> would then be completed.

>Release-Note:

>Audit-Trail:
From: "Robert Elz" <kre@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59834 CVS commit: src/sys/dev/usb
Date: Sat, 13 Dec 2025 10:20:20 +0000

 Module Name:	src
 Committed By:	kre
 Date:		Sat Dec 13 10:20:20 UTC 2025

 Modified Files:
 	src/sys/dev/usb: ucomvar.h

 Log Message:
 PR kern/59834 - handle undefined ref to struct termios

 See the PR for the gory details, and explanation of why
 this hasn't previously bothered anyone for the past 25
 (close to 26) years - but this file has had an undefined
 reference to struct termios in it ever since it was
 created.

 All we need (here) is an incomplete struct definition,
 so a pointer to the struct can be declared.  So, that
 is what this change does.

 For possible alternative changes, see the PR.

 XXX - pullup ??  (someone tell me if pullups, probably
 only to -11, should be requested for this - that is,
 if the ucom as console changes were pulled up).


 To generate a diff of this commit:
 cvs rdiff -u -r1.27 -r1.28 src/sys/dev/usb/ucomvar.h

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->needs-pullups
State-Changed-By: kre@NetBSD.org
State-Changed-When: Sat, 13 Dec 2025 10:39:26 +0000
State-Changed-Why:
Might need pullup to netbsd-11


From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: PR/59834 CVS commit: src/sys/dev/usb
Date: Sat, 13 Dec 2025 12:12:40 +0100

 On Sat, Dec 13, 2025 at 10:25:01AM +0000, Robert Elz wrote:
 >  XXX - pullup ??  (someone tell me if pullups, probably
 >  only to -11, should be requested for this - that is,
 >  if the ucom as console changes were pulled up).

 They have not been pulled up to any branch.

 Martin

State-Changed-From-To: needs-pullups->closed
State-Changed-By: kre@NetBSD.org
State-Changed-When: Sat, 13 Dec 2025 12:00:01 +0000
State-Changed-Why:
Thanks Martin, no pullups required, we are done


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.