Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp11164ybl; Tue, 27 Aug 2019 14:54:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqzHBxwjifAt9aRdc2wUzvumI72DTc1tSRnyzcoogd7MX1H/H+e6jlK/hbXWhepa6DinerIX X-Received: by 2002:a63:8ac4:: with SMTP id y187mr559523pgd.412.1566942865338; Tue, 27 Aug 2019 14:54:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566942865; cv=none; d=google.com; s=arc-20160816; b=OKzaibOtHOimjgfhA7JtF9BfCz4j3HJLCnYcuUaq8C9aolYXqzbqVfcmvvwOl3FrhI 6QTa/dYn/R4vYTRk3vXaEE/ZNZ8wahPtW+c7Yq53djmA5Qs/oGCS4X6ssBSADpshV1L5 2UqAyZouKmm5kpbZxcLDzptktn+hRy/MGOG45GPivRUaw8aiQwCbjLJpB0BlKFP7tuS/ 41olBWPz05tLpWVT+ZHjV+ANcd0GkOnwmbH5Mohht6sJYp0P2fwLoLlqIvgdmee6W86J m03Nhxt8eFIz8SnN2rA5ksKOzJvCvDmgpPrG7BXazNCZyfRw7ZNpQijT91zCxlDOGN9p ip4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=ZQv8StKOE1H8ES5ZJJ44fYA+yMEActYMMdtdH+anETg=; b=BljT/NcyXNTInygqs0Dq/hWNhhcdyluZEQeONdYGeROdGyttfIFnAJsczy8Yu4uwQZ uEcgSk8eAZknvRpaiWCsdw/86ngW4qhIHGDHpRk9gBTKwzr+lNniZ5zA73snoaILvBhu /+1qkXnX1IEyqJVr5WurylZ0l0g2QYj20aJWFhlmZTYzzdWu2McQ4RKwHXGzT/OYp3KZ Sf5jEelX84JIAi+mB9Puquvb1ckndE9l8luGKeL5e4iA7BTvhN//pzRm9e5Oc+/StBFK vzemx/29fz1pOTgvb2K+LoB/xVUKK4ENIVSPDT0v5V/qYiGNKWQclx8QWE1ula2cuZJS mtTg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b26si454838pgw.564.2019.08.27.14.54.09; Tue, 27 Aug 2019 14:54:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726619AbfH0VwJ (ORCPT + 99 others); Tue, 27 Aug 2019 17:52:09 -0400 Received: from muru.com ([72.249.23.125]:58888 "EHLO muru.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726092AbfH0VwJ (ORCPT ); Tue, 27 Aug 2019 17:52:09 -0400 Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 478AB8107; Tue, 27 Aug 2019 21:52:37 +0000 (UTC) From: Tony Lindgren To: Jacek Anaszewski Cc: Pavel Machek , Dan Murphy , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] leds: lm3532: Avoid potentially unpaired regulator calls Date: Tue, 27 Aug 2019 14:52:05 -0700 Message-Id: <20190827215205.59677-1-tony@atomide.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We may currently get unpaired regulator calls when configuring the LED brightness via sysfs in case of regulator calls producing errors. Let's fix this by maintaining local state for enabled. Signed-off-by: Tony Lindgren --- drivers/leds/leds-lm3532.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/leds/leds-lm3532.c b/drivers/leds/leds-lm3532.c --- a/drivers/leds/leds-lm3532.c +++ b/drivers/leds/leds-lm3532.c @@ -127,6 +127,7 @@ struct lm3532_als_data { * @num_leds - Number of LED strings are supported in this array * @full_scale_current - The full-scale current setting for the current sink. * @led_strings - The LED strings supported in this array + * @enabled - Enabled status * @label - LED label */ struct lm3532_led { @@ -138,6 +139,7 @@ struct lm3532_led { int ctrl_brt_pointer; int num_leds; int full_scale_current; + int enabled:1; u32 led_strings[LM3532_MAX_CONTROL_BANKS]; char label[LED_MAX_NAME_SIZE]; }; @@ -292,11 +294,15 @@ static int lm3532_get_ramp_index(int ramp_time) ramp_time); } +/* Caller must take care of locking */ static int lm3532_led_enable(struct lm3532_led *led_data) { int ctrl_en_val = BIT(led_data->control_bank); int ret; + if (led_data->enabled) + return 0; + ret = regmap_update_bits(led_data->priv->regmap, LM3532_REG_ENABLE, ctrl_en_val, ctrl_en_val); if (ret) { @@ -304,14 +310,24 @@ static int lm3532_led_enable(struct lm3532_led *led_data) return ret; } - return regulator_enable(led_data->priv->regulator); + ret = regulator_enable(led_data->priv->regulator); + if (ret < 0) + return ret; + + led_data->enabled = 1; + + return 0; } +/* Caller must take care of locking */ static int lm3532_led_disable(struct lm3532_led *led_data) { int ctrl_en_val = BIT(led_data->control_bank); int ret; + if (!led_data->enabled) + return 0; + ret = regmap_update_bits(led_data->priv->regmap, LM3532_REG_ENABLE, ctrl_en_val, 0); if (ret) { @@ -319,7 +335,13 @@ static int lm3532_led_disable(struct lm3532_led *led_data) return ret; } - return regulator_disable(led_data->priv->regulator); + ret = regulator_disable(led_data->priv->regulator); + if (ret < 0) + return ret; + + led_data->enabled = 0; + + return 0; } static int lm3532_brightness_set(struct led_classdev *led_cdev, -- 2.23.0