From patchwork Mon Feb 20 20:16:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 730182 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3vRvzz4ZlCz9s85 for ; Tue, 21 Feb 2017 07:17:03 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752079AbdBTURD (ORCPT ); Mon, 20 Feb 2017 15:17:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54728 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751249AbdBTURD (ORCPT ); Mon, 20 Feb 2017 15:17:03 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9F36281254; Mon, 20 Feb 2017 20:17:03 +0000 (UTC) Received: from shalem.localdomain.com (ovpn-117-9.ams2.redhat.com [10.36.117.9]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1KKGx6k014649; Mon, 20 Feb 2017 15:17:02 -0500 From: Hans de Goede To: Thierry Reding Cc: Hans de Goede , linux-pwm@vger.kernel.org Subject: [PATCH 2/3] pwm: lpss: Simplify update check in pwm_lpss_apply Date: Mon, 20 Feb 2017 21:16:56 +0100 Message-Id: <20170220201657.24801-3-hdegoede@redhat.com> In-Reply-To: <20170220201657.24801-1-hdegoede@redhat.com> References: <20170220201657.24801-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 20 Feb 2017 20:17:03 +0000 (UTC) Sender: linux-pwm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pwm@vger.kernel.org Simple keep a pm ref over the entire function and do the update check once at the beginning. This simplifies the code and makes sure we also check the update bit when disabling the pwm. Signed-off-by: Hans de Goede --- drivers/pwm/pwm-lpss.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/drivers/pwm/pwm-lpss.c b/drivers/pwm/pwm-lpss.c index 6c99abc..0b549dc 100644 --- a/drivers/pwm/pwm-lpss.c +++ b/drivers/pwm/pwm-lpss.c @@ -128,34 +128,30 @@ static int pwm_lpss_apply(struct pwm_chip *chip, struct pwm_device *pwm, struct pwm_lpss_chip *lpwm = to_lpwm(chip); int ret; + pm_runtime_get_sync(chip->dev); + ret = pwm_lpss_is_updating(pwm); + if (ret) + goto out; + if (state->enabled) { if (!pwm_is_enabled(pwm)) { - pm_runtime_get_sync(chip->dev); - ret = pwm_lpss_is_updating(pwm); - if (ret) { - pm_runtime_put(chip->dev); - return ret; - } pwm_lpss_prepare(lpwm, pwm, state->duty_cycle, state->period); pwm_lpss_write(pwm, pwm_lpss_read(pwm) | PWM_ENABLE); ret = pwm_lpss_update(pwm); - if (ret) { - pm_runtime_put(chip->dev); - return ret; - } + if (ret == 0) + pm_runtime_get(chip->dev); } else { - ret = pwm_lpss_is_updating(pwm); - if (ret) - return ret; pwm_lpss_prepare(lpwm, pwm, state->duty_cycle, state->period); - return pwm_lpss_update(pwm); + ret = pwm_lpss_update(pwm); } } else if (pwm_is_enabled(pwm)) { pwm_lpss_write(pwm, pwm_lpss_read(pwm) & ~PWM_ENABLE); pm_runtime_put(chip->dev); } - return 0; +out: + pm_runtime_put(chip->dev); + return ret; } static const struct pwm_ops pwm_lpss_ops = {