From owner-svn-src-head@freebsd.org Fri Apr 20 20:30:34 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 15DD1F9E581; Fri, 20 Apr 2018 20:30:34 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id BFA11734AA; Fri, 20 Apr 2018 20:30:33 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B662D1D18B; Fri, 20 Apr 2018 20:30:33 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w3KKUXcn037051; Fri, 20 Apr 2018 20:30:33 GMT (envelope-from manu@FreeBSD.org) Received: (from manu@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w3KKUXHs037049; Fri, 20 Apr 2018 20:30:33 GMT (envelope-from manu@FreeBSD.org) Message-Id: <201804202030.w3KKUXHs037049@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: manu set sender to manu@FreeBSD.org using -f From: Emmanuel Vadot Date: Fri, 20 Apr 2018 20:30:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r332843 - head/sys/dev/extres/regulator X-SVN-Group: head X-SVN-Commit-Author: manu X-SVN-Commit-Paths: head/sys/dev/extres/regulator X-SVN-Commit-Revision: 332843 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Apr 2018 20:30:34 -0000 Author: manu Date: Fri Apr 20 20:30:33 2018 New Revision: 332843 URL: https://svnweb.freebsd.org/changeset/base/332843 Log: regulator: Check status before disabling When disabling regulator when they are unused, check before is they are enabled. While here don't check the enable_cnt on the regulator entry as it is checked by regnode_stop. This solve the panic on any board using a fixed regulator that is driven by a gpio when the regulator is unused. Tested On: OrangePi One Pointy Hat to: myself Reported by: kevans, Milan Obuch (freebsd-arm@dino.sk) Modified: head/sys/dev/extres/regulator/regulator.c Modified: head/sys/dev/extres/regulator/regulator.c ============================================================================== --- head/sys/dev/extres/regulator/regulator.c Fri Apr 20 20:18:10 2018 (r332842) +++ head/sys/dev/extres/regulator/regulator.c Fri Apr 20 20:30:33 2018 (r332843) @@ -166,17 +166,19 @@ static void regulator_shutdown(void *dummy) { struct regnode *entry; + int status, ret; int disable = 1; REG_TOPO_SLOCK(); TUNABLE_INT_FETCH("hw.regulator.disable_unused", &disable); TAILQ_FOREACH(entry, ®node_list, reglist_link) { - if (entry->enable_cnt == 0 && - entry->std_param.always_on == 0 && disable) { + if (entry->std_param.always_on == 0 && disable) { if (bootverbose) printf("regulator: shuting down %s\n", entry->name); - regnode_stop(entry, 0); + ret = regnode_status(entry, &status); + if (ret == 0 && status == REGULATOR_STATUS_ENABLED) + regnode_stop(entry, 0); } } REG_TOPO_UNLOCK();