Module Name: src Committed By: buhrow Date: Mon Feb 13 19:07:14 UTC 2023
Modified Files: src/sys/kern: subr_devsw.c Log Message: When a device driver calls devsw_attach() it has the option of attaching a block device structure and a character device structure, or, just the character device structure. With the existing code, if a driver elects not to attach a block device structure and if it asks for a major number to be dynamically assigned to its character interface, that driver will not be able to detach and reattach its character driver interface. This is a very long standing bug which didn't come to light until we began using loadable kernel modules more heavily. this patch fixes this problem. With this patch in place, drivers that implement only a character device interface may detach and reattach that character interface as often as they need to. Fixes PR kern/57229 To generate a diff of this commit: cvs rdiff -u -r1.49 -r1.50 src/sys/kern/subr_devsw.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/subr_devsw.c diff -u src/sys/kern/subr_devsw.c:1.49 src/sys/kern/subr_devsw.c:1.50 --- src/sys/kern/subr_devsw.c:1.49 Sat Oct 29 10:52:36 2022 +++ src/sys/kern/subr_devsw.c Mon Feb 13 19:07:14 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_devsw.c,v 1.49 2022/10/29 10:52:36 riastradh Exp $ */ +/* $NetBSD: subr_devsw.c,v 1.50 2023/02/13 19:07:14 buhrow Exp $ */ /*- * Copyright (c) 2001, 2002, 2007, 2008 The NetBSD Foundation, Inc. @@ -69,7 +69,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: subr_devsw.c,v 1.49 2022/10/29 10:52:36 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_devsw.c,v 1.50 2023/02/13 19:07:14 buhrow Exp $"); #ifdef _KERNEL_OPT #include "opt_dtrace.h" @@ -397,7 +397,7 @@ devsw_attach(const char *devname, if (conv->d_name == NULL || strcmp(devname, conv->d_name) != 0) continue; - if (*bmajor < 0) + if ((bdev != NULL) && (*bmajor < 0)) *bmajor = conv->d_bmajor; if (*cmajor < 0) *cmajor = conv->d_cmajor;