Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp874913pxb; Wed, 6 Apr 2022 02:52:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+xu5KgGNOb7se/h2wbe/JVQqB353cR/zxeQpW4qmXosdb/e5LfFku+edKy314NPplBvlW X-Received: by 2002:a63:f515:0:b0:384:1f78:34b0 with SMTP id w21-20020a63f515000000b003841f7834b0mr6339987pgh.67.1649238751121; Wed, 06 Apr 2022 02:52:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649238751; cv=none; d=google.com; s=arc-20160816; b=cSqBYo1TtLs5JlHlwUK1S6UbSoZ0Q4iqjLLH8tsHR8Wn5+XHr1B5vn3ZtCEec8GzWs N7dAKeL2Fd7mpntDwbBr+qOY9nWfMQKmAjVpqOV9S6f1aVummMi/FqV03GSJ2LAGsg2N MvT6L8dDw0In0aND1kPHNBgtc0q/uh042TapFTJfBAGtUXMGjwHtH3DE0gHMx2UpwSS9 rqdTNT4OCOV0e1YX5WQap2FjJp/KVhSfdgPMRWUE4WaO5/c24YtvWrhMmadXlVBSaGjK LLgzDUKQe9tiOS4az9l/i/VFhQUszIj5f34XQ9ywiek+27x0VYz/FaB3n1kl9Gq7sWA3 1WUA== 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=jMe5qb4FBTXiIfdqtLAYM9nsrVhM33zsWy9mDtXV8OQ=; b=yRJB0LeTzCsIvlUYVet0jUXnJ8FFYVWcXSNllSUjjOWajVmhxf8ADhZkT6nG4RxOcm 5EDrpWnCDT40Ux/KAuWiJm6kmsX8vyLWT5EtkTWahU9g0sbvtySdOHWENWb0ClG2QihY /eca3q6wCqqOPDxwD1X8bHksu0Nd7F9ULK8EAJlFCiAhGzgSUb/kx/P33QQgso0t23bO NgF5SGLXFst9vMXyOBGuOygXW6UaaF/k8jdpASVRb04hgr+hWPBAzyjlml9MDXB1qsE0 TGTg+c1rbIllJiDW+ZwnDZtT7qmyEiREdz+JE7ZCRs1pQPX6H4biAsrsA61XUcI4qHXm OWZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LYV6fiLY; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id q11-20020a65624b000000b003816043ee8asi12288132pgv.127.2022.04.06.02.52.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 02:52:31 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LYV6fiLY; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D2B7554076F; Wed, 6 Apr 2022 01:11:32 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1588356AbiDFAPg (ORCPT + 99 others); Tue, 5 Apr 2022 20:15:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349471AbiDEJtz (ORCPT ); Tue, 5 Apr 2022 05:49:55 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36DA0FD21; Tue, 5 Apr 2022 02:46:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D2B9AB81B76; Tue, 5 Apr 2022 09:46:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23093C385A1; Tue, 5 Apr 2022 09:46:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649152005; bh=/4hjeViN+EfUTKzkf5o0XiMashHr4EoRfdRaBYxu8NU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LYV6fiLYMQaJQ4Pd6a3xnJlTetcnF68ZhqFsUHKl+18XvJufsC/q+VTap7NZti/Wi gYISxzuUtGz6phlH5a7VENaELDahvi+VAWAM9Eid+TYSDrrIqzG9bF2klEXeFm57SH CsNRzxOa/2p4pE8HfWSo9c679LVATzmCXNLBbWlA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Thierry Reding , Sasha Levin Subject: [PATCH 5.15 582/913] pwm: lpc18xx-sct: Initialize driver data and hardware before pwmchip_add() Date: Tue, 5 Apr 2022 09:27:24 +0200 Message-Id: <20220405070357.290361080@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Uwe Kleine-König [ Upstream commit 0401f24cd238ae200a23a13925f98de3d2c883b8 ] When a driver calls pwmchip_add() it has to be prepared to immediately get its callbacks called. So move allocation of driver data and hardware initialization before the call to pwmchip_add(). This fixes a potential NULL pointer exception and a race condition on register writes. Fixes: 841e6f90bb78 ("pwm: NXP LPC18xx PWM/SCT driver") Signed-off-by: Uwe Kleine-König Signed-off-by: Thierry Reding Signed-off-by: Sasha Levin --- drivers/pwm/pwm-lpc18xx-sct.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/drivers/pwm/pwm-lpc18xx-sct.c b/drivers/pwm/pwm-lpc18xx-sct.c index 8e461f3baa05..8cc8ae16553c 100644 --- a/drivers/pwm/pwm-lpc18xx-sct.c +++ b/drivers/pwm/pwm-lpc18xx-sct.c @@ -395,12 +395,6 @@ static int lpc18xx_pwm_probe(struct platform_device *pdev) lpc18xx_pwm_writel(lpc18xx_pwm, LPC18XX_PWM_LIMIT, BIT(lpc18xx_pwm->period_event)); - ret = pwmchip_add(&lpc18xx_pwm->chip); - if (ret < 0) { - dev_err(&pdev->dev, "pwmchip_add failed: %d\n", ret); - goto disable_pwmclk; - } - for (i = 0; i < lpc18xx_pwm->chip.npwm; i++) { struct lpc18xx_pwm_data *data; @@ -410,14 +404,12 @@ static int lpc18xx_pwm_probe(struct platform_device *pdev) GFP_KERNEL); if (!data) { ret = -ENOMEM; - goto remove_pwmchip; + goto disable_pwmclk; } pwm_set_chip_data(pwm, data); } - platform_set_drvdata(pdev, lpc18xx_pwm); - val = lpc18xx_pwm_readl(lpc18xx_pwm, LPC18XX_PWM_CTRL); val &= ~LPC18XX_PWM_BIDIR; val &= ~LPC18XX_PWM_CTRL_HALT; @@ -425,10 +417,16 @@ static int lpc18xx_pwm_probe(struct platform_device *pdev) val |= LPC18XX_PWM_PRE(0); lpc18xx_pwm_writel(lpc18xx_pwm, LPC18XX_PWM_CTRL, val); + ret = pwmchip_add(&lpc18xx_pwm->chip); + if (ret < 0) { + dev_err(&pdev->dev, "pwmchip_add failed: %d\n", ret); + goto disable_pwmclk; + } + + platform_set_drvdata(pdev, lpc18xx_pwm); + return 0; -remove_pwmchip: - pwmchip_remove(&lpc18xx_pwm->chip); disable_pwmclk: clk_disable_unprepare(lpc18xx_pwm->pwm_clk); return ret; -- 2.34.1