From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B38261EB1BF; Thu, 17 Apr 2025 18:03:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744912989; cv=none; b=YpQ51sJnd7oAA6yVfMrI83txA/vM0ok9YS0A81irJ4HbVCZ3ViZ7xs12msIIghamMdbZBPCQ38vWotGnFXEo+JuWSRTV+7irzZQbEiL/vOjgaNgLEDgZsis0YvZnNM8/5prLLfRaOdqO6ZPlePhF+lMwdFLLUL5CNtjDFVQZ7FQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744912989; c=relaxed/simple; bh=BqM6Mf1B/9MIWRzftWL9Fypkhfj7ipYM56DVDYANryc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RHvOdObEXPqnLfLiiH5Sn1I4o0IN0NfHRwNcAaRjW2QOgSeviA18k3o7FBJPEerC0jyuVklua1kK70dhCb64ZIchYsgQ3Vb51tNU3VYV0fo5Ai68NXE7kOIQuxhUMFd/pNnRZyu3UdRMDyhCMbj+bLl9hPPiRSGhwW5ELo7ysNI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=eWA+ZCm/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="eWA+ZCm/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFCE0C4CEE4; Thu, 17 Apr 2025 18:03:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1744912989; bh=BqM6Mf1B/9MIWRzftWL9Fypkhfj7ipYM56DVDYANryc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eWA+ZCm/LbsSFp40ANWsCN+Lfj1SeV6Y6GMSVncEYdtfHwvuXr3fU3Elu+eO+eCET 9Yil9F4oKjq5EMr+zlLjLiLEkaAjR+8/YXTrZ9cPaIw3wFQ8neVvCW+NhvjsOeHwv9 ChQN1l/xkz6RZhIttaPRW76MIYTLPn/p9MadIcys= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Sasha Levin Subject: [PATCH 6.14 190/449] pwm: fsl-ftm: Handle clk_get_rate() returning 0 Date: Thu, 17 Apr 2025 19:47:58 +0200 Message-ID: <20250417175125.620655780@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250417175117.964400335@linuxfoundation.org> References: <20250417175117.964400335@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Uwe Kleine-König [ Upstream commit 928446a5302eee30ebb32075c0db5dda5a138fb7 ] Considering that the driver doesn't enable the used clocks (and also that clk_get_rate() returns 0 if CONFIG_HAVE_CLK is unset) better check the return value of clk_get_rate() for being non-zero before dividing by it. Fixes: 3479bbd1e1f8 ("pwm: fsl-ftm: More relaxed permissions for updating period") Signed-off-by: Uwe Kleine-König Link: https://lore.kernel.org/r/b68351a51017035651bc62ad3146afcb706874f0.1743501688.git.u.kleine-koenig@baylibre.com Signed-off-by: Uwe Kleine-König Signed-off-by: Sasha Levin --- drivers/pwm/pwm-fsl-ftm.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/pwm/pwm-fsl-ftm.c b/drivers/pwm/pwm-fsl-ftm.c index 2510c10ca4730..c45a5fca4cbbd 100644 --- a/drivers/pwm/pwm-fsl-ftm.c +++ b/drivers/pwm/pwm-fsl-ftm.c @@ -118,6 +118,9 @@ static unsigned int fsl_pwm_ticks_to_ns(struct fsl_pwm_chip *fpc, unsigned long long exval; rate = clk_get_rate(fpc->clk[fpc->period.clk_select]); + if (rate >> fpc->period.clk_ps == 0) + return 0; + exval = ticks; exval *= 1000000000UL; do_div(exval, rate >> fpc->period.clk_ps); @@ -190,6 +193,9 @@ static unsigned int fsl_pwm_calculate_duty(struct fsl_pwm_chip *fpc, unsigned int period = fpc->period.mod_period + 1; unsigned int period_ns = fsl_pwm_ticks_to_ns(fpc, period); + if (!period_ns) + return 0; + duty = (unsigned long long)duty_ns * period; do_div(duty, period_ns); -- 2.39.5