Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9106683pxu; Mon, 28 Dec 2020 06:48:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJyCk5CoRkZIHh58LuPD8PYryli8dCJlwpzD/+F3vMTl1G5UAqEaiGjQSvGkIHzwhvm2XGkW X-Received: by 2002:a17:906:e94c:: with SMTP id jw12mr42971295ejb.56.1609166926601; Mon, 28 Dec 2020 06:48:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609166926; cv=none; d=google.com; s=arc-20160816; b=US3QKLzS8rbfLihsguw+J0owF9KTwerhaSANB0LNXDKFhNOipS/Cwf9upkbO+yJxwq d0thHp0kGPKmkTDE6OA0ooLxuXwBthTkKMdRxmzNcReh8V7esNtuXDRj09Ju5uCxTg// qpZQiBE0Kn7Dcc3Uq0ipZgwjjptrqPMfYD+fxFt8isew7cP4e2533R6IOIakFalGUJ+N lD7QFrdMQV7s6gSajM8xLi/Shckkwh7LxNwt8H/CvRKYGYIBPL5C/k2Zg17F8OUtBq6v iom6rS2pGMtlIFhXUol2O8SUMNnbp5rSYWZ3qvKfVo2uRxuU3Ib5X38v2P3v9X7l7DOo nSKQ== 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=+BfpnmohFpdamVFTS6qdELkUyWzfa5RxesgUHddgfS8=; b=sXRlHlaM0bdEnw5Yx4Pe/NOyBYUNFpJDsk7CcRhWlKsQIhL1+Cv2AlaU20tt5nqnro vEEOkj0Pok8Ij4xKpBZhKZVmb2MW4mYA3i5Y7V3tuX7+sLJKUTzmv/hLfJVzDmv/KEPt +OFfit9Yf7Rempv4XLPtM//fDueBP3MPTH4QVdmkTq32uEQ8+/1OlTF1MivbvnXTpRZp tYJaP8t8o29N4wnR4tFbo+TKyqhGclIuz6Cy2cLylTfypoc5Za4rhhci6yzD7vg3EIXt 3JpKUI3vSyzFmdZbGXiHUPCrUT1MedLihcD5E1z4hN/eISa8DDgkgSt+ZKVMAzP5DZHR sXiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VGKBdZtv; 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 l20si21506997edw.0.2020.12.28.06.48.24; Mon, 28 Dec 2020 06:48:46 -0800 (PST) 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=VGKBdZtv; 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 S2438262AbgL1OXz (ORCPT + 99 others); Mon, 28 Dec 2020 09:23:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:59756 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2502875AbgL1OXp (ORCPT ); Mon, 28 Dec 2020 09:23:45 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id ED6E120791; Mon, 28 Dec 2020 14:23:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165384; bh=dKFIqJAkreP7x4OwIFF3ICRl8vZM4yI8GJOz+q8JmpM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VGKBdZtvTAHf5g0Qqb/997Rs8zyrDcpDHXvAxmhn4foxBZ3vtn8dQFyJUW6FontRU vVallKgODw9tDq7ZxBEiaTCmeKQkDbciMX8SkdmmYI/xgyUVGI4WQB/K5aNqZjBusT L2PTCkm6LoZ7P3KHJw7dTrE0cK+6jp1LjBebMfAc= 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?= , Johannes Pointner , Thierry Reding , Sasha Levin Subject: [PATCH 5.10 481/717] pwm: imx27: Fix overflow for bigger periods Date: Mon, 28 Dec 2020 13:47:59 +0100 Message-Id: <20201228125044.013444789@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@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 [ Upstream commit 1ce65396e6b2386b4fd54f87beff0647a772e1cd ] The second parameter of do_div is an u32 and NSEC_PER_SEC * prescale overflows this for bigger periods. Assuming the usual pwm input clk rate of 66 MHz this happens starting at requested period > 606060 ns. Splitting the division into two operations doesn't loose any precision. It doesn't need to be feared that c / NSEC_PER_SEC doesn't fit into the unsigned long variable "duty_cycles" because in this case the assignment above to period_cycles would already have been overflowing as period >= duty_cycle and then the calculation is moot anyhow. Fixes: aef1a3799b5c ("pwm: imx27: Fix rounding behavior") Signed-off-by: Uwe Kleine-König Tested-by: Johannes Pointner Signed-off-by: Thierry Reding Signed-off-by: Sasha Levin --- drivers/pwm/pwm-imx27.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/pwm/pwm-imx27.c b/drivers/pwm/pwm-imx27.c index c50d453552bd4..86bcafd23e4f6 100644 --- a/drivers/pwm/pwm-imx27.c +++ b/drivers/pwm/pwm-imx27.c @@ -235,8 +235,9 @@ static int pwm_imx27_apply(struct pwm_chip *chip, struct pwm_device *pwm, period_cycles /= prescale; c = clkrate * state->duty_cycle; - do_div(c, NSEC_PER_SEC * prescale); + do_div(c, NSEC_PER_SEC); duty_cycles = c; + duty_cycles /= prescale; /* * according to imx pwm RM, the real period value should be PERIOD -- 2.27.0