Module Name: src
Committed By: jmcneill
Date: Mon Dec 28 19:31:44 UTC 2020
Modified Files:
src/sys/dev/hdaudio: hdaudio.c
Log Message:
If the Subordinate Node Count returns 0 nodes, complain and return instead
of trying to kmem_zalloc 0 bytes later on.
To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/hdaudio/hdaudio.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/dev/hdaudio/hdaudio.c
diff -u src/sys/dev/hdaudio/hdaudio.c:1.12 src/sys/dev/hdaudio/hdaudio.c:1.13
--- src/sys/dev/hdaudio/hdaudio.c:1.12 Mon Dec 28 16:49:58 2020
+++ src/sys/dev/hdaudio/hdaudio.c Mon Dec 28 19:31:43 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: hdaudio.c,v 1.12 2020/12/28 16:49:58 jmcneill Exp $ */
+/* $NetBSD: hdaudio.c,v 1.13 2020/12/28 19:31:43 jmcneill Exp $ */
/*
* Copyright (c) 2009 Precedence Technologies Ltd <[email protected]>
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hdaudio.c,v 1.12 2020/12/28 16:49:58 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hdaudio.c,v 1.13 2020/12/28 19:31:43 jmcneill Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -698,6 +698,7 @@ hdaudio_attach_fg(struct hdaudio_functio
static void
hdaudio_codec_attach(struct hdaudio_codec *co)
{
+ struct hdaudio_softc *sc = co->co_host;
struct hdaudio_function_group *fg;
uint32_t vid, snc, fgrp;
int starting_node, num_nodes, nid;
@@ -714,7 +715,6 @@ hdaudio_codec_attach(struct hdaudio_code
return;
#ifdef HDAUDIO_DEBUG
- struct hdaudio_softc *sc = co->co_host;
uint32_t rid = hdaudio_command(co, 0, CORB_GET_PARAMETER,
COP_REVISION_ID);
hda_print(sc, "Codec%02X: %04X:%04X HDA %d.%d rev %d stepping %d\n",
@@ -725,6 +725,16 @@ hdaudio_codec_attach(struct hdaudio_code
starting_node = (snc >> 16) & 0xff;
num_nodes = snc & 0xff;
+ /*
+ * If the total number of nodes is 0, there's nothing we can do.
+ * This shouldn't happen, so complain about it.
+ */
+ if (num_nodes == 0) {
+ hda_error(sc, "Codec%02X: No subordinate nodes found (%08x)\n",
+ co->co_addr, snc);
+ return;
+ }
+
co->co_nfg = num_nodes;
co->co_fg = kmem_zalloc(co->co_nfg * sizeof(*co->co_fg), KM_SLEEP);