From patchwork Fri Jun 21 14:37:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 13707689 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 9EF54C27C4F for ; Fri, 21 Jun 2024 14:38:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=DpjbtuRsYUxGDKKpuIwVrQYGfcBuCB+ep5KKwdfomXI=; b=EpBal6QzSy22v0vw9YsVlRgoZX wpsKqcqEb+Hclhwwm4baLvaUw8EUpWLNS72YvVEsIn9ZW4WslVlY1KsfjkgYwEJbcXoAiMpSZAZfO XyBZgdRNbPyMuBQ8k/Cca8/CLTOtpHcgYyOKcZSAMPZAkwslRfoyXet/T/WeTTnBxmfFs5YhM1XTx 142XM4aJmOmFOSLrYQf2duAqZxZfI2GloPYKiwUNo8rkwrkVaMxwdVVzsNN3I+WEaZYYJ0K42Ir1r sEZI7l+lxI8EEYGiKNGiJM9Ul3BfT28tLws6DvCfKaqT4nX1ik5x9AVTxouicEEHsOOP8f6YetWk2 8mXuGJ0A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKfOn-00000009X8g-1Oe3; Fri, 21 Jun 2024 14:37:57 +0000 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKfOY-00000009X2s-1KR0 for linux-arm-kernel@lists.infradead.org; Fri, 21 Jun 2024 14:37:43 +0000 Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-a6265d3ba8fso218158766b.0 for ; Fri, 21 Jun 2024 07:37:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1718980660; x=1719585460; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DpjbtuRsYUxGDKKpuIwVrQYGfcBuCB+ep5KKwdfomXI=; b=oViz6pv4fhILjf+KJVCRFX5JPGN8eCtToHl73zeCZFs7tRwgE0bZW6QTXezFyOxgwd JWylmR3nW0p2j/HpoidEs6n8pMrLpRknAewZVnZWMtaXr16ivMMEJUZ2DBS05PlTv0yT 1MoOkeZp80AE8pYKklbFkVS1sq4luIUosBG6hgpiloO0msD1P4nViViOkg8OwgNUDBLH kiM868RouhElmuBLeHwP/fHAn9Z/bUfUnPwOFFBqQlRWgB1fCe4lscCuRe7qOfM0MV/6 XVN8+GGGDVQFudRJwkHq8FbJPMToQQuTRY7aODAlR0RtsvOgmi7/DqE8i8t7uHGuBphH dVvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718980660; x=1719585460; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DpjbtuRsYUxGDKKpuIwVrQYGfcBuCB+ep5KKwdfomXI=; b=AM9bslY8GSCF2PVjqUlVCvak5Xq39Byi6FUXuKgjlEtHL5mFLySM0d/XWwXxgWDSdb ANFLdY6qeKvUul4gq2l0ShfdZepSRTG2uvB9eDWZays8jDQYhkOxNbhYpsnyKL2RBixm dzuFo6/fS9iEbnewjRjrGH5BANbXJPzNCg0AtXV0uTc4k9phSzu7RDdrTj2jhB7iKtlc cusVePZ/2VhU1k1WF0MmsXglAT6HAgQRlI8YEyrOejFBg97OvxvulUTWYXkJya8FExhW bDtMfq0Tl38HEPPqU5ayWD9M1MrNDs1igjjeaZofM74nYNucvqs8pCJIUoMcleM1yqQJ G+aA== X-Forwarded-Encrypted: i=1; AJvYcCXI1yXnRfWRkqOchX3Cq89dbeVUIFJFUnx8eCZDPSObgovrs9i4w92yLKk0eKN3UvJyhs5/0icXvsPVEL8eoL88M2GQzl3B4foWZXjoHrkv/kHCPv4= X-Gm-Message-State: AOJu0YwvagG3GBYBgkb0FNRV99kTggwG5Ebg6c0D/DRG23FpODtKYpUC HjvRMmhJssxGr3/XxjJfM1CowwWQbTQuXnKhSfdBDexkfMJZilCQL6Tv7oe6OwQ= X-Google-Smtp-Source: AGHT+IFnG8vPc7gD/zkJj+cDdWoK1zUqRd6sd4hZoStrTa7UEp0SdW6Bnq1Jrrg14s9KXzb7mLfmvQ== X-Received: by 2002:a17:907:a646:b0:a6f:5192:6f4d with SMTP id a640c23a62f3a-a6fab60321fmr603671866b.8.1718980660351; Fri, 21 Jun 2024 07:37:40 -0700 (PDT) Received: from localhost (p5091583d.dip0.t-ipconnect.de. [80.145.88.61]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6fcf56ece7sm90255466b.208.2024.06.21.07.37.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 07:37:39 -0700 (PDT) From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Fabrice Gasnier , Maxime Coquelin , Alexandre Torgue , Benjamin Gaignard , Lee Jones , Thierry Reding Cc: linux-pwm@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, Trevor Gamblin , stable@vger.kernel.org Subject: [PATCH v2 1/3] pwm: stm32: Refuse too small period requests Date: Fri, 21 Jun 2024 16:37:12 +0200 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=969; i=u.kleine-koenig@baylibre.com; h=from:subject:message-id; bh=77m9S/e76ZnqolXIdKGvPpQwodpWtsZsa1irYtdWzSg=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBmdZAb+JF1Lt4sQgcrKfQpUfAROKFoD9THKpVyX 3OGJ7yuteKJATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZnWQGwAKCRCPgPtYfRL+ TogNB/4wXOzt1/fRlY9bvWJQ8dB2JW/44VfPAoPIjaBk7pL32PDPR21QrNgn1+8ThreMJc6YFht BTJPKzI2CtXXdaR/N90Zdv+6Hl+EAxR3+JzPp1fN0F0v74hQ/DsWOPXcQFG+21256SX25ScI2Hv s6m/49IIBgcyGmVdHiIZVt/IaoQyXtW7PfhKWqZBCcmOs2zLOhhllZQFwiLhhr5ADfObNftH080 nIxbYKKHZ+lHZIHeAKH74pq2GjrYAHvlzoSHMnHg7IcbB369mX5L2nxfkwOq/un0+QEzy8PGj0C TosDsIqF3zMkjlyMqWdIzyKTzTVNQg5bgLc9w2hB5UsIeZSq X-Developer-Key: i=u.kleine-koenig@baylibre.com; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240621_073742_394510_2313A5D1 X-CRM114-Status: GOOD ( 11.34 ) 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 If period_ns is small, prd might well become 0. Catch that case because otherwise with regmap_write(priv->regmap, TIM_ARR, prd - 1); a few lines down quite a big period is configured. Fixes: 7edf7369205b ("pwm: Add driver for STM32 plaftorm") Cc: stable@vger.kernel.org Reviewed-by: Trevor Gamblin Signed-off-by: Uwe Kleine-König --- drivers/pwm/pwm-stm32.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/pwm/pwm-stm32.c b/drivers/pwm/pwm-stm32.c index a2f231d13a9f..3e7b2a8e34e7 100644 --- a/drivers/pwm/pwm-stm32.c +++ b/drivers/pwm/pwm-stm32.c @@ -337,6 +337,8 @@ static int stm32_pwm_config(struct stm32_pwm *priv, unsigned int ch, prd = mul_u64_u64_div_u64(period_ns, clk_get_rate(priv->clk), (u64)NSEC_PER_SEC * (prescaler + 1)); + if (!prd) + return -EINVAL; /* * All channels share the same prescaler and counter so when two