Message ID | Y0f+tKCz+ZAIoroQ@dc75zzyyyyyyyyyyyyycy-3.rev.dnainternet.fi |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp234486wrs; Thu, 13 Oct 2022 05:06:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5gxwH5DduqMswjJRHPEHpuOePjceMbu33cpdLV+S74/pYviHy024n/dIP33b5EKIeceNAB X-Received: by 2002:a05:6a00:88f:b0:52c:6962:274f with SMTP id q15-20020a056a00088f00b0052c6962274fmr37214351pfj.12.1665662772714; Thu, 13 Oct 2022 05:06:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665662772; cv=none; d=google.com; s=arc-20160816; b=hDXjiTgIC/Zl3T/EkgD/qbGn0iY2iajc40pE0Z+pe3H2/3z0g37ogQl859ysBXQDbo EqkKjdX9g+GJzhu8kCYsGHXIMjhQvnrXVrWDjvcprk95Psi1w4wjF5/uqr6NfXMNgRsO 7Z+hL4aa1P1ZZM0+0Hbg1vcIIDGDUlhcRqP7uxZxzhKeVtukTgANWiwvOFjNujVAbO+b dcTwtgw2ad3DgDRXCw0aQ2AEqzGqyerMq0HXmmyNNMj0tWBOxdQpU5rAiOPS9ev9xrp2 HEUMslYGj0CCLiCAMBwZZBAt/u5L3Jat4Qe8APx2MfOfrnxIy95E1yGdWiVF2WRgh5Yh HPlA== 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:cc:to:from:date:dkim-signature; bh=xKC63qt3cm6YXRHgcntnH0PvtZLR9kcs/isijApz+ls=; b=X9CviPwWdoAkSm3ysW91lSBXaLF0rQMRq65IfMTWFI0Hc9388cFwzXY3iRV3slLjQk x0/Kkh5LaouNsl2S65Wpq0cTccUrRpxy7oX7ebz/9BumnZGuyD/O+HdWLlNt6+YCX3gI IagebjE+c1fbMcZ+FPyTUt436kbLzSfxtC0zBO8q+6Gj2rwb9A26ktinsVlHQ4h89Fxe ENxbEQkHnxoriMZGwleI29lpam/Pc/tM4LV/Uure3YuPbab1LMZ3I+QZHboYLo22tOkl SLDzBwjuhq//dk6Yh4bnZuYLu5lrSpN+Z+Ulwk0WThBtV2SOGnevBUo2UZ/+VT2yWjX6 ewJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=e7XsURb1; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b10-20020a056a00114a00b00562a1cb3661si3249205pfm.272.2022.10.13.05.05.59; Thu, 13 Oct 2022 05:06:12 -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=pass header.i=@gmail.com header.s=20210112 header.b=e7XsURb1; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229543AbiJMMFD (ORCPT <rfc822;ouuuleilei@gmail.com> + 99 others); Thu, 13 Oct 2022 08:05:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbiJMMFA (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 13 Oct 2022 08:05:00 -0400 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAE7B303F2; Thu, 13 Oct 2022 05:04:58 -0700 (PDT) Received: by mail-lj1-x22d.google.com with SMTP id a25so2098591ljk.0; Thu, 13 Oct 2022 05:04:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=xKC63qt3cm6YXRHgcntnH0PvtZLR9kcs/isijApz+ls=; b=e7XsURb1RcZi3Nh/LAiEeEg1Ck5uv1klfPu0FDyuB+c6O2VvSpgaaaR+rWiLHAG98D medPItFI58F6F31FmgihXNuTasYDNf56dI6AzsHI5SzsmVqJfjhBbkeMdVnuhsiZIjAB aZsgwozFcen0t9cIFS4LOwv3ruR9/c8eXRo7Xd3QETCc5zhJxQO+0TJKHQ/wNS14A2N6 WfDWq0E9Lk6OIPJOwim2h1UvUWGmzc3nlvA4qxW5+FcPDgY/aLJX8C+cZUMJGmf5UWkO WbFPiMBYtJv7xkYSfJ0Ey1BP01eOv4pMqNK78on2wWupxrFn3F7UulxFyChavfJThCzg qN+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xKC63qt3cm6YXRHgcntnH0PvtZLR9kcs/isijApz+ls=; b=RtSEBqjWyoEGvG/XrjsO4BH+vi7ghkDd5lypKUC7VAsuX+pG5eKVZbv1r/GJ0jwbcl IacNpuKdV2ngnyfC/iAOi17Xef+SDP2G9BRcoGlxTpe8O7nzduY0vPytvOd76Rq9zaJ1 rSpDVrqNb3C/U6sTikYuk6poyo3TJd/p1Jkp4wez7DJ+NL+1hVN/LKdEkqumqcHdkicG snntjgxbSq6WNEGAt4SYTJn2jmYQT5dRIUeFAHfKbWd1Smcsg/ImEjW5O7Ti8CM2f1/i gquw6KZBdMMrcrGiqUKwEavNgUhls2z92vzJqwNbP0eristv2W/GzE7xIg+1zkwjbNKR GYGw== X-Gm-Message-State: ACrzQf28deBbWtZqHL2Tl2vukNWUrsSG4C4gHZMcMRUTotEeRRWUQViz p+00VLMsxtQya9KtsDJVUtM= X-Received: by 2002:a2e:6d02:0:b0:26a:cf02:40c4 with SMTP id i2-20020a2e6d02000000b0026acf0240c4mr13103360ljc.513.1665662665868; Thu, 13 Oct 2022 05:04:25 -0700 (PDT) Received: from dc75zzyyyyyyyyyyyyycy-3.rev.dnainternet.fi (dc75zzyyyyyyyyyyyyycy-3.rev.dnainternet.fi. [2001:14ba:16f3:4a00::4]) by smtp.gmail.com with ESMTPSA id 5-20020ac25f05000000b0049d83646ce7sm378761lfq.110.2022.10.13.05.04.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 05:04:24 -0700 (PDT) Date: Thu, 13 Oct 2022 15:04:04 +0300 From: Matti Vaittinen <mazziesaccount@gmail.com> To: Matti Vaittinen <mazziesaccount@gmail.com>, Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com> Cc: Jonathan Cameron <jic23@kernel.org>, Lars-Peter Clausen <lars@metafoo.de>, Hartmut Knaack <knaack.h@gmx.de>, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] tools: iio: iio_utils: fix digit calculation Message-ID: <Y0f+tKCz+ZAIoroQ@dc75zzyyyyyyyyyyyyycy-3.rev.dnainternet.fi> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="AeOA1JcKrLrt2PA9" 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,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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?1746574007171168200?= X-GMAIL-MSGID: =?utf-8?q?1746574007171168200?= |
Series |
tools: iio: iio_utils: fix digit calculation
|
|
Commit Message
Matti Vaittinen
Oct. 13, 2022, 12:04 p.m. UTC
The iio_utils uses a digit calculation in order to know length of the
file name containing a buffer number. The digit calculation does not
work for number 0.
This leads to allocation of one character too small buffer for the
file-name when file name contains value '0'. (Eg. buffer0).
Fix digit calculation by returning one digit to be present for number
'0'.
Fixes: 096f9b862e60 ("tools:iio:iio_utils: implement digit calculation")
Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
---
tools/iio/iio_utils.c | 4 ++++
1 file changed, 4 insertions(+)
base-commit: 4fe89d07dcc2804c8b562f6c7896a45643d34b2f
Comments
On Thu, 13 Oct 2022 15:04:04 +0300 Matti Vaittinen <mazziesaccount@gmail.com> wrote: > The iio_utils uses a digit calculation in order to know length of the > file name containing a buffer number. The digit calculation does not > work for number 0. > > This leads to allocation of one character too small buffer for the > file-name when file name contains value '0'. (Eg. buffer0). > > Fix digit calculation by returning one digit to be present for number > '0'. > > Fixes: 096f9b862e60 ("tools:iio:iio_utils: implement digit calculation") > Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com> hi Matti Makes sense. Applied to the fixes-togreg branch of iio.git and marked for stable. Thanks, Jonathan > --- > tools/iio/iio_utils.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c > index aadee6d34c74..8d35893b2fa8 100644 > --- a/tools/iio/iio_utils.c > +++ b/tools/iio/iio_utils.c > @@ -547,6 +547,10 @@ static int calc_digits(int num) > { > int count = 0; > > + /* It takes a digit to represent zero */ > + if (!num) > + return 1; > + > while (num != 0) { > num /= 10; > count++; > > base-commit: 4fe89d07dcc2804c8b562f6c7896a45643d34b2f
diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c index aadee6d34c74..8d35893b2fa8 100644 --- a/tools/iio/iio_utils.c +++ b/tools/iio/iio_utils.c @@ -547,6 +547,10 @@ static int calc_digits(int num) { int count = 0; + /* It takes a digit to represent zero */ + if (!num) + return 1; + while (num != 0) { num /= 10; count++;