From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4728C433E4 for ; Tue, 28 Jul 2020 19:49:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8255E207FC for ; Tue, 28 Jul 2020 19:49:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="B8CmtYfE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728192AbgG1Ttm (ORCPT ); Tue, 28 Jul 2020 15:49:42 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:36139 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728021AbgG1Ttm (ORCPT ); Tue, 28 Jul 2020 15:49:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595965780; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qGvTzT8NM7IHgswr1ardDnnF8Kc5Lio2kQPzsmWgHR8=; b=B8CmtYfEc94X1H0UxG5Hp74e+NQSHc4X8+dRUL36we3aBRIJeQP/+0BQp47OZWlHuwrBd6 0QxnHlEMH4robhwxS5+BGKCX6jMswLOZZ9bEPL6wYWtEdxn5yrqsBG1/20kZff/dBx53f3 Xp2Z+77lBFT80YBM0lIZcGtPL6KI8xM= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-234-0Z2IMUwCM9mN4vN72dEDcQ-1; Tue, 28 Jul 2020 15:49:38 -0400 X-MC-Unique: 0Z2IMUwCM9mN4vN72dEDcQ-1 Received: by mail-ej1-f72.google.com with SMTP id r14so2785450eji.16 for ; Tue, 28 Jul 2020 12:49:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=qGvTzT8NM7IHgswr1ardDnnF8Kc5Lio2kQPzsmWgHR8=; b=szrqX0S8qbdSZr0gHmuYyjmD6IY14GG1jgaiHbrTz3EttZxpITGZDCQsBUaMKdmWm4 4BJEWT/6wsPKYCWa0ArXdclmz7mc4nCs+1DO+gR688wpV7Zj3QPW22IdWNwhW83HDKhf WS0QAqdqPSEgtN9s3qwLOIoeCrDPySpQ/MrpZMGhLQDoWOLMKvEndxchY932Q37qxitz PE26QWSqgarirSCxQmbj0LEERm92dMlvJDuRKkFq8UdIXDebRcz3SkPkafiY9xAIYqe/ grd/CMwInvs29OvEeKGslmJAUKAo2q8LOjqU5T2TzDqbIE3scSy7ZAhL9ZYsNnbtmcPb nvkg== X-Gm-Message-State: AOAM531+gbPshJUerh7DdRHAigBLF0fWoSDiAf+l6QEOGOuRKVxhzCXm Grrk9mXgOLqSxd0jPKkDGINtno2RrMfnZykUo9x2ix/IpX4lJ6IERG6PLdbPJLT/mDBpZqI/cPk 0FRKGFPoEltdzqx9xNwHS9w== X-Received: by 2002:a17:906:2816:: with SMTP id r22mr3236524ejc.215.1595965777423; Tue, 28 Jul 2020 12:49:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyST52qxA4L/r7rRNNQhsCVnQBD9xfOfW4Zv8ngTpgqQ7I6PmsbCzOTgI7uEiR84fie460aPA== X-Received: by 2002:a17:906:2816:: with SMTP id r22mr3236509ejc.215.1595965777212; Tue, 28 Jul 2020 12:49:37 -0700 (PDT) Received: from x1.localdomain (2001-1c00-0c0c-fe00-d2ea-f29d-118b-24dc.cable.dynamic.v6.ziggo.nl. [2001:1c00:c0c:fe00:d2ea:f29d:118b:24dc]) by smtp.gmail.com with ESMTPSA id yj16sm9921523ejb.122.2020.07.28.12.49.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 28 Jul 2020 12:49:36 -0700 (PDT) Subject: Re: [PATCH v5 05/16] pwm: lpss: Add pwm_lpss_prepare_enable() helper To: Andy Shevchenko Cc: Thierry Reding , =?UTF-8?Q?Uwe_Kleine-K=c3=b6nig?= , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , =?UTF-8?B?VmlsbGUgU3lyasOkbMOk?= , "Rafael J . Wysocki" , Len Brown , linux-pwm@vger.kernel.org, intel-gfx , dri-devel@lists.freedesktop.org, Mika Westerberg , linux-acpi@vger.kernel.org References: <20200717133753.127282-1-hdegoede@redhat.com> <20200717133753.127282-6-hdegoede@redhat.com> <20200728184553.GZ3703480@smile.fi.intel.com> From: Hans de Goede Message-ID: Date: Tue, 28 Jul 2020 21:49:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <20200728184553.GZ3703480@smile.fi.intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Hi, On 7/28/20 8:45 PM, Andy Shevchenko wrote: > On Fri, Jul 17, 2020 at 03:37:42PM +0200, Hans de Goede wrote: >> In the not-enabled -> enabled path pwm_lpss_apply() needs to get a >> runtime-pm reference; and then on any errors it needs to release it >> again. >> >> This leads to somewhat hard to read code. This commit introduces a new >> pwm_lpss_prepare_enable() helper and moves all the steps necessary for >> the not-enabled -> enabled transition there, so that we can error check >> the entire transition in a single place and only have one pm_runtime_put() >> on failure call site. >> >> While working on this I noticed that the enabled -> enabled (update >> settings) path was quite similar, so I've added an enable parameter to >> the new pwm_lpss_prepare_enable() helper, which allows using it in that >> path too. > > Reviewed-by: Andy Shevchenko > But see below. > >> Suggested-by: Andy Shevchenko >> Signed-off-by: Hans de Goede >> --- >> drivers/pwm/pwm-lpss.c | 45 ++++++++++++++++++++++++------------------ >> 1 file changed, 26 insertions(+), 19 deletions(-) >> >> diff --git a/drivers/pwm/pwm-lpss.c b/drivers/pwm/pwm-lpss.c >> index da9bc3d10104..8a136ba2a583 100644 >> --- a/drivers/pwm/pwm-lpss.c >> +++ b/drivers/pwm/pwm-lpss.c >> @@ -122,41 +122,48 @@ static inline void pwm_lpss_cond_enable(struct pwm_device *pwm, bool cond) >> pwm_lpss_write(pwm, pwm_lpss_read(pwm) | PWM_ENABLE); >> } >> >> +static int pwm_lpss_prepare_enable(struct pwm_lpss_chip *lpwm, >> + struct pwm_device *pwm, >> + const struct pwm_state *state, >> + bool enable) >> +{ >> + int ret; >> + >> + ret = pwm_lpss_is_updating(pwm); >> + if (ret) >> + return ret; >> + >> + pwm_lpss_prepare(lpwm, pwm, state->duty_cycle, state->period); >> + pwm_lpss_cond_enable(pwm, enable && lpwm->info->bypass == false); >> + ret = pwm_lpss_wait_for_update(pwm); >> + if (ret) >> + return ret; >> + >> + pwm_lpss_cond_enable(pwm, enable && lpwm->info->bypass == true); >> + return 0; >> +} >> + >> static int pwm_lpss_apply(struct pwm_chip *chip, struct pwm_device *pwm, >> const struct pwm_state *state) >> { >> struct pwm_lpss_chip *lpwm = to_lpwm(chip); >> - int ret; > >> + int ret = 0; > > We can avoid this change... > >> 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_cond_enable(pwm, lpwm->info->bypass == false); >> - ret = pwm_lpss_wait_for_update(pwm); >> - if (ret) { >> + ret = pwm_lpss_prepare_enable(lpwm, pwm, state, true); >> + if (ret) >> pm_runtime_put(chip->dev); >> - return ret; >> - } >> - pwm_lpss_cond_enable(pwm, lpwm->info->bypass == true); >> } else { >> - ret = pwm_lpss_is_updating(pwm); >> - if (ret) >> - return ret; >> - pwm_lpss_prepare(lpwm, pwm, state->duty_cycle, state->period); >> - return pwm_lpss_wait_for_update(pwm); > >> + ret = pwm_lpss_prepare_enable(lpwm, pwm, state, false); > > ...by simple return directly from here. But I admit I haven't seen the next patch yet. True, but I'm not a big fan of earlier returns except for errors. Regards, Hans > >> } >> } else if (pwm_is_enabled(pwm)) { >> pwm_lpss_write(pwm, pwm_lpss_read(pwm) & ~PWM_ENABLE); >> pm_runtime_put(chip->dev); >> } >> >> - return 0; >> + return ret; >> } >> >> static void pwm_lpss_get_state(struct pwm_chip *chip, struct pwm_device *pwm, >> -- >> 2.26.2 >> > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, NICE_REPLY_A,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 415FFC433E5 for ; Tue, 28 Jul 2020 19:49:47 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1641020809 for ; Tue, 28 Jul 2020 19:49:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bU30BtTY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1641020809 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 58FEE6E3DB; Tue, 28 Jul 2020 19:49:46 +0000 (UTC) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by gabe.freedesktop.org (Postfix) with ESMTP id CEA656E3D6 for ; Tue, 28 Jul 2020 19:49:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595965783; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qGvTzT8NM7IHgswr1ardDnnF8Kc5Lio2kQPzsmWgHR8=; b=bU30BtTYKscB1C3YIg8heGeKemY8vngrU3rr+qgwxx1J26rsq7xNqq5eyYu+2eiIUb0hBs BHIx1HMy6ESRLkfvaZqfl0ReTpcUN3rwqRH55rRR94wuJbeHemN5J6a0zk2Q12vuEta21u EYf9o9FOBgVRXqi4J59RioYRDgTvqjk= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-289-WDGOoEexOLe3SCZOfjRTOQ-1; Tue, 28 Jul 2020 15:49:38 -0400 X-MC-Unique: WDGOoEexOLe3SCZOfjRTOQ-1 Received: by mail-ed1-f70.google.com with SMTP id t9so5960882edw.22 for ; Tue, 28 Jul 2020 12:49:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=qGvTzT8NM7IHgswr1ardDnnF8Kc5Lio2kQPzsmWgHR8=; b=gG0rlnFXkEY/ZJu9UBKfqk6D7ea8mUI9G6DadpI/0IMOZZYooUe1FCNrSP5HlAf3nd JYhaLjJUTmxnBxELatslZI+ZqFzUiAb8wspeoMeWWjCIaQ7hMxMmFHNvlfTGpk9aAVe9 JlzScd/CAJY5d1bhb1rSkzSLGS1dlQCjwdFw18C6UYFai0MNTk0GnYK4C8HgRkOq3MsY EOJfHyXnqrjjWVJi4DvREdGxGYwkpI5v+EBu7LHRWHL4NlIxIPIsCaH+1N7SeVkd/p4+ zi7L6NtCvCWXHq2Wutd7y1p2hzhIAT6S4u9yNNz4d429Y2M7P8W7CWGasF+WCI9+KlXW YvhA== X-Gm-Message-State: AOAM5327PEsWH+g/06e+3TWKWbGtcgtdklXIZhLIzTpn2xQJQ8ZdVQL1 PG2OmfDi19ihDeOtulJXH0eNVkGXum7cwrVTlE7FvFOtXSlz5N1W99ne2e4j/IIh0NuUe+4QxPj RV/2CLHJMOgpPocNZi84rAeOsLqtM X-Received: by 2002:a17:906:2816:: with SMTP id r22mr3236536ejc.215.1595965777448; Tue, 28 Jul 2020 12:49:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyST52qxA4L/r7rRNNQhsCVnQBD9xfOfW4Zv8ngTpgqQ7I6PmsbCzOTgI7uEiR84fie460aPA== X-Received: by 2002:a17:906:2816:: with SMTP id r22mr3236509ejc.215.1595965777212; Tue, 28 Jul 2020 12:49:37 -0700 (PDT) Received: from x1.localdomain (2001-1c00-0c0c-fe00-d2ea-f29d-118b-24dc.cable.dynamic.v6.ziggo.nl. [2001:1c00:c0c:fe00:d2ea:f29d:118b:24dc]) by smtp.gmail.com with ESMTPSA id yj16sm9921523ejb.122.2020.07.28.12.49.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 28 Jul 2020 12:49:36 -0700 (PDT) Subject: Re: [PATCH v5 05/16] pwm: lpss: Add pwm_lpss_prepare_enable() helper To: Andy Shevchenko References: <20200717133753.127282-1-hdegoede@redhat.com> <20200717133753.127282-6-hdegoede@redhat.com> <20200728184553.GZ3703480@smile.fi.intel.com> From: Hans de Goede Message-ID: Date: Tue, 28 Jul 2020 21:49:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <20200728184553.GZ3703480@smile.fi.intel.com> Content-Language: en-US X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pwm@vger.kernel.org, intel-gfx , "Rafael J . Wysocki" , linux-acpi@vger.kernel.org, Thierry Reding , dri-devel@lists.freedesktop.org, Rodrigo Vivi , =?UTF-8?Q?Uwe_Kleine-K=c3=b6nig?= , Mika Westerberg , Len Brown Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Hi, On 7/28/20 8:45 PM, Andy Shevchenko wrote: > On Fri, Jul 17, 2020 at 03:37:42PM +0200, Hans de Goede wrote: >> In the not-enabled -> enabled path pwm_lpss_apply() needs to get a >> runtime-pm reference; and then on any errors it needs to release it >> again. >> >> This leads to somewhat hard to read code. This commit introduces a new >> pwm_lpss_prepare_enable() helper and moves all the steps necessary for >> the not-enabled -> enabled transition there, so that we can error check >> the entire transition in a single place and only have one pm_runtime_put() >> on failure call site. >> >> While working on this I noticed that the enabled -> enabled (update >> settings) path was quite similar, so I've added an enable parameter to >> the new pwm_lpss_prepare_enable() helper, which allows using it in that >> path too. > > Reviewed-by: Andy Shevchenko > But see below. > >> Suggested-by: Andy Shevchenko >> Signed-off-by: Hans de Goede >> --- >> drivers/pwm/pwm-lpss.c | 45 ++++++++++++++++++++++++------------------ >> 1 file changed, 26 insertions(+), 19 deletions(-) >> >> diff --git a/drivers/pwm/pwm-lpss.c b/drivers/pwm/pwm-lpss.c >> index da9bc3d10104..8a136ba2a583 100644 >> --- a/drivers/pwm/pwm-lpss.c >> +++ b/drivers/pwm/pwm-lpss.c >> @@ -122,41 +122,48 @@ static inline void pwm_lpss_cond_enable(struct pwm_device *pwm, bool cond) >> pwm_lpss_write(pwm, pwm_lpss_read(pwm) | PWM_ENABLE); >> } >> >> +static int pwm_lpss_prepare_enable(struct pwm_lpss_chip *lpwm, >> + struct pwm_device *pwm, >> + const struct pwm_state *state, >> + bool enable) >> +{ >> + int ret; >> + >> + ret = pwm_lpss_is_updating(pwm); >> + if (ret) >> + return ret; >> + >> + pwm_lpss_prepare(lpwm, pwm, state->duty_cycle, state->period); >> + pwm_lpss_cond_enable(pwm, enable && lpwm->info->bypass == false); >> + ret = pwm_lpss_wait_for_update(pwm); >> + if (ret) >> + return ret; >> + >> + pwm_lpss_cond_enable(pwm, enable && lpwm->info->bypass == true); >> + return 0; >> +} >> + >> static int pwm_lpss_apply(struct pwm_chip *chip, struct pwm_device *pwm, >> const struct pwm_state *state) >> { >> struct pwm_lpss_chip *lpwm = to_lpwm(chip); >> - int ret; > >> + int ret = 0; > > We can avoid this change... > >> 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_cond_enable(pwm, lpwm->info->bypass == false); >> - ret = pwm_lpss_wait_for_update(pwm); >> - if (ret) { >> + ret = pwm_lpss_prepare_enable(lpwm, pwm, state, true); >> + if (ret) >> pm_runtime_put(chip->dev); >> - return ret; >> - } >> - pwm_lpss_cond_enable(pwm, lpwm->info->bypass == true); >> } else { >> - ret = pwm_lpss_is_updating(pwm); >> - if (ret) >> - return ret; >> - pwm_lpss_prepare(lpwm, pwm, state->duty_cycle, state->period); >> - return pwm_lpss_wait_for_update(pwm); > >> + ret = pwm_lpss_prepare_enable(lpwm, pwm, state, false); > > ...by simple return directly from here. But I admit I haven't seen the next patch yet. True, but I'm not a big fan of earlier returns except for errors. Regards, Hans > >> } >> } else if (pwm_is_enabled(pwm)) { >> pwm_lpss_write(pwm, pwm_lpss_read(pwm) & ~PWM_ENABLE); >> pm_runtime_put(chip->dev); >> } >> >> - return 0; >> + return ret; >> } >> >> static void pwm_lpss_get_state(struct pwm_chip *chip, struct pwm_device *pwm, >> -- >> 2.26.2 >> > _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, NICE_REPLY_A,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5AD2DC433E3 for ; Tue, 28 Jul 2020 19:49:46 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 31121207F5 for ; Tue, 28 Jul 2020 19:49:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bU30BtTY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 31121207F5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D24516E3D3; Tue, 28 Jul 2020 19:49:45 +0000 (UTC) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by gabe.freedesktop.org (Postfix) with ESMTP id CE7F96E3D3 for ; Tue, 28 Jul 2020 19:49:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595965783; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qGvTzT8NM7IHgswr1ardDnnF8Kc5Lio2kQPzsmWgHR8=; b=bU30BtTYKscB1C3YIg8heGeKemY8vngrU3rr+qgwxx1J26rsq7xNqq5eyYu+2eiIUb0hBs BHIx1HMy6ESRLkfvaZqfl0ReTpcUN3rwqRH55rRR94wuJbeHemN5J6a0zk2Q12vuEta21u EYf9o9FOBgVRXqi4J59RioYRDgTvqjk= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-289-HBLHTkrwNbSHhlikussNOw-1; Tue, 28 Jul 2020 15:49:38 -0400 X-MC-Unique: HBLHTkrwNbSHhlikussNOw-1 Received: by mail-ed1-f69.google.com with SMTP id t30so4888036edi.12 for ; Tue, 28 Jul 2020 12:49:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=qGvTzT8NM7IHgswr1ardDnnF8Kc5Lio2kQPzsmWgHR8=; b=ubbx1RC6upqWzuios8NwLQnfhVTyjbnJBL7OPsnYsiUHYen0mO8NXykfKAtGHyp+fW OUsOa4xyf3qaKX0o6/p50H2nA/BooDXt4MCUJzb273PGX24oK/V2Me850k9z7YAJ6dPD 8TmQbCRFtMCo9Q2kl3gDhIBdqPOner3OXaj+Nh+3JyaAOO38/ZwZ0QmfVNMjR38XzXBP Q/OCWck+74LexVRPA+mfP31uZ6AjngMYu0KmljTDFD5o3LP4NNLn2qYgJHYODURjoRPZ kCAb34go8vLl9Pd1awcwTznoZJOL1yIWp/U2CKbiCuEcQQnu2iXL6EglNinyhLNqExZ+ VLiQ== X-Gm-Message-State: AOAM531dmNKQcH8tFLrol9qPHOr/XTYGr5qBvxUQl2ecW3pXza3qP9YD xE3BhI+moR+6L6zJs2zK1qWySD+yjXJ74yasVlQS3ZzrmafOtAZ1JRCJ46/9v4bUsKy0A7Hbjgi U3LC0gDgzrlbMNA+W2+mNiQE4N3qw X-Received: by 2002:a17:906:2816:: with SMTP id r22mr3236529ejc.215.1595965777423; Tue, 28 Jul 2020 12:49:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyST52qxA4L/r7rRNNQhsCVnQBD9xfOfW4Zv8ngTpgqQ7I6PmsbCzOTgI7uEiR84fie460aPA== X-Received: by 2002:a17:906:2816:: with SMTP id r22mr3236509ejc.215.1595965777212; Tue, 28 Jul 2020 12:49:37 -0700 (PDT) Received: from x1.localdomain (2001-1c00-0c0c-fe00-d2ea-f29d-118b-24dc.cable.dynamic.v6.ziggo.nl. [2001:1c00:c0c:fe00:d2ea:f29d:118b:24dc]) by smtp.gmail.com with ESMTPSA id yj16sm9921523ejb.122.2020.07.28.12.49.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 28 Jul 2020 12:49:36 -0700 (PDT) To: Andy Shevchenko References: <20200717133753.127282-1-hdegoede@redhat.com> <20200717133753.127282-6-hdegoede@redhat.com> <20200728184553.GZ3703480@smile.fi.intel.com> From: Hans de Goede Message-ID: Date: Tue, 28 Jul 2020 21:49:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <20200728184553.GZ3703480@smile.fi.intel.com> Content-Language: en-US X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: Re: [Intel-gfx] [PATCH v5 05/16] pwm: lpss: Add pwm_lpss_prepare_enable() helper X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pwm@vger.kernel.org, intel-gfx , "Rafael J . Wysocki" , linux-acpi@vger.kernel.org, dri-devel@lists.freedesktop.org, =?UTF-8?Q?Uwe_Kleine-K=c3=b6nig?= , Mika Westerberg , Len Brown Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Hi, On 7/28/20 8:45 PM, Andy Shevchenko wrote: > On Fri, Jul 17, 2020 at 03:37:42PM +0200, Hans de Goede wrote: >> In the not-enabled -> enabled path pwm_lpss_apply() needs to get a >> runtime-pm reference; and then on any errors it needs to release it >> again. >> >> This leads to somewhat hard to read code. This commit introduces a new >> pwm_lpss_prepare_enable() helper and moves all the steps necessary for >> the not-enabled -> enabled transition there, so that we can error check >> the entire transition in a single place and only have one pm_runtime_put() >> on failure call site. >> >> While working on this I noticed that the enabled -> enabled (update >> settings) path was quite similar, so I've added an enable parameter to >> the new pwm_lpss_prepare_enable() helper, which allows using it in that >> path too. > > Reviewed-by: Andy Shevchenko > But see below. > >> Suggested-by: Andy Shevchenko >> Signed-off-by: Hans de Goede >> --- >> drivers/pwm/pwm-lpss.c | 45 ++++++++++++++++++++++++------------------ >> 1 file changed, 26 insertions(+), 19 deletions(-) >> >> diff --git a/drivers/pwm/pwm-lpss.c b/drivers/pwm/pwm-lpss.c >> index da9bc3d10104..8a136ba2a583 100644 >> --- a/drivers/pwm/pwm-lpss.c >> +++ b/drivers/pwm/pwm-lpss.c >> @@ -122,41 +122,48 @@ static inline void pwm_lpss_cond_enable(struct pwm_device *pwm, bool cond) >> pwm_lpss_write(pwm, pwm_lpss_read(pwm) | PWM_ENABLE); >> } >> >> +static int pwm_lpss_prepare_enable(struct pwm_lpss_chip *lpwm, >> + struct pwm_device *pwm, >> + const struct pwm_state *state, >> + bool enable) >> +{ >> + int ret; >> + >> + ret = pwm_lpss_is_updating(pwm); >> + if (ret) >> + return ret; >> + >> + pwm_lpss_prepare(lpwm, pwm, state->duty_cycle, state->period); >> + pwm_lpss_cond_enable(pwm, enable && lpwm->info->bypass == false); >> + ret = pwm_lpss_wait_for_update(pwm); >> + if (ret) >> + return ret; >> + >> + pwm_lpss_cond_enable(pwm, enable && lpwm->info->bypass == true); >> + return 0; >> +} >> + >> static int pwm_lpss_apply(struct pwm_chip *chip, struct pwm_device *pwm, >> const struct pwm_state *state) >> { >> struct pwm_lpss_chip *lpwm = to_lpwm(chip); >> - int ret; > >> + int ret = 0; > > We can avoid this change... > >> 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_cond_enable(pwm, lpwm->info->bypass == false); >> - ret = pwm_lpss_wait_for_update(pwm); >> - if (ret) { >> + ret = pwm_lpss_prepare_enable(lpwm, pwm, state, true); >> + if (ret) >> pm_runtime_put(chip->dev); >> - return ret; >> - } >> - pwm_lpss_cond_enable(pwm, lpwm->info->bypass == true); >> } else { >> - ret = pwm_lpss_is_updating(pwm); >> - if (ret) >> - return ret; >> - pwm_lpss_prepare(lpwm, pwm, state->duty_cycle, state->period); >> - return pwm_lpss_wait_for_update(pwm); > >> + ret = pwm_lpss_prepare_enable(lpwm, pwm, state, false); > > ...by simple return directly from here. But I admit I haven't seen the next patch yet. True, but I'm not a big fan of earlier returns except for errors. Regards, Hans > >> } >> } else if (pwm_is_enabled(pwm)) { >> pwm_lpss_write(pwm, pwm_lpss_read(pwm) & ~PWM_ENABLE); >> pm_runtime_put(chip->dev); >> } >> >> - return 0; >> + return ret; >> } >> >> static void pwm_lpss_get_state(struct pwm_chip *chip, struct pwm_device *pwm, >> -- >> 2.26.2 >> > _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx