Module Name:    src
Committed By:   thorpej
Date:           Thu Feb  4 23:29:16 UTC 2021

Modified Files:
        src/sys/kern: subr_device.c
        src/sys/sys: device.h

Log Message:
Add device_attached_to_iattr(), which return true if the device
attached to the specified interface attribute.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/kern/subr_device.c
cvs rdiff -u -r1.164 -r1.165 src/sys/sys/device.h

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_device.c
diff -u src/sys/kern/subr_device.c:1.4 src/sys/kern/subr_device.c:1.5
--- src/sys/kern/subr_device.c:1.4	Thu Jan 28 15:53:46 2021
+++ src/sys/kern/subr_device.c	Thu Feb  4 23:29:16 2021
@@ -1,7 +1,7 @@
-/*	$NetBSD: subr_device.c,v 1.4 2021/01/28 15:53:46 thorpej Exp $	*/
+/*	$NetBSD: subr_device.c,v 1.5 2021/02/04 23:29:16 thorpej Exp $	*/
 
 /*
- * Copyright (c) 2006 The NetBSD Foundation, Inc.
+ * Copyright (c) 2006, 2021 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_device.c,v 1.4 2021/01/28 15:53:46 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_device.c,v 1.5 2021/02/04 23:29:16 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -39,6 +39,7 @@ device_t			root_device;
 /*
  * Accessor functions for the device_t type.
  */
+
 devclass_t
 device_class(device_t dev)
 {
@@ -182,3 +183,22 @@ device_is_a(device_t dev, const char *dn
 
 	return strcmp(dev->dv_cfdriver->cd_name, dname) == 0;
 }
+
+/*
+ * device_attached_to_iattr:
+ *
+ *	Returns true if the device attached to the specified interface
+ *	attribute.
+ */
+bool
+device_attached_to_iattr(device_t dev, const char *iattr)
+{
+	cfdata_t cfdata = device_cfdata(dev);
+	const struct cfparent *pspec;
+
+	if (cfdata == NULL || (pspec = cfdata->cf_pspec) == NULL) {
+		return false;
+	}
+
+	return strcmp(pspec->cfp_iattr, iattr) == 0;
+}

Index: src/sys/sys/device.h
diff -u src/sys/sys/device.h:1.164 src/sys/sys/device.h:1.165
--- src/sys/sys/device.h:1.164	Wed Jan 27 04:54:08 2021
+++ src/sys/sys/device.h	Thu Feb  4 23:29:16 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: device.h,v 1.164 2021/01/27 04:54:08 thorpej Exp $ */
+/* $NetBSD: device.h,v 1.165 2021/02/04 23:29:16 thorpej Exp $ */
 
 /*
  * Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -544,6 +544,7 @@ void		device_active_deregister(device_t,
 				         void (*)(device_t, devactive_t));
 
 bool		device_is_a(device_t, const char *);
+bool		device_attached_to_iattr(device_t, const char *);
 
 device_t	device_find_by_xname(const char *);
 device_t	device_find_by_driver_unit(const char *, int);

Reply via email to