Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp617296pxb; Tue, 5 Apr 2022 16:05:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfFSp9UTVzTmlEic7NFQk9MgOY050k3zIzEg+3YRQv+dJNho39eGVKBXqADopFGDYVTvww X-Received: by 2002:a05:6a00:1797:b0:4fb:1997:b76e with SMTP id s23-20020a056a00179700b004fb1997b76emr5797957pfg.70.1649199934302; Tue, 05 Apr 2022 16:05:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649199934; cv=none; d=google.com; s=arc-20160816; b=iX8Y0Fd9ek9NLYujarFYRCAoNEByNJtF7EojV7bcO99WO2GFtNjiBtLhaKhvgmQtvQ 5g2huEAnEiHnVIboKkC6GHAerBnC44xdmuFJ9/jjXBckOcipH71T5bzg7H4JPZF+2OU3 YsQBmCrK6TxaFqe7Hdwuv4FqiKnZmw63Z05G0hJkVR8rhXmhf2T3d3kFVRWBIqbyFYBY MYyUoIIOHVVcPavFNvuH6kziW99BMbgOMiEjSUBH/VHVAAqDrdEExnTgvtlkrNzHmZmc bbQoVRiC0PPCB2JU5/Jg7xIPCZXeeF1IRwDIBAhhyOSa7DTDp6iklYEQMZEvg1McJmhl 3fEg== 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=Eo9ZgXT+wwtoFyWVWJRPcK+m+wfHClHswZIk7Q5KC7Kmam6SPJ8EeKRymlwd1sLg5D Pt5eqpv6cPLwq9RSPl/+Ait2bgRTI6FAotr1QdAYu1lJvtM5B5FqstODmrfESzeEaYNw fGx5DkyXLwhnYX5cIWHo6NcJxXt7m2beQ46DnFlOPc5hvzDMCvgLLo2aeuI0Nb1VgBos 4zvxOlIMXhjvvLO22l7yui7nbO29fM+CsVL262Cd8F2T/8xKC0jpUwgudYKKf1F/o9qB sXerXf2yCqUlEzgOoExdNK+3/mSYQgu7HP+qOJYqi9+poAV70YxDNdSwiKQ7w8qB2JNR pvQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="t/hLstPB"; 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 g17-20020a056a0023d100b004fa3f687674si14804638pfc.256.2022.04.05.16.05.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 16:05:34 -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="t/hLstPB"; 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 A0673188A39; Tue, 5 Apr 2022 15:48:31 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380703AbiDEMyE (ORCPT + 99 others); Tue, 5 Apr 2022 08:54:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343819AbiDEJOa (ORCPT ); Tue, 5 Apr 2022 05:14:30 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D49643493; Tue, 5 Apr 2022 02:00:45 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 07A80614E4; Tue, 5 Apr 2022 09:00:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19CD8C385A3; Tue, 5 Apr 2022 09:00:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149244; bh=/4hjeViN+EfUTKzkf5o0XiMashHr4EoRfdRaBYxu8NU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t/hLstPBRRs4z//bdtHEPbMcwUEEL7rz6sGsGXm02vp/RHX3A4ZNowMu+3vvdLK9o +p8YbVPODw0r3TPzUBb0IOx6+yn7Qdof+pKtTxyF1HraYGhKUMZFo9EWnEmquJRQB/ Okh0Jo7pQzh3ADvetKBGoLKy1N3DDrOItzY7zcss= 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.16 0647/1017] pwm: lpc18xx-sct: Initialize driver data and hardware before pwmchip_add() Date: Tue, 5 Apr 2022 09:26:00 +0200 Message-Id: <20220405070413.488705405@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@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