Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2564592lqp; Mon, 25 Mar 2024 02:46:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVjHIuhutEEF6Tlrksbo/5DMzCJB3SOKF/HbHQZ0Jcyb7Oq3vqkRcJw2hQ/t/MSeG1GnEQ4u60EVnL/+GuREBwyTs5st4zwGXYh4S6BSQ== X-Google-Smtp-Source: AGHT+IHe1mLza4dZnVIehwoDh8f0eF7L0QziNLHwguUZldIYngOJN16jwUbNo0BoTvBR9K72mIxS X-Received: by 2002:a05:6a21:182:b0:1a3:6a79:2112 with SMTP id le2-20020a056a21018200b001a36a792112mr9065374pzb.37.1711360006316; Mon, 25 Mar 2024 02:46:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711360006; cv=pass; d=google.com; s=arc-20160816; b=I8KPRWk4Ppa919RMEoeuCFo5mSrbZT+Xh1KhnDcWEptNNrigKVDzs3Lkms9HI+nJdQ FC4rJLU05cymvd0LuWZvn19fLYAYf9cr927JOODjNoIslTRRQh4+EJAa9HE+WNPRUFKM ao9MTBjCvQMEYnTHT6/7xV/IZGI4LpJaLRXfrYbqezYUNifKcETzIeSJ8Eh/T+SdGeRf 4AKJqF6M8UaqwZGutR1SXzS0RfrzrhLdgjhGfjw2VCJME3FDch5r8zufiVitwFnr5hf2 Nqm2KRj79wl7Sx469X37oXfzNitsC1pgxW03WZEKT9FXzHredLPoOZUQttpJHk/XDc61 TePw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=c9eelNEiDbGgeD+RHoMzqNj33suP34t7Gchk4UEn5fM=; fh=3gwvur5dWAhItACzWgch6pcFnkr/ccEGdgYH7q721Rs=; b=WZmwARD/kUAeVLVfk94cQ+oxo1LUTjBRerSrCtKovlxrtuMuuyznoB6KwDbn8LFTgt Jdf8ZEvW9JhiAqJYTlG1vaZhDGwowC8ugCkKDWrdIdMFAaef/KNOB8P4+eksTfX895ev pnz4UZl4/GmO48flhThRVPg+Em77YGZ84EY0PCCyqUzdRaoPar11SunRbd5r+VZjoNwg q+QGEb/0RTnb+mN2p7GqvrQY0N+nM/+0qnwB00iqhXGLpA3DaUZqRxz1EhyaRkt78MQA TRjJN0+XO2rt7mhKX25EiwAr4ObDcrIsEI4Oh41hfnM0+NduboBJp9OuZ+pzqL4uZ5ok YczA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LK4AuACZ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115826-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115826-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id x3-20020a170902a38300b001e0c95a0d66si727371pla.32.2024.03.25.02.46.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 02:46:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-115826-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LK4AuACZ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115826-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115826-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id E2097B23B9A for ; Mon, 25 Mar 2024 08:07:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 20B8F378C4B; Mon, 25 Mar 2024 03:01:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LK4AuACZ" 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 8BFAD145FF5; Sun, 24 Mar 2024 23:14:19 +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=1711322059; cv=none; b=Onr6ES1Z0ICAPvXSPOtumO0Q9WA4s4si6aiK6oFioMNDU4v7Ijiield9ECbKWSsnVnDS9Mj5daBb9QOBbwp8DQGE/pFYd33JntbCKs/4iem4V0Hf9FD1oXLqIsW/YMNFP3lcZ7JxqfE5qJm6W/qIcqK8X0ZSCF+Yrd+xuSTIEy8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322059; c=relaxed/simple; bh=tuaO+TMyNegk7atL+7siquVjQWrQBQOb9fB6/Uozhyg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TEzbPYhli9bFtZtzKB1jfPiEwyM63zF7K70wcyyrGajqat5r/C5ICbUW4mMbuku6ihODSXkn3/uC0Yu9P8H9NHwNwTjjlygKZaB3H1GuoGL/b3xEXW6m+aOX2MRR4SKCxuGFeR7S2EmBJr3gxkv7a+G4K7Owe6D2N4PuCtrTJd0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LK4AuACZ; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFB9DC433C7; Sun, 24 Mar 2024 23:14:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711322059; bh=tuaO+TMyNegk7atL+7siquVjQWrQBQOb9fB6/Uozhyg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LK4AuACZP4B9zEPgoUoen4y9dDXRWqGYkCXOknYzxtqc5CjW7CIjkQG8hnQltZUKZ w+AnfUTZAZQIazdN6mEX0KjZ8AzGM+jyDf1MnNaVBw8ABP7Xtxo6z/viom4080E+AK hKmggEedLJPOHbtDqBO5EcAiR7Ol2aEpsLcoj7zfCa7dHLUH8h7R4rsajkgJ6ZQkXA oM20Gh88WV7E8Eojl2oc1j1BGyG4HVTl8LUsBSvcB3ay/jvdVI/NJDpoCZT8WnuWrY X6gmIzBH2UoaWJyaiNsfnVZuibQRvOZtDoyuR9mo8l1dZ5jxbU0HWSU0dqcNvxuUIw 1mo2TkYnQyhhg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Sasha Levin Subject: [PATCH 6.1 132/451] pwm: sti: Fix capture for st,pwm-num-chan < st,capture-num-chan Date: Sun, 24 Mar 2024 19:06:48 -0400 Message-ID: <20240324231207.1351418-133-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324231207.1351418-1-sashal@kernel.org> References: <20240324231207.1351418-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Uwe Kleine-König [ Upstream commit 5f623835584f1c8d1030666796f40c47a448ce0b ] The driver only used the number of pwm channels to set the pwm_chip's npwm member. The result is that if there are more capture channels than PWM channels specified in the device tree, only a part of the capture channel is usable. Fix that by passing the bigger channel count to the pwm framework. This makes it possible that the .apply() callback is called with .hwpwm >= pwm_num_devs, catch that case and return an error code. Fixes: c97267ae831d ("pwm: sti: Add PWM capture callback") Link: https://lore.kernel.org/r/20240204212043.2951852-2-u.kleine-koenig@pengutronix.de Signed-off-by: Uwe Kleine-König Signed-off-by: Sasha Levin --- drivers/pwm/pwm-sti.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c index 652fdb8dc7bfa..0a7920cbd4949 100644 --- a/drivers/pwm/pwm-sti.c +++ b/drivers/pwm/pwm-sti.c @@ -395,8 +395,17 @@ static int sti_pwm_capture(struct pwm_chip *chip, struct pwm_device *pwm, static int sti_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, const struct pwm_state *state) { + struct sti_pwm_chip *pc = to_sti_pwmchip(chip); + struct sti_pwm_compat_data *cdata = pc->cdata; + struct device *dev = pc->dev; int err; + if (pwm->hwpwm >= cdata->pwm_num_devs) { + dev_err(dev, "device %u is not valid for pwm mode\n", + pwm->hwpwm); + return -EINVAL; + } + if (state->polarity != PWM_POLARITY_NORMAL) return -EINVAL; @@ -647,7 +656,7 @@ static int sti_pwm_probe(struct platform_device *pdev) pc->chip.dev = dev; pc->chip.ops = &sti_pwm_ops; - pc->chip.npwm = pc->cdata->pwm_num_devs; + pc->chip.npwm = max(cdata->pwm_num_devs, cdata->cpt_num_devs); for (i = 0; i < cdata->cpt_num_devs; i++) { struct sti_cpt_ddata *ddata = &cdata->ddata[i]; -- 2.43.0