Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1775744pxp; Mon, 7 Mar 2022 02:02:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJwQ+uGmxbDqzoHmNMxaAIKAJE26n+YqTk2nUWmSafZBYWnrQIQUonW06VhN0z9olpN70KZj X-Received: by 2002:a17:906:d204:b0:6d6:df17:835e with SMTP id w4-20020a170906d20400b006d6df17835emr8184667ejz.20.1646647373414; Mon, 07 Mar 2022 02:02:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646647373; cv=none; d=google.com; s=arc-20160816; b=TyGw7pZzwD2qt3H4ntKb0SvB/yfy/44Lxhgy0Tw6BFZWfDvMXXowQwCbeNGubp7CY2 gP4hcslWCqiC1w2ozLtczGpABh1CKylthLmvBPcGr47/B5xZS6qgIXhfrFAYNIHp4NyG yAOXCkyvH43bOyV2TPZvsrUu9+WdMqea+wFWdZX6IWYdWnCyGDVUUy/a+K49id94UKtZ CMv4YVXXz3DNV11ZEpZxyzebu+4CeLrZhX1BJrk4NnUS8PL74PwNh3wpFSp8d4l0I55B N2s/fKj6UNbaG8VOdMfHSUYJFcSNmUmQdrtuceeZQqw2GQ/ncAoREoddkrbDPqPzbHXB 6m+g== 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=AFRpIDgBMQhePZbxl3gyBYsaj1mV3ZfMgtb8AvIFZHg=; b=ydvoNgzzFw63vUIZbBHY0MhywxQWcrUqu77+vkpoeW/vzGnPbYuupKnlE2wEm78vXZ kU83NHH9wywxmGSU3EF7ZphHHspoCYnV6P/UUs7jyRUupZmV1JjIU1R0HJnP8vbpxmmS tVHN1cQ47YlWk/DBAga/B4gfbn+Q5V2MNcr+aNkApYE0xvtnUlwf8amArxTkigNjc/Vq 3RbLzDF/0qYFKxpQHUjmkEX/7G3syMgJECFRa3vTE9ZnUNrmOwzMEmrxusnRXa0bHFb4 JjT8f1n8Sn28eEy+F//9JueWuW7nYpeAevCG2n4e8tLqZwsFJ5vUiS5Bq3zGHFqFbhQc /91g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cm1qYX7w; 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 w23-20020a1709061f1700b006d0fc013ca9si7492910ejj.44.2022.03.07.02.02.31; Mon, 07 Mar 2022 02:02:53 -0800 (PST) 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=cm1qYX7w; 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 S236792AbiCGJZS (ORCPT + 99 others); Mon, 7 Mar 2022 04:25:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237330AbiCGJXp (ORCPT ); Mon, 7 Mar 2022 04:23:45 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C991647381; Mon, 7 Mar 2022 01:22:49 -0800 (PST) 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 71C38B810AC; Mon, 7 Mar 2022 09:22:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD5C9C340F5; Mon, 7 Mar 2022 09:22:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646644967; bh=Fx8sxKDlicv+ZHV+t6h5Trdm0xpJq9j4m2GOhUsmSgM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cm1qYX7w1N0f7iyoliVdDKkgjgy2t21RTalM2X1NjU9rjI76Z0OMvgbjDtd8j5z18 9r+qBjdkINqJCBrsgBXVktZUHMGukO2uz9pQFsfSg4HqEVOq1EoXtOeJeIP4acFUDK Z/awxcKWS3VNzErgKCDN25Qq8BzlnKzbHj3bYBSE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hans de Goede , Dmitry Torokhov Subject: [PATCH 4.14 38/42] Input: elan_i2c - move regulator_[en|dis]able() out of elan_[en|dis]able_power() Date: Mon, 7 Mar 2022 10:19:12 +0100 Message-Id: <20220307091637.262135849@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220307091636.146155347@linuxfoundation.org> References: <20220307091636.146155347@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 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: Hans de Goede commit 81a36d8ce554b82b0a08e2b95d0bd44fcbff339b upstream. elan_disable_power() is called conditionally on suspend, where as elan_enable_power() is always called on resume. This leads to an imbalance in the regulator's enable count. Move the regulator_[en|dis]able() calls out of elan_[en|dis]able_power() in preparation of fixing this. No functional changes intended. Signed-off-by: Hans de Goede Link: https://lore.kernel.org/r/20220131135436.29638-1-hdegoede@redhat.com [dtor: consolidate elan_[en|dis]able() into elan_set_power()] Signed-off-by: Dmitry Torokhov Signed-off-by: Greg Kroah-Hartman --- drivers/input/mouse/elan_i2c_core.c | 62 ++++++++++++------------------------ 1 file changed, 22 insertions(+), 40 deletions(-) --- a/drivers/input/mouse/elan_i2c_core.c +++ b/drivers/input/mouse/elan_i2c_core.c @@ -137,55 +137,21 @@ static int elan_get_fwinfo(u16 ic_type, return 0; } -static int elan_enable_power(struct elan_tp_data *data) +static int elan_set_power(struct elan_tp_data *data, bool on) { int repeat = ETP_RETRY_COUNT; int error; - error = regulator_enable(data->vcc); - if (error) { - dev_err(&data->client->dev, - "failed to enable regulator: %d\n", error); - return error; - } - do { - error = data->ops->power_control(data->client, true); + error = data->ops->power_control(data->client, on); if (error >= 0) return 0; msleep(30); } while (--repeat > 0); - dev_err(&data->client->dev, "failed to enable power: %d\n", error); - return error; -} - -static int elan_disable_power(struct elan_tp_data *data) -{ - int repeat = ETP_RETRY_COUNT; - int error; - - do { - error = data->ops->power_control(data->client, false); - if (!error) { - error = regulator_disable(data->vcc); - if (error) { - dev_err(&data->client->dev, - "failed to disable regulator: %d\n", - error); - /* Attempt to power the chip back up */ - data->ops->power_control(data->client, true); - break; - } - - return 0; - } - - msleep(30); - } while (--repeat > 0); - - dev_err(&data->client->dev, "failed to disable power: %d\n", error); + dev_err(&data->client->dev, "failed to set power %s: %d\n", + on ? "on" : "off", error); return error; } @@ -1206,9 +1172,19 @@ static int __maybe_unused elan_suspend(s /* Enable wake from IRQ */ data->irq_wake = (enable_irq_wake(client->irq) == 0); } else { - ret = elan_disable_power(data); + ret = elan_set_power(data, false); + if (ret) + goto err; + + ret = regulator_disable(data->vcc); + if (ret) { + dev_err(dev, "error %d disabling regulator\n", ret); + /* Attempt to power the chip back up */ + elan_set_power(data, true); + } } +err: mutex_unlock(&data->sysfs_mutex); return ret; } @@ -1224,7 +1200,13 @@ static int __maybe_unused elan_resume(st data->irq_wake = false; } - error = elan_enable_power(data); + error = regulator_enable(data->vcc); + if (error) { + dev_err(dev, "error %d enabling regulator\n", error); + goto err; + } + + error = elan_set_power(data, true); if (error) { dev_err(dev, "power up when resuming failed: %d\n", error); goto err;