From 17bf1d36370fb16b3e96dd1c500c60c87d6e1af6 Mon Sep 17 00:00:00 2001 From: khorben Date: Tue, 31 Jan 2017 00:58:15 +0000 Subject: [PATCH] Always allow hdaudio(4) to suspend Sometimes hdaudio(4) can fail to attach, but the device remains in the tree. Even though the PMF registration is performed, it is explicitly de-registered in the code path for errors - therefore preventing suspending later. This patch makes sure PMF registration is performed accordingly upon errors as well. No objection on tech-kern@. Tested on a Lenovo ThinkPad T440s (amd64). XXX pull-up to netbsd-7 --- sys/dev/pci/hdaudio_pci.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sys/dev/pci/hdaudio_pci.c b/sys/dev/pci/hdaudio_pci.c index 5f1776ca6b4b..aaf4ee2dad26 100644 --- a/sys/dev/pci/hdaudio_pci.c +++ b/sys/dev/pci/hdaudio_pci.c @@ -1,4 +1,4 @@ -/* $NetBSD: hdaudio_pci.c,v 1.5 2016/12/16 11:34:52 nonaka Exp $ */ +/* $NetBSD: hdaudio_pci.c,v 1.6 2017/01/31 00:58:15 khorben Exp $ */ /* * Copyright (c) 2009 Precedence Technologies Ltd @@ -34,7 +34,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: hdaudio_pci.c,v 1.5 2016/12/16 11:34:52 nonaka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: hdaudio_pci.c,v 1.6 2017/01/31 00:58:15 khorben Exp $"); #include #include @@ -157,9 +157,6 @@ hdaudio_pci_attach(device_t parent, device_t self, void *opaque) } aprint_normal_dev(self, "interrupting at %s\n", intrstr); - if (!pmf_device_register(self, NULL, hdaudio_pci_resume)) - aprint_error_dev(self, "couldn't establish power handler\n"); - hdaudio_pci_reinit(sc); /* Attach bus-independent HD audio layer */ @@ -176,8 +173,12 @@ hdaudio_pci_attach(device_t parent, device_t self, void *opaque) csr &= ~(PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_BACKTOBACK_ENABLE); pci_conf_write(sc->sc_pc, sc->sc_tag, PCI_COMMAND_STATUS_REG, csr); - pmf_device_deregister(self); + + if (!pmf_device_register(self, NULL, NULL)) + aprint_error_dev(self, "couldn't establish power handler\n"); } + else if (!pmf_device_register(self, NULL, hdaudio_pci_resume)) + aprint_error_dev(self, "couldn't establish power handler\n"); } static int