Message ID | Y1r+EHqpVz/HYrIm@ubunlion |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp474385wru; Thu, 27 Oct 2022 14:58:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6GA4oDw/HyeVk2OXTcU5qeWZVbO/qECpwTSFwTB8oYSPzyhOntYaVIjgkItbCc6GPbvYTW X-Received: by 2002:a17:907:9717:b0:78d:9fb4:16dd with SMTP id jg23-20020a170907971700b0078d9fb416ddmr45038675ejc.720.1666907919009; Thu, 27 Oct 2022 14:58:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666907919; cv=none; d=google.com; s=arc-20160816; b=IpH9iZ7Cf8rz625NgB23LDDKlIN0xll5wBhTgSweqecHWNHJH+M/KmGaGc+mIRZ74d rINDkA9UNYo+jTTsh0yRN+Pm4Je1YYe0yNBHmvedkc27sMW6IbpXbgEynCzfMBgcaec9 xBJrzyqj3T4ZBtlcvJi71nQdoaAi4QhaPlCwtv7bOW+GYIRVLtYX1GFu7lzyVVm2uMcp jJD/LPP1O8CnXAnuh7rLWGXre6j/ycve6rVyaO93otXVmYt5k4cGRIczMVBSRFBFUlnO UapfGZfRr7otM2TOCZ415wZ4fGJgygr449Yf0z1dF11iXr1wTNIfSGoFv1Eir25rjql1 vjRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:to:from:date:dkim-signature; bh=FTkhBeepRKSAHiYLJq9sHFnd+ItThndsaOmn8W9S0OA=; b=Q/fUtGIafCgF54Lqjeb8oj4PnRlXFmc3xwdeKdp9+dGwK29qAfo6Ba5KgaUiwfjdot 90gnwcPaoivUX9APb396jqdVWDxPEwipDJ3bU9OlIo4JFUD7rsR//52oJDaZy5/fkQpA ZuwpGParryPnyV6ZS+r8GBJRm1yZ+BYL1ymzvlRUAf6Rz0KPkFi1b7zCpp6HLZpFHIOl LpbVHjJwGu5pQfFTH/Mv883zw5IWaf767mv0JzQ1aO2MVc654akVUnyXKFU5OljX0yV2 tqoP7bPme75U9JcL5Wfx58ctD1sljHAxVoYtN3mi5D5wK0Z9y0VxqPhXh36R3IoeHwQn LDdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=e64bH2KC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id he8-20020a1709073d8800b00782a5657512si2724569ejc.416.2022.10.27.14.58.15; Thu, 27 Oct 2022 14:58:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=e64bH2KC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236592AbiJ0Vy5 (ORCPT <rfc822;chrisfriedt@gmail.com> + 99 others); Thu, 27 Oct 2022 17:54:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233569AbiJ0Vyz (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 27 Oct 2022 17:54:55 -0400 Received: from msg-1.mailo.com (msg-1.mailo.com [213.182.54.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E6505AA22; Thu, 27 Oct 2022 14:54:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1666907670; bh=4oNdMi2kwzVQqP/G4iEoq1fG0MnLzqOREBAq7uQlKko=; h=X-EA-Auth:Date:From:To:Subject:Message-ID:MIME-Version: Content-Type; b=e64bH2KCF/NhJoK7k50x0726Cj5ZS9rGv3hbTf8tz3Bm/9XvAn5m+EMVyt2HlMW1c dvqfdpENHQrLWJtoicI2guChk23LV+q9UGLQPqoaBLAZ/D/NfnF7FaEML1GJPO21lx JvYGG7Wads6WLSJEnsC9A7xyJ7uJ1kKqmfZa4VFs= Received: by b-4.in.mailobj.net [192.168.90.14] with ESMTP via [213.182.55.206] Thu, 27 Oct 2022 23:54:30 +0200 (CEST) X-EA-Auth: pBtERwH+CqDwwoap8myOtvOhAxjDOFlSbXiE1xcZX4jb77aRpGyBPzTOL5KKCfbUA5uF7kSH2l7vbDTeoiapN5VOEN0ZNqsl Date: Fri, 28 Oct 2022 03:24:24 +0530 From: Deepak R Varma <drv@mailo.com> To: outreachy@lists.linux.dev, Lars-Peter Clausen <lars@metafoo.de>, Michael Hennerich <Michael.Hennerich@analog.com>, Jonathan Cameron <jic23@kernel.org>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, linux-iio@vger.kernel.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH] staging: iio: frequency: ad9832: Use div64_ul instead of do_div Message-ID: <Y1r+EHqpVz/HYrIm@ubunlion> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747879638119064991?= X-GMAIL-MSGID: =?utf-8?q?1747879638119064991?= |
Series |
staging: iio: frequency: ad9832: Use div64_ul instead of do_div
|
|
Commit Message
Deepak R Varma
Oct. 27, 2022, 9:54 p.m. UTC
do_div() does a 64-by-32 division. Here the divisor is an unsigned long
which on some platforms is 64 bit wide. So use div64_ul instead of do_div
to avoid a possible truncation. Issue identified using the
coccicheck tool.
Signed-off-by: Deepak R Varma <drv@mailo.com>
---
drivers/staging/iio/frequency/ad9832.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
--
2.34.1
Comments
> -----Original Message----- > From: Deepak R Varma <drv@mailo.com> > Sent: Thursday, October 27, 2022 11:54 PM > To: outreachy@lists.linux.dev; Lars-Peter Clausen <lars@metafoo.de>; > Hennerich, Michael <Michael.Hennerich@analog.com>; Jonathan Cameron > <jic23@kernel.org>; Greg Kroah-Hartman <gregkh@linuxfoundation.org>; > linux-iio@vger.kernel.org; linux-staging@lists.linux.dev; linux- > kernel@vger.kernel.org > Subject: [PATCH] staging: iio: frequency: ad9832: Use div64_ul instead of > do_div > > [External] > > do_div() does a 64-by-32 division. Here the divisor is an unsigned long > which on some platforms is 64 bit wide. So use div64_ul instead of do_div > to avoid a possible truncation. Issue identified using the > coccicheck tool. > > Signed-off-by: Deepak R Varma <drv@mailo.com> > --- Reviewed-by: Nuno Sá <nuno.sa@analog.com>
On Fri, 28 Oct 2022 10:11:56 +0000 "Sa, Nuno" <Nuno.Sa@analog.com> wrote: > > -----Original Message----- > > From: Deepak R Varma <drv@mailo.com> > > Sent: Thursday, October 27, 2022 11:54 PM > > To: outreachy@lists.linux.dev; Lars-Peter Clausen <lars@metafoo.de>; > > Hennerich, Michael <Michael.Hennerich@analog.com>; Jonathan Cameron > > <jic23@kernel.org>; Greg Kroah-Hartman <gregkh@linuxfoundation.org>; > > linux-iio@vger.kernel.org; linux-staging@lists.linux.dev; linux- > > kernel@vger.kernel.org > > Subject: [PATCH] staging: iio: frequency: ad9832: Use div64_ul instead of > > do_div > > > > [External] > > > > do_div() does a 64-by-32 division. Here the divisor is an unsigned long > > which on some platforms is 64 bit wide. So use div64_ul instead of do_div > > to avoid a possible truncation. Issue identified using the > > coccicheck tool. > > > > Signed-off-by: Deepak R Varma <drv@mailo.com> > > --- > > Reviewed-by: Nuno Sá <nuno.sa@analog.com> As per the email Greg linked to, please take a close look at the surround code and include analysis of whether the value can actually be greater than 32 bits. Note that in most cases that would actually mean the code was broken on 32 bit platforms.
diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c index 6f9eebd6c7ee..a8409f6b1c4c 100644 --- a/drivers/staging/iio/frequency/ad9832.c +++ b/drivers/staging/iio/frequency/ad9832.c @@ -122,8 +122,7 @@ static unsigned long ad9832_calc_freqreg(unsigned long mclk, unsigned long fout) { unsigned long long freqreg = (u64)fout * (u64)((u64)1L << AD9832_FREQ_BITS); - do_div(freqreg, mclk); - return freqreg; + return div64_ul(freqreg, mclk); } static int ad9832_write_frequency(struct ad9832_state *st,