From patchwork Mon Aug 20 14:43:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 959777 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41vGlm5H8mz9s3C for ; Tue, 21 Aug 2018 00:44:04 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726277AbeHTR75 (ORCPT ); Mon, 20 Aug 2018 13:59:57 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:56783 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726641AbeHTR75 (ORCPT ); Mon, 20 Aug 2018 13:59:57 -0400 Received: from pty.hi.pengutronix.de ([2001:67c:670:100:1d::c5]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1frlPU-0004xl-TO; Mon, 20 Aug 2018 16:44:00 +0200 Received: from ukl by pty.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1frlPT-0000ms-VD; Mon, 20 Aug 2018 16:43:59 +0200 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Thierry Reding Cc: linux-pwm@vger.kernel.org, Gavin Schenk , kernel@pengutronix.de Subject: [PATCH 2/2] pwm: warn callers of pwm_apply_state() that expect a certain level after disabling Date: Mon, 20 Aug 2018 16:43:57 +0200 Message-Id: <20180820144357.7206-3-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180820144357.7206-1-u.kleine-koenig@pengutronix.de> References: <20180820095221.fydcvtz7ppcymrta@pengutronix.de> <20180820144357.7206-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c5 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-pwm@vger.kernel.org Sender: linux-pwm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pwm@vger.kernel.org If a pwm-API user changes the duty cycle to 0% or 100% and setting the state to disabled, probably the old implicit behaviour is expected that the pin state stays where it is after pwm_disable(). While there might be some users that trigger this warning as false positive, it is probably good to have this anyhow at least until the newly introduced undefined behaviour sunk in a bit. Signed-off-by: Uwe Kleine-König --- drivers/pwm/core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 1581f6ab1b1f..a076d58127ac 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -475,6 +475,18 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state) if (!memcmp(state, &pwm->state, sizeof(*state))) return 0; + /* + * If period, duty_cycle and/or polarity changes and the pwm should be + * disabled the user might expect something that is explicitly undefined + * (i.e. a certain state of the pin in disabled state). + */ + WARN_ONCE((state->period != pwm->state.period || + state->duty_cycle != pwm->state.duty_cycle || + state->polarity != pwm->state.polarity) && + (state->duty_cycle == 0 || + state->duty_cycle == state->period) && + state->enabled == false, "%s: config changed for disabled pin", pwm->label); + if (pwm->chip->ops->apply) { err = pwm->chip->ops->apply(pwm->chip, pwm, state); if (err)