mirror-linux/drivers/parport
Ben Hutchings ef15ccbb3e parport: Fix race between port and client registration
The parport subsystem registers port devices before they are fully
initialised, resulting in a race condition where client drivers such
as lp can attach to ports that are not completely initialised or even
being torn down.

When the port and client drivers are built as modules and loaded
around the same time during boot, this occasionally results in a
crash.  I was able to make this happen reliably in a VM with a
PC-style parallel port by patching parport_pc to fail probing:

> --- a/drivers/parport/parport_pc.c
> +++ b/drivers/parport/parport_pc.c
> @@ -2069,7 +2069,7 @@ static struct parport *__parport_pc_probe_port(unsigned long int base,
>  	if (!p)
>  		goto out3;
>
> -	base_res = request_region(base, 3, p->name);
> +	base_res = NULL;
>  	if (!base_res)
>  		goto out4;
>

and then running:

    while true; do
        modprobe lp & modprobe parport_pc
	wait
	rmmod lp parport_pc
    done

for a few seconds.

In the long term I think port registration should be changed to put
the call to device_add() inside parport_announce_port(), but since the
latter currently cannot fail this will require changing all port
drivers.

For now, add a flag to indicate whether a port has been "announced"
and only try to attach client drivers to ports when the flag is set.

Fixes: 6fa45a2268 ("parport: add device-model to parport subsystem")
Closes: https://bugs.debian.org/1130365
Closes: https://lore.kernel.org/all/6ba903ad-9897-42bb-8c2d-337385cc3746@molgen.mpg.de/
Cc: stable <stable@kernel.org>
Signed-off-by: Ben Hutchings <benh@debian.org>
Acked-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Link: https://patch.msgid.link/afo6uBv68GDevbMD@decadent.org.uk
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2026-05-22 12:19:02 +02:00
..
BUGS-parport
Kconfig parport: PC style parport depends on HAS_IOPORT 2023-05-31 19:17:40 +01:00
Makefile parport: remove ax88796 driver 2023-01-16 09:26:06 +01:00
TODO-parport parport: Remove completed item from to-do list 2026-04-02 17:05:56 +02:00
daisy.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
ieee1284.c treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
ieee1284_ops.c
multiface.h
parport_amiga.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
parport_atari.c
parport_cs.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
parport_gsc.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
parport_gsc.h parport: gsc: remove DMA leftover code 2023-08-03 14:40:37 +02:00
parport_ip32.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
parport_mfc3.c parport: mfc3: avoid empty-body warning 2024-04-11 15:14:10 +02:00
parport_pc.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
parport_serial.c serial: 8250_pci: Share WCH IDs with parport_serial driver 2024-12-04 16:42:55 +01:00
parport_sunbpp.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
probe.c
procfs.c parport: Proper fix for array out-of-bounds access 2024-10-13 18:17:35 +02:00
share.c parport: Fix race between port and client registration 2026-05-22 12:19:02 +02:00