From patchwork Wed May 3 19:58:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 13230547 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 014EAC77B7F for ; Wed, 3 May 2023 19:59:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:From:Cc:To:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=ny+bdoAQi9F0VI0i3df4aKkvDb04L3RDWSniTW4hOnc=; b=xEkeV+n3Y2DCb/ evQdAi1tkgSP3BPKqPQX+IYxFJAQFuhBPFVN2NyeGsaISe2BFRP2nsR1+mBp2M8mlhvO7Gmj5PhKH MLuhlQBR+mOe2NevArkuTkluHSSunhtKQ0fWvOQ1JnlrstUd+7HS0OqmmqYdzuUqSkCzmpj/j9wZo REEwAZJFolWlhG6YBZArKpxmhveNA2q4jOsgcX2U7HzQPx7/nM6slJZo1qKS6WiKkew2+UiT6yHS+ bVFW5n2Z9oNo2oAIcjI1OBffiiBoMr/wpitSeKkkkWhkuH3EYqOHP7uRDZN51SClERPn2TpFuC/Il tcvmnc0Iht0mE7p1wrmQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1puIcK-005esB-14; Wed, 03 May 2023 19:58:24 +0000 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1puIcH-005erc-36; Wed, 03 May 2023 19:58:23 +0000 Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-50bd87539c2so3295249a12.0; Wed, 03 May 2023 12:58:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683143900; x=1685735900; h=content-transfer-encoding:subject:from:cc:to:content-language :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=SwruGZFr/+VxvRHZ7yoTbI/FMSH+WcULSX9JkVPhf6I=; b=LZzEDGQBdN0Ba4ItabfKCKinA6jrql6QSKIWGlE4TnmU/20Lfq9hcqaU2kE75LIHdV wuLaFv1b6fKVPXvJ7f6pVNOP0Sy688l7nZYCK9Ye19Ecd3SNYtuEhFIMoPVl8RI+xauw c2lhU+BZbPfmxMsPFpWSvdTBVwWx3qdZ1jyajVmKurty/xp7FxbR4wH7cIZdHgdF/7/f j0quAh0w7Fpl9z8M0rBeABgqpISTajGv0f86ICak+zFzrC22HdkRY8Oy9H4C+NJxWi81 0BzwZjzQdHhozMSnTuMfnwZGryinrV1+qNFDVtvXmzvzqHtoHYrDjpB+xX2gyehngUU2 lU+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683143900; x=1685735900; h=content-transfer-encoding:subject:from:cc:to:content-language :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=SwruGZFr/+VxvRHZ7yoTbI/FMSH+WcULSX9JkVPhf6I=; b=dkQcZjg+DGk75REdeyojb2WXaX2OJHmYH5Ay0AD6DLywfSoG2l16bW20n2zE241H04 QOtTNw/jf28yGfRF/uBQcaGc6HYgUVKxiB8KGAvztaGTJ+gd78llDtm3fgaNKnM/W85Q 8GanwvOE20O7rgpIu2V/PGmslldAkNNqWTZDr9jh6/E0AHsvk2okwn4r88LNc3UyhUVR OV7nOEW3irxNOdw/LlSKUGgLGNLkENFj1fXKCEZ+Noc1+XZPUbZZbJS0WOdXyNXwKGhM LwxLtPIS+lDJtB8RvIxJBaDUVHmvj+vua3fkJ7VoKKq+FzQUq0nIB0wJ8NnWafXwofEE 2RmQ== X-Gm-Message-State: AC+VfDx5hxJdwLsUz9iorsMDDj8I8sksCydpxwvj11jJH+sN0iPS/N5O Hz4I5km6kIdSGiENUcDYxHs= X-Google-Smtp-Source: ACHHUZ5UwFn6M+NdYUwjvdBLmLzJCzCqZCqLFidH7kTshROl2xAOI5Z97rE2fesMcCV1t98Bf0iGTw== X-Received: by 2002:aa7:c849:0:b0:506:83e7:8c6c with SMTP id g9-20020aa7c849000000b0050683e78c6cmr11577422edt.10.1683143899499; Wed, 03 May 2023 12:58:19 -0700 (PDT) Received: from ?IPV6:2a01:c22:7b1d:3100:e5d3:5790:75fc:741b? (dynamic-2a01-0c22-7b1d-3100-e5d3-5790-75fc-741b.c22.pool.telefonica.de. [2a01:c22:7b1d:3100:e5d3:5790:75fc:741b]) by smtp.googlemail.com with ESMTPSA id e6-20020aa7d7c6000000b004af6c5f1805sm1048055eds.52.2023.05.03.12.58.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 03 May 2023 12:58:18 -0700 (PDT) Message-ID: <1d1a8ede-e789-bc4d-2dcd-9d06d2df4061@gmail.com> Date: Wed, 3 May 2023 21:58:17 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Content-Language: en-US To: Jerome Brunet , Martin Blumenstingl , Neil Armstrong , Kevin Hilman , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , "thierry.reding@gmail.com" Cc: "linux-arm-kernel@lists.infradead.org" , "open list:ARM/Amlogic Meson..." , linux-pwm@vger.kernel.org From: Heiner Kallweit Subject: [PATCH] pwm: pwm-meson: fix handling of period/duty if greater than UINT_MAX X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230503_125821_998057_38C20C6E X-CRM114-Status: GOOD ( 10.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org state->period/duty are of type u64, and if their value is greater than UINT_MAX, then the cast to uint will cause problems. Fix this by changing the type of the respective local variables to u64. Fixes: b79c3670e120 ("pwm: meson: Don't duplicate the polarity internally") Cc: stable@vger.kernel.org Suggested-by: Uwe Kleine-König Signed-off-by: Heiner Kallweit Reviewed-by: Uwe Kleine-König --- drivers/pwm/pwm-meson.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index 3865538dd..33107204a 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -156,8 +156,9 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm, const struct pwm_state *state) { struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm]; - unsigned int duty, period, pre_div, cnt, duty_cnt; + unsigned int pre_div, cnt, duty_cnt; unsigned long fin_freq; + u64 duty, period; duty = state->duty_cycle; period = state->period; @@ -179,19 +180,19 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm, dev_dbg(meson->chip.dev, "fin_freq: %lu Hz\n", fin_freq); - pre_div = div64_u64(fin_freq * (u64)period, NSEC_PER_SEC * 0xffffLL); + pre_div = div64_u64(fin_freq * period, NSEC_PER_SEC * 0xffffLL); if (pre_div > MISC_CLK_DIV_MASK) { dev_err(meson->chip.dev, "unable to get period pre_div\n"); return -EINVAL; } - cnt = div64_u64(fin_freq * (u64)period, NSEC_PER_SEC * (pre_div + 1)); + cnt = div64_u64(fin_freq * period, NSEC_PER_SEC * (pre_div + 1)); if (cnt > 0xffff) { dev_err(meson->chip.dev, "unable to get period cnt\n"); return -EINVAL; } - dev_dbg(meson->chip.dev, "period=%u pre_div=%u cnt=%u\n", period, + dev_dbg(meson->chip.dev, "period=%llu pre_div=%u cnt=%u\n", period, pre_div, cnt); if (duty == period) { @@ -204,14 +205,13 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm, channel->lo = cnt; } else { /* Then check is we can have the duty with the same pre_div */ - duty_cnt = div64_u64(fin_freq * (u64)duty, - NSEC_PER_SEC * (pre_div + 1)); + duty_cnt = div64_u64(fin_freq * duty, NSEC_PER_SEC * (pre_div + 1)); if (duty_cnt > 0xffff) { dev_err(meson->chip.dev, "unable to get duty cycle\n"); return -EINVAL; } - dev_dbg(meson->chip.dev, "duty=%u pre_div=%u duty_cnt=%u\n", + dev_dbg(meson->chip.dev, "duty=%llu pre_div=%u duty_cnt=%u\n", duty, pre_div, duty_cnt); channel->pre_div = pre_div;