From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A972CC433DB for ; Wed, 3 Mar 2021 22:25:41 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D6E6D64EC3 for ; Wed, 3 Mar 2021 22:25:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D6E6D64EC3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: In-Reply-To:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Reply-To:Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=desn8XZSJIcu0IuEODd+DU0Ynezc5dAxpO+5l+9p+8g=; b=O5unuNvLXhgfJunfluNq6YPQm JnBNPdC0giUXSp4mh7vTvDlVuAehRKSSUGUaN/6enF00UmFw8XEQjDzkHo4AHv98lvHwMCy4XWBIl djcCm37r5KnKc0XlIST9wKJLlow5xdPfJ6tX7UqV3mRbjWuCt97LH3TEbES3+i5lJxKHcwQICIwJv z4n0DcQhrJ69+BWTwql8hKhr5Y040WG5xCIWYACl5x3A/f5eRZ5eZ3QW7aOWJKxR3VhFgXt9h8hdO 7fOu7OWJH/rf6ki57Hjtl6Dc5hSeOSv/P70EjfleDFEfYLtTR6D7PbusmqAALoGFK7Ryq2YnsO8Pu FtdFTuRQQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lHZqj-006jkF-TL; Wed, 03 Mar 2021 22:20:10 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHTAr-005Kii-Nx for linux-arm-kernel@desiato.infradead.org; Wed, 03 Mar 2021 15:12:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=U6T9PbU/F4qKp+N/YQtkVMfFVe3qnYSRW1k8rGsnvnk=; b=jeFr5EUsvzUt6CQG0PHMn5gHID i3RD5kccUJkNxdxJK/07Z9J9lLzHU0Vfhsinozj0l8DEMFQwA4BFR2Yh8pOq4lw1WJOusbyUxeWUq LsLWfKqP0va41prdAAGOR/fql7mAiyakBIPsB+dPHH1sLkbCX10cGUuGH4KtCUIDBhHQizYqbQUwh ew9c6xu9RurZk4qSzkmHewwKFTYMFU1HYbWYbydVifO7lWrYaELV4BoWTqV0hu2NayNi5n/ObJbMc msE+JGl0OQog4h9OO8s59KLJVCJEbaQobsICgokwi3HKgBWapKjXa0xj3d3INzpyIOCaa5AqVk7Qv mwG1KFPQ==; Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by casper.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lH6TI-00HImb-Og for linux-arm-kernel@lists.infradead.org; Tue, 02 Mar 2021 14:58:02 +0000 Received: by mail-pg1-x530.google.com with SMTP id a4so13943215pgc.11 for ; Tue, 02 Mar 2021 06:57:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=U6T9PbU/F4qKp+N/YQtkVMfFVe3qnYSRW1k8rGsnvnk=; b=BBmSnXXr+94I6o1ekJr9V+ADvzDVATCFa7BccMr9FAJhc0gsyNi5pLeemmgdQhFhfL G9Mso1M/4bzUIVzexYT4ggJhMej38VIoGil1Z4SnggW/LKRm3OKV88h9RKKOh5p5XA5O 15quSskjfkQTAlyI23i8U7rTHirlIoRTfyHu7ICnbuk7HM83LI1wZX/A7EB0E2imd2iz xF1BKS8jaXgWQyxjgf6YgnoiNuZP93gDZhF0xpDURqMZulbVP9RkSeV+hYme0zfuYbLo qAF5kB1a3JMgNlJyYknLMlLknaZZX9TduHtqiGBBNyn8KNgdpoQ/dmniWSptZtW5/VNM am6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=U6T9PbU/F4qKp+N/YQtkVMfFVe3qnYSRW1k8rGsnvnk=; b=W1/Vn5i1zlk+UdxzJ5YG+uGXYu9fobWPlUKXqErrts9X4N4qaQ3XqjYCB5g7YvADCV 7226RKhOI9lrBJ37X7ADTmeGz4Nn0e0MPsPq0LOd54pUOZiNT1UjdDMygiT+40lF/5HY WyyQbTt15Cx/0lSIcPQ8sLzCT9+j1J44xQH+DT//PpmEvA+ud1HYSxSZ6aITJd1NOB82 AR3+uAzcYV4Z2rNWNYY/dGojWauOwbgY16+6FW0cn60PJV5KiR73L5BgK8lRAxuxk5Kk /7pi6vXsGDOLhSN6DiFCTHzgsRLewGVEDH8GRypbfNAPbQ46o5LHmo8qsqsOX8LeR85H KRuQ== X-Gm-Message-State: AOAM530cHn/pBp3C/rPIZd7xsH6GRIaq8zx6EXI6MP7+Yxzvev9M1+na 428zZlHPsqvnX22DHby1sXU= X-Google-Smtp-Source: ABdhPJzkOHuxJPX9u8w6hzM1eTHou32whD5fTEDPdbRDsHCAUdvnl3kj6FbvUtuDUvEvuW3HZpIemQ== X-Received: by 2002:a63:e747:: with SMTP id j7mr18301486pgk.235.1614697013985; Tue, 02 Mar 2021 06:56:53 -0800 (PST) Received: from shinobu ([156.146.35.76]) by smtp.gmail.com with ESMTPSA id s138sm22917284pfc.135.2021.03.02.06.56.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Mar 2021 06:56:53 -0800 (PST) Date: Tue, 2 Mar 2021 23:56:46 +0900 From: William Breathitt Gray To: Fabrice Gasnier Cc: jic23@kernel.org, david@lechnology.com, alexandre.torgue@foss.st.com, mcoquelin.stm32@gmail.com, olivier.moysan@foss.st.com, linux-iio@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] counter: stm32-timer-cnt: fix ceiling write max value Message-ID: References: <1614696235-24088-1-git-send-email-fabrice.gasnier@foss.st.com> MIME-Version: 1.0 In-Reply-To: <1614696235-24088-1-git-send-email-fabrice.gasnier@foss.st.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210302_145802_402422_5CA45D09 X-CRM114-Status: GOOD ( 21.25 ) 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: , Content-Type: multipart/mixed; boundary="===============3071026837219307490==" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org --===============3071026837219307490== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="wvX72FUvr+D6FcPx" Content-Disposition: inline --wvX72FUvr+D6FcPx Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Mar 02, 2021 at 03:43:55PM +0100, Fabrice Gasnier wrote: > The ceiling value isn't checked before writing it into registers. The user > could write a value higher than the counter resolution (e.g. 16 or 32 bits > indicated by max_arr). This makes most significant bits to be truncated. > Fix it by checking the max_arr to report a range error [1] to the user. >=20 > Fixes: ad29937e206f ("counter: Add STM32 Timer quadrature encoder") >=20 > [1] https://lkml.org/lkml/2021/2/12/358 >=20 > Signed-off-by: Fabrice Gasnier Acked-by: William Breathitt Gray Side question: if priv->ceiling is tracking the current ceiling configuration, would it make sense to change stm32_count_ceiling_read() to print the value of priv->ceiling instead of doing a regmap_read() call? > --- > drivers/counter/stm32-timer-cnt.c | 5 +++++ > 1 file changed, 5 insertions(+) >=20 > diff --git a/drivers/counter/stm32-timer-cnt.c b/drivers/counter/stm32-ti= mer-cnt.c > index ef2a974..2cf0c05 100644 > --- a/drivers/counter/stm32-timer-cnt.c > +++ b/drivers/counter/stm32-timer-cnt.c > @@ -32,6 +32,7 @@ struct stm32_timer_cnt { > struct regmap *regmap; > struct clk *clk; > u32 ceiling; > + u32 max_arr; > bool enabled; > struct stm32_timer_regs bak; > }; > @@ -185,6 +186,9 @@ static ssize_t stm32_count_ceiling_write(struct count= er_device *counter, > if (ret) > return ret; > =20 > + if (ceiling > priv->max_arr) > + return -ERANGE; > + > /* TIMx_ARR register shouldn't be buffered (ARPE=3D0) */ > regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_ARPE, 0); > regmap_write(priv->regmap, TIM_ARR, ceiling); > @@ -360,6 +364,7 @@ static int stm32_timer_cnt_probe(struct platform_devi= ce *pdev) > priv->regmap =3D ddata->regmap; > priv->clk =3D ddata->clk; > priv->ceiling =3D ddata->max_arr; > + priv->max_arr =3D ddata->max_arr; > =20 > priv->counter.name =3D dev_name(dev); > priv->counter.parent =3D dev; > --=20 > 2.7.4 >=20 --wvX72FUvr+D6FcPx Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEk5I4PDJ2w1cDf/bghvpINdm7VJIFAmA+UggACgkQhvpINdm7 VJJt3g/+OVZcvByeL/DXkUu5tzYQxQ5xzzfViSO16w54567c2tGJuB8gBEFaK9eG Q5EzOeM9YaL982A/9OtqQup3CAJVkLizpy65aH1jDlPasA8JKKoelTfd+mAo58Vu hiwG3DXxwOCZNB7b2/+RaKcYyayviVsKgrl8mHUQ1SY81kM3/cdzSLSnAoxkfD8o 7w1CdXnOxDvvTD6rwcbc4izhSSxgHzvaGHFpKwwYa3gDpmCY44rDKsgXc0CL6F2B 1JRDgvIePdqIStdC8VXcGkUwmlrEVwfSqFgbAtadWuwMSR293AR1PCayvsA4yWyo 49fMudR81RlG5aFyYoOWbAvoKpiq81LlGQspGWFcND4mdbDR7qvEeuZO//0wbTxk 5bNTj/VrQeSyNb7HmDFzOaKwF3waAnYpwZyOcUKVwzVNyAJkRq4nCPn29OKHE3mC /Pbun8nAcbF0BP5R6QzX++aELtXzuArqJHOCDudTDQas0i7BNH0/+1KNKvisLTbk 6ftDbo0p3M90RUks08LLVpDzrAUGpyWeq7+VmWj1jHj22759PtbkEd/dxXKMkcQk OwD4+2zRN4yq4J2U8oiofAprHHgidhAXPB+Qvy4GXP1SewZl3q+cXCNn20Se39Xw uEDiJrNEX2zfbyRHx1V1zjqBlXFvCKIt62uqb8FBMmexuC5fmbc= =M2Bd -----END PGP SIGNATURE----- --wvX72FUvr+D6FcPx-- --===============3071026837219307490== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel --===============3071026837219307490==--