Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1717744pxb; Fri, 24 Sep 2021 10:18:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwt4+ZSo3foQeJQ6Bqc7Ea6firnY193MHK65QHZulq62AJffxDZ3kfJa32n8DZJCrb9EIxR X-Received: by 2002:a92:c145:: with SMTP id b5mr9032519ilh.203.1632503925308; Fri, 24 Sep 2021 10:18:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632503925; cv=none; d=google.com; s=arc-20160816; b=fBHso9P83NfCQkVP8TXbPDiTQPV1vPfzvbIJi3RvlvCh5XbSlMcniyYCXVQKi/0R4C WOFFOmgPDREZgdVOvYttM4wjKpDA6RwmubW5lirVEpBpEYbaaK/7F8ZbIvRevQeDUOGe n+h2MbzitsOpA3xbq3s97HH5ABTFuJoge1Tk5ieR+M9dTniY4c4Xtt1Nk41pCN0lM8tB cv7svVL37Uwu03VLjVN9OWnyOtjb2l5kO7f+LL8VUQOxt+Q/J94pavfs1SLStt/3XBHb BQzHPB5bd0x9YkvcaJliihSKxR5mQTuGKkmx2RRTYGCaIfHcfS/KfB01gW17fPO3pdKM 2Orw== 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=9Q09Bx34yiCNUuMBKFlWh+8yIUxgKzA1fsiWnHV9G8w=; b=WSVr8L7xAgHJxHCkwq5L9Mu3KhedI0k6yO5BJxXOrsSclksM1wPvwInFFSng94uVGd uZyWExVV+r2QF/ERgXgRYfybl78lPtb+yMDCX0m3sPaJqQdOqeLc0HvMSFoQmUVviVJG 75i1px0+tOn6NvE87VfY0fWTCc0zBJ3m8Wl4hnW9W2kH+8J3Qtg3B5nO5/ZV3LV46PQy NTpdVqdEJrLstRh1AuYrLnD1L5Dg4YMCe5+H4SqCYOrG9OtHUfOlDpG/T+wOaLRi/ct3 w0LcL2/TF1Mocxg/z37e/iQfvFK+YSce2/9JPtfnX6P017+cwweYdtFNJgr72n85nvQL p9/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jUzSTd5t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ay35si12972144iob.35.2021.09.24.10.18.33; Fri, 24 Sep 2021 10:18:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jUzSTd5t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1344185AbhIXMwE (ORCPT + 99 others); Fri, 24 Sep 2021 08:52:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:44324 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344566AbhIXMu3 (ORCPT ); Fri, 24 Sep 2021 08:50:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3A3546128A; Fri, 24 Sep 2021 12:48:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632487705; bh=VD6fSfNA7spBicbIVz8xxrBQDuTPphwK3kHX3ZUXDcs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jUzSTd5tVwIJQr6SA40ggWzT5u7ZRy9WdCoPBmp4NoL6oSWQFO5MDc5u/Rclcaxvj j8ELj6QhOaTUn2a3I3nD0kY7PGZ3+4bDYI+HnYC4uTrc2h2KyKY/br9OtrO5shUr9Y WYjeFzK8TKuyREq6R8ABBR4RZNthu5gp/iztYcio= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sascha Hauer , Shawn Guo , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Thierry Reding Subject: [PATCH 4.19 16/34] pwm: mxs: Dont modify HW state in .probe() after the PWM chip was registered Date: Fri, 24 Sep 2021 14:44:10 +0200 Message-Id: <20210924124330.492622344@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210924124329.965218583@linuxfoundation.org> References: <20210924124329.965218583@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Uwe Kleine-König commit 020162d6f49f2963062229814a56a89c86cbeaa8 upstream. This fixes a race condition: After pwmchip_add() is called there might already be a consumer and then modifying the hardware behind the consumer's back is bad. So reset before calling pwmchip_add(). Note that reseting the hardware isn't the right thing to do if the PWM is already running as it might e.g. disable (or even enable) a backlight that is supposed to be on (or off). Fixes: 4dce82c1e840 ("pwm: add pwm-mxs support") Cc: Sascha Hauer Cc: Shawn Guo Signed-off-by: Uwe Kleine-König Signed-off-by: Thierry Reding Signed-off-by: Greg Kroah-Hartman --- drivers/pwm/pwm-mxs.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) --- a/drivers/pwm/pwm-mxs.c +++ b/drivers/pwm/pwm-mxs.c @@ -152,6 +152,11 @@ static int mxs_pwm_probe(struct platform return ret; } + /* FIXME: Only do this if the PWM isn't already running */ + ret = stmp_reset_block(mxs->base); + if (ret) + return dev_err_probe(&pdev->dev, ret, "failed to reset PWM\n"); + ret = pwmchip_add(&mxs->chip); if (ret < 0) { dev_err(&pdev->dev, "failed to add pwm chip %d\n", ret); @@ -160,15 +165,7 @@ static int mxs_pwm_probe(struct platform platform_set_drvdata(pdev, mxs); - ret = stmp_reset_block(mxs->base); - if (ret) - goto pwm_remove; - return 0; - -pwm_remove: - pwmchip_remove(&mxs->chip); - return ret; } static int mxs_pwm_remove(struct platform_device *pdev)