From patchwork Wed May 24 19:48:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 13254483 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 8193BC77B73 for ; Wed, 24 May 2023 19:53:16 +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:In-Reply-To:References:Cc:To:From: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xFCZa+1RzcFMvd1AhtSVWpSb85995Aw0o6KDtCAjA3E=; b=MDhXFB7SU780C7 KDPss22AsatRAevm/wnkC4V4S0a8cF/2mE+NSJpoa7G28x2l4wrR3nR/lVlQdRrKFhpKnOV/v7Jm3 BNXJ9F1LH0zBuCyTN3h/EBLPKES+2UAqG8db1O03AuP9E0m+TVY8f6RfljRyKBgxfE/aPQw4TcpYQ wNrn6s0nvvMsBeqwqM9R0fj4XjT+sbVArbTVdx+9ZU5kwHUXjfyQf0VlqAKESElpCaVmgiXBaJRUy bnkfLcYxIK+VmWYC4yvBPMOmgAUKu70OF3VwKviNPKjAmPOnHbUTlJfN8/tOEKwIkNH3BBSKGtUNJ kzFRywFhsPvli7xdIv9A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q1uXV-00EWJW-2t; Wed, 24 May 2023 19:52:53 +0000 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q1uXN-00EWCg-2d; Wed, 24 May 2023 19:52:47 +0000 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-970056276acso196779966b.2; Wed, 24 May 2023 12:52:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684957960; x=1687549960; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=cQt4vB+zOkte7n2X6CmDlExagU5OjizdoI8k0JY4EOQ=; b=VLVIYvlc3xdaG9fQAmq0qTM3/d1XkHI3Dy98zU6LPqU4j5jkVLj8I0l/QfJ7fopq98 Y7udraFpDOT4vT7TH7YRfIGNbH+0QmXBCVX2c8K5/ts1UEuHJwJcwBh8F5nRiCqnmu7z 64PwJNGolisTqhQv51c9N+U5tgIiGUcNEi17zZAc1zvKnN/CYHpWc8L/7QE/KjYta1ew xDlfRkAn+LD8+6awh1IWOSRb2KBGHzdBJ6X6MD0Dd1NuxloSv54VIxiByoAtQPWzP57T w1qrMJvK4K7conyQxYAGkGqWpGMN3bV3R4GVwYOACNWGCQeMU+P8aYtAISWeLYpMcUQz mrlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684957960; x=1687549960; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cQt4vB+zOkte7n2X6CmDlExagU5OjizdoI8k0JY4EOQ=; b=On/Ckd2gXClqy23cqI/8iZ9TuazEc7a6PP0XX/Sgi5bQ2nYaOzsEopLHkWANwtUFt9 tMhMwSeBFu6nsfMsgAUvqkuwokwRtjl2a5CBm9LaiLBWgLmfCLBFzgIMfpvVoftpf/KZ rTMj0mkSwf7VCVaqKZ0f/KOxLkvzuNsr6ze9vs1md3voHKV2OwfLmQ10Zv2vmjkMT8Ls er2TV9HHBr07ycSsnpxUNLCXcbMOS6Zqa8VJvyc111dw6letX4RtYGnKam4HZ+ynkMYT ZUuypvV6vC5hgPx8PTEBTkAGXSoUriaSnR4t9MsbiPolnIJutyzs69aX/if8r5rYkRrx YLUg== X-Gm-Message-State: AC+VfDxKL2hNq7TjXep/kVSe00jgaFkoD+tz6bQBn4TCWLtzMn+vEOIK 7epTDy2blBI25JvxJ5jzQvk= X-Google-Smtp-Source: ACHHUZ6dOxNjjb/xWU+h6RMte8RHv9yjBTI+rcetpEsrC+chSNhcbvNnj6piReqjqfzJg4MSRSPQtA== X-Received: by 2002:a17:907:9449:b0:969:cbf4:98fa with SMTP id dl9-20020a170907944900b00969cbf498famr17499502ejc.65.1684957960342; Wed, 24 May 2023 12:52:40 -0700 (PDT) Received: from ?IPV6:2a01:c23:c519:9c00:cd4b:d130:35c7:5e08? (dynamic-2a01-0c23-c519-9c00-cd4b-d130-35c7-5e08.c23.pool.telefonica.de. [2a01:c23:c519:9c00:cd4b:d130:35c7:5e08]) by smtp.googlemail.com with ESMTPSA id jy2-20020a170907762200b0096f689848desm6160383ejc.195.2023.05.24.12.52.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 May 2023 12:52:40 -0700 (PDT) Message-ID: <404a7747-298c-683f-e32c-5f009fff744f@gmail.com> Date: Wed, 24 May 2023 21:48:36 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: [PATCH v5 RESEND 2/6] pwm: meson: fix handling of period/duty if greater than UINT_MAX Content-Language: en-US From: Heiner Kallweit 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, Dmitry Rokosov References: In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230524_125245_855894_01FC454B X-CRM114-Status: GOOD ( 10.81 ) 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 Reviewed-by: Martin Blumenstingl Signed-off-by: Heiner Kallweit --- 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;