Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2851828pxb; Mon, 18 Apr 2022 09:33:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxO8kIimJ+T5ib9CIs1Ha+G2G0eYOLJCfErJEoi29jygqeBsUr4TAC8CvhtpffLO+bIhHd7 X-Received: by 2002:a05:6a00:a02:b0:4fd:f9dd:5494 with SMTP id p2-20020a056a000a0200b004fdf9dd5494mr13261755pfh.68.1650299601196; Mon, 18 Apr 2022 09:33:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650299601; cv=none; d=google.com; s=arc-20160816; b=Y70KGtwEMKaWk1D/X5AUAxtrB4ey6fE67u35vzGQ7rj1vs1/KSuh5v7wZdVdidYQj2 c4xLVoe88Vxz/Mv9+ut9mAshHo9aPPWsYJjIWP0MEeeooK5new9nAOBs9UEl0V5EUaSY 3PjcxWIvAMxOQGCsL8b/nxkLc9v2RIKJ14conlyIatxD/k1UeeKrGkyci92QM0kHSMX+ 9o976uvZ/9D0bbv2wUpIrYG3gUiFinjF+rRbycnJ4YS1sPWqofZDqTF4L8a7tfEs4E77 waU/8B9q37VFTsefEA0QYoxSrmX76IWoNV4AZN3EUjKgYKKvImJ7fgy4fjNUoPZjT1r2 WR/w== 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=8wt0+n3znH8GZnEBB3dODkkJ24/WSfw8H4bGAUhY7eE=; b=J3lcAX6BCUWVwyQg5biqU4cyiiWtw6bl0yAwi9kZNiXNB+iLxBYeAGhoqEZUFKBAZE gJ8Jhe+ru7q4PPFwOsXe++YH4WvSjuiXy0atsrkw2uDQR+H1N/xTgzhBYvq+Cek5taCN qZuBriPOkMr5MqmSKqutZK7XbPod9M6qdK1S2sHCtF70aEhhlnMIKT7NYEnRg8WJkHbM Xfo0BeNTCAqqvOoNE+IxIdOpks1L229PwIpIJaits5O7Q+tSla1MUbdul5280fRJC8Rb WUJOtafSWy/Jn0vEt866Iltp/vGFe4eEXFoPVPDNXhOC1qSQIbAf6Ci98aDS0lPgj7A0 M5xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WvSvpA77; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h15-20020a170902ac8f00b00153b2d1659esi8828515plr.422.2022.04.18.09.33.04; Mon, 18 Apr 2022 09:33:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WvSvpA77; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1343578AbiDRNyH (ORCPT + 99 others); Mon, 18 Apr 2022 09:54:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244840AbiDRNa5 (ORCPT ); Mon, 18 Apr 2022 09:30:57 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BE7E1EC55; Mon, 18 Apr 2022 05:55:55 -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 344B2B80E4B; Mon, 18 Apr 2022 12:55:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E9B4C385A1; Mon, 18 Apr 2022 12:55:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650286553; bh=vrr9yOlm8FE3cGTKPSJUOj69XGFkfbaYIYMtWeMhDG0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WvSvpA77wx38oTxOge8yOWm+WKlgHdxub2P0we4Sl9vBDxmJ1zE8ngdqz1hTPOrwh NkGno/oYq1xTyDk/wOFJ4DtfQurtqAKu7L18w9pUoYK5ktkrhhYQjgv0Xry3dtAOD/ KJT1RLIzNLcW5TodNSAnH8c8RkxDsRElsgaO+UaU= 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 4.14 130/284] pwm: lpc18xx-sct: Initialize driver data and hardware before pwmchip_add() Date: Mon, 18 Apr 2022 14:11:51 +0200 Message-Id: <20220418121214.985804074@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121210.689577360@linuxfoundation.org> References: <20220418121210.689577360@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=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 d7f5f7de030d..8b3aad06e236 100644 --- a/drivers/pwm/pwm-lpc18xx-sct.c +++ b/drivers/pwm/pwm-lpc18xx-sct.c @@ -406,12 +406,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; @@ -421,14 +415,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; @@ -436,10 +428,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