Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern In device_is_a(), handle dev or dev->dv_cfdriver be...



details:   https://anonhg.NetBSD.org/src/rev/e87e2eceba89
branches:  trunk
changeset: 980230:e87e2eceba89
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Thu Jan 28 15:53:46 2021 +0000

description:
In device_is_a(), handle dev or dev->dv_cfdriver being NULL.  This
makes the calling pattern:

        device_is_a(device_parent(dev), "whatever")

safe.

diffstat:

 sys/kern/subr_device.c |  7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diffs (28 lines):

diff -r c67c003885c0 -r e87e2eceba89 sys/kern/subr_device.c
--- a/sys/kern/subr_device.c    Thu Jan 28 15:43:12 2021 +0000
+++ b/sys/kern/subr_device.c    Thu Jan 28 15:53:46 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_device.c,v 1.3 2015/03/09 15:35:11 pooka Exp $    */
+/*     $NetBSD: subr_device.c,v 1.4 2021/01/28 15:53:46 thorpej Exp $  */
 
 /*
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_device.c,v 1.3 2015/03/09 15:35:11 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_device.c,v 1.4 2021/01/28 15:53:46 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -176,6 +176,9 @@
 bool
 device_is_a(device_t dev, const char *dname)
 {
+       if (dev == NULL || dev->dv_cfdriver == NULL) {
+               return false;
+       }
 
        return strcmp(dev->dv_cfdriver->cd_name, dname) == 0;
 }



Home | Main Index | Thread Index | Old Index