Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6759522rwn; Tue, 13 Sep 2022 08:39:19 -0700 (PDT) X-Google-Smtp-Source: AA6agR6GO1Vcu3Lxqp9bqNiH62k0Zzn4W7ufAEHGm0Xy3/23nzttRBb02ARxdbH8t8F/7C1rxHLm X-Received: by 2002:a17:907:3d9f:b0:77a:21d4:7310 with SMTP id he31-20020a1709073d9f00b0077a21d47310mr13864055ejc.279.1663083558855; Tue, 13 Sep 2022 08:39:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663083558; cv=none; d=google.com; s=arc-20160816; b=qavwKvchi/sT7NLiDGp02B8vegS9CFl+qb6IZZ2oKoFdUK7RIUc2Do36HLoWEfGVs9 9bovsfXFO+pN8/bHMMtj0k7ErVtyWB/QLCjiQweC4VfIvWXOrjeffXtFGhqvbT7y3dAS ea+tUR/HhD2wtA7lFEZSqq3b0orWiQmRa0GGl3xcMlN+UYJOLBTgami7zvFIoAPlVnf1 2awALbETNCYbTQGNkXyRXMqyIyYAQPyxo2yzCBBwpt1Obln5UoOrPwDF6omaWcoxmIXj FHs9hT3JcWiDIxyfIHV4LX8aZwZpXu4f+gx0IJGC0rcvn/zqicB8Z4T38ybpr6xxnOEN mFNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=RDhOVTHGYsIaKW4j/v9NRg27hm+Qto/eH5kKAGrmJLM=; b=E6Sb6na/1B68J9sCXOpZ9hvQdcF/madZG+vdTfbCR5iUBRaqwB5QZ+X7NhZHPIfR2U rBPyqp7DIH0INdYGNHzS+K+I3j0vdA3HMz6DU0rVFr+s45Q5jTWskkcXJuLhX7Nwn9aD wlYyrJI2q+0KcYGJP+vXvlDp2xGFGWA7qPpNcaEiDaE66qLizmARaehJQhVNsDbhctF1 FpqvfrtYuyh1wKACyPtnGLVffzVfaHqZy1enbpkHmSCUMluRX2DGvJ7YrmX3qXK5cGNd Pf9o4NLhoZfsR8Ywz/0lMg6xQes220prDUcbEsuqWKbdyAk3ijSOuYt4fvQ73sAFmyhf Ke9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iQR1FSWO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f15-20020a50a6cf000000b00446fdce2a62si10754366edc.420.2022.09.13.08.38.53; Tue, 13 Sep 2022 08:39:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iQR1FSWO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235344AbiIMPGP (ORCPT + 99 others); Tue, 13 Sep 2022 11:06:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235369AbiIMPEP (ORCPT ); Tue, 13 Sep 2022 11:04:15 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A7032F64E; Tue, 13 Sep 2022 07:29:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id BE74FB80FA0; Tue, 13 Sep 2022 14:29:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29E60C4314E; Tue, 13 Sep 2022 14:29:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663079386; bh=3iWgK3pNJMPaywnNeNspWA6vxh5BEbVggat3fdhcvNo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iQR1FSWOyWg2cFeYbrDyma7JDmQ43aC9Xau3AwpkkvBK1bOWNxiL+cSz78TqCYi6J Y3jF2cVW8pUaNsvvprASopIu/EG+ME6WcGCd0v/n2ZduSEowwqSpsq+fKu928Ptr55 zmeVeSuuYJt0bX5KhPqc9f5rrjBGAznOfs+EmJkw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrew Halaney , Douglas Anderson , Brian Masney , Mark Brown , Sasha Levin Subject: [PATCH 5.4 090/108] regulator: core: Clean up on enable failure Date: Tue, 13 Sep 2022 16:07:01 +0200 Message-Id: <20220913140357.487443955@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140353.549108748@linuxfoundation.org> References: <20220913140353.549108748@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrew Halaney [ Upstream commit c32f1ebfd26bece77141257864ed7b4720da1557 ] If regulator_enable() fails, enable_count is incremented still. A consumer, assuming no matching regulator_disable() is necessary on failure, will then get this error message upon regulator_put() since enable_count is non-zero: [ 1.277418] WARNING: CPU: 3 PID: 1 at drivers/regulator/core.c:2304 _regulator_put.part.0+0x168/0x170 The consumer could try to fix this in their driver by cleaning up on error from regulator_enable() (i.e. call regulator_disable()), but that results in the following since regulator_enable() failed and didn't increment user_count: [ 1.258112] unbalanced disables for vreg_l17c [ 1.262606] WARNING: CPU: 4 PID: 1 at drivers/regulator/core.c:2899 _regulator_disable+0xd4/0x190 Fix this by decrementing enable_count upon failure to enable. With this in place, just the reason for failure to enable is printed as expected and developers can focus on the root cause of their issue instead of thinking their usage of the regulator consumer api is incorrect. For example, in my case: [ 1.240426] vreg_l17c: invalid input voltage found Fixes: 5451781dadf8 ("regulator: core: Only count load for enabled consumers") Signed-off-by: Andrew Halaney Reviewed-by: Douglas Anderson Reviewed-by: Brian Masney Link: https://lore.kernel.org/r/20220819194336.382740-1-ahalaney@redhat.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/regulator/core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index ae2addadb36f2..6ba3f6e7ea4f8 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2486,13 +2486,18 @@ static int _regulator_do_enable(struct regulator_dev *rdev) */ static int _regulator_handle_consumer_enable(struct regulator *regulator) { + int ret; struct regulator_dev *rdev = regulator->rdev; lockdep_assert_held_once(&rdev->mutex.base); regulator->enable_count++; - if (regulator->uA_load && regulator->enable_count == 1) - return drms_uA_update(rdev); + if (regulator->uA_load && regulator->enable_count == 1) { + ret = drms_uA_update(rdev); + if (ret) + regulator->enable_count--; + return ret; + } return 0; } -- 2.35.1