From patchwork Mon Jan 29 22:07:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Adami X-Patchwork-Id: 867330 X-Patchwork-Delegate: david.oberhollenzer@sigma-star.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="H8bJE6VO"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="MfYOXBl4"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zVkC96chFz9s71 for ; Tue, 30 Jan 2018 09:07:33 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=8wlaAtRNEz1UTMWrJDLXZkzuMwWEIDLNrs2jueq+zKM=; b=H8bJE6VOkogoKA1iO8vGXUspjM yuBL1a2yDKX6nDJr5No/FR03ZJsQGi2rIQ95XKaDp2jY/ra4JF+50FPBGuiMr36d+gMEGe2NPxx2+ NbwCXCumOMxIbiTLHQ3ZGF8BrLrPWNEqKJ24bUJJR5tpxzwBb5YlJPRvqNt8B8qb8g1yfAD8UoXbf m0JFOHLoT3PdxkHHmFCZYV/qC8A3qP27O6IqFYtEjkFFufQkQVVHuU/GPAmbRxZw2TSxrRNiNRjZL 9OSn4+1A5x2/5x9GRYtP6yPc5/fx3E/szcrEOf/xnoag6/Xr6Bd3+HcZYusSAwIFW+bxbi80S6+V/ cQknbgPA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1egHaM-00013q-6H; Mon, 29 Jan 2018 22:07:30 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1egHaJ-00010a-Mq for linux-mtd@lists.infradead.org; Mon, 29 Jan 2018 22:07:29 +0000 Received: by mail-wm0-x244.google.com with SMTP id r71so17340515wmd.1 for ; Mon, 29 Jan 2018 14:07:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/Y0zWqiaU1jYNFn1E9PqMiqKo4SsSr3Ox7nvLBLfLiQ=; b=MfYOXBl4yJXT/dFtejq75UyA0aFeIz/TPYfRLgN9qHF/3eRomGQ6B9oxlWF1H7lagJ F0QRM/RW0vwbq2ouSotakkCVcrsLF7OuF6FES6Q19RQjyQQSQdMbjuX5iXVBDh2jTnWT R8FctUGyRiyI4BDVjbR20iJEWQpwv7Ua6BSuKexC6dd0WsVK9b3Jsk3JqbhwE9tE2NR8 OjzbUex+gmq6x7DjtrQmGgSnYqCGxRJsWKid/RxVud0mG7prl3t5fIsLedSMbQnd7qEs Zznh0E6Yt3X+TJUd1XjuJ+tzG9eP9/1y8BRUekDJ78b/RVIexzCFGr4fr+fMt09i7Va7 2pTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/Y0zWqiaU1jYNFn1E9PqMiqKo4SsSr3Ox7nvLBLfLiQ=; b=V5ADZPMtwWFR/+ATKnLdonJjWLo2tfc7U+GrmdpsJ9vnjPMqpjZDHfmb8h5VtejmHs 31SkKk1cqGojHNAFFU6xaesznp7rEBh2D6az5kYqC6KCIhOv+4CkyVlWjjWFRAbzEses kABt84o+XHczFR78LH1/WonJb6kSBeBgSFjcT1aAuA0GbeoMxviIqRO5aDFZxiYDHAnb L1/c9Umqn10Wc3Mxn/ZJSlcQX/YkMlB8ZHxAJ0r98NRD0FFDlnWrQ8hFUMa7N3LwNNKi ozCnqG4kvCFsqq0bS8TBO0bDQ8M+xehWqZsTkVvBjuDzo2erbszkd+h8FcAJP2Jo0GOH MsNg== X-Gm-Message-State: AKwxytfaCuguR0itKAH62Lg9rGkfnJpeWWE+40bJjYEJqvHc8iiYsi97 OnObfBhQpCubL9Kui9Ev/ow9wA== X-Google-Smtp-Source: AH8x227gu8YjHg4I9qYNTna3v24Azgp963M+YIng9rrRK/47KFkVVnOAzL+yVd26AubpCE66O22COQ== X-Received: by 10.28.155.66 with SMTP id d63mr17329297wme.132.1517263634921; Mon, 29 Jan 2018 14:07:14 -0800 (PST) Received: from andrea-ThinkPad-T520.homenet.telecomitalia.it (host57-10-dynamic.248-95-r.retail.telecomitalia.it. [95.248.10.57]) by smtp.gmail.com with ESMTPSA id v22sm13334832wra.58.2018.01.29.14.07.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 29 Jan 2018 14:07:14 -0800 (PST) From: Andrea Adami To: linux-mtd@lists.infradead.org Subject: [PATCH v2 1/2] mtd-utils: common.c: convert to integer arithmetic Date: Mon, 29 Jan 2018 23:07:11 +0100 Message-Id: <1517263632-11126-2-git-send-email-andrea.adami@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517263632-11126-1-git-send-email-andrea.adami@gmail.com> References: <1517263632-11126-1-git-send-email-andrea.adami@gmail.com> X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:400c:c09:0:0:0:244 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (andrea.adami[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Oberhollenzer MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org We use floating point just to print out KiB, MiB, GiB. Avoid that to be klibc friendly. Fixes compilation for aarch64 against klibc: error: '-mgeneral-regs-only' is incompatible with floating-point argument | printf("%s%.1f GiB", p, (double)bytes / (1024 * 1024 * 1024)); etc. Signed-off-by: Andrea Adami --- v2 fixes -Wformat warnings for printf() using %d instead of %lld lib/common.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/common.c b/lib/common.c index 69b03b3..8041878 100644 --- a/lib/common.c +++ b/lib/common.c @@ -107,6 +107,9 @@ long long util_get_bytes(const char *str) void util_print_bytes(long long bytes, int bracket) { const char *p; + int GiB = 1024 * 1024 * 1024; + int MiB = 1024 * 1024; + int KiB = 1024; if (bracket) p = " ("; @@ -115,12 +118,15 @@ void util_print_bytes(long long bytes, int bracket) printf("%lld bytes", bytes); - if (bytes > 1024 * 1024 * 1024) - printf("%s%.1f GiB", p, (double)bytes / (1024 * 1024 * 1024)); - else if (bytes > 1024 * 1024) - printf("%s%.1f MiB", p, (double)bytes / (1024 * 1024)); - else if (bytes > 1024 && bytes != 0) - printf("%s%.1f KiB", p, (double)bytes / 1024); + if (bytes > GiB) + printf("%s%lld.%lld GiB", p, + bytes / GiB, bytes % GiB / (GiB / 10)); + else if (bytes > MiB) + printf("%s%lld.%lld MiB", p, + bytes / MiB, bytes % MiB / (MiB / 10)); + else if (bytes > KiB && bytes != 0) + printf("%s%lld.%lld KiB", p, + bytes / KiB, bytes % KiB / (KiB / 10)); else return; From patchwork Mon Jan 29 22:07:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Adami X-Patchwork-Id: 867332 X-Patchwork-Delegate: david.oberhollenzer@sigma-star.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ZdjbeyR3"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="R2OKbLNM"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zVkCc3zH4z9sBd for ; Tue, 30 Jan 2018 09:07:56 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=cJl6Cid9/thpzhYkiaLN68sT/4u5YUh+ejQlpmQG5/g=; b=ZdjbeyR3hacgB6sHou8DqBUXDc TxSwnTK3JiVZdWS/j/WGeJ1/6Vk0GFfbAvpV76EwPmcLLf1X5XdT2WK9FUdXH0Jp0lLnEQuhzU43U fS/AK/bhWTAep8jEmQk2ti/4LdnZ7U7KGJi6Nq8g7gD0AzGz0q0qPMEA5wkEvX9YyqnKqcZGTpGZb lPn9qIism/7oeEYAiMOtMPHgVhyIdDueFAp7w+jbX/FJU75g+k4RATyRKu09uRfU24e0yjyq9wLrn yALjUaWkWSAUxl2D7uFSV9DexcM0BOhkZyCoSzwbfVhhM3RW4Toj0zSPBntO9HYrMVFLjgje4gvL3 l0tJ/QvA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1egHah-0001Tp-8S; Mon, 29 Jan 2018 22:07:51 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1egHaK-00010u-AM for linux-mtd@lists.infradead.org; Mon, 29 Jan 2018 22:07:30 +0000 Received: by mail-wm0-x242.google.com with SMTP id x4so902432wmc.0 for ; Mon, 29 Jan 2018 14:07:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QZyp4EjZsz+YG5ddKdDKT6EWEttdMG9o+GFwxHT80dM=; b=R2OKbLNMIPNnviWFH39ku3xVsVMMq22W01PLAwu2KBf5bqtq86Gp9uzgTHi5rmJ3xT /OQ+Ho5bsuihnBg5t6L1UXM4AccYeZ/g/x65bOO6nP4CIhB/2wU+d7UW/UIOZhAfnwwH BIjfV/z71tURTQpf3+zuyFJXIhfXRA3UG2xengAAxPGA98T2fQjHg1QeUvtZrea7q7II dhzwYaB9d12uGQSjQtwhptDYbHmW8bVHuOFhrC5jmlxPZP0nEbaLgkZvYrhqsUuUGDzo cpNTEAAVFCdCs6QVVbg6ZbdddeuM7s2oDthzCXh7xAYI1IHv59PExwgRt0Br2ty5G9Kb 5aCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QZyp4EjZsz+YG5ddKdDKT6EWEttdMG9o+GFwxHT80dM=; b=roFPSymnn17va3Mq/716U+ihOp4jn0gdu+vdFZDYBDm5AJMY74X1ufGd3WZRYTCVCJ ROaRSqDv2Uq19levir9v5AIsUReYomP/I/VFM9c3iv6ZlcB1xaF1a+wa3TTAuFDeOg/q HQFt7WXuDawHG3WfPjl+klX25b+S8irnOrsqjX3EtxNt3mCWhr+XNrtMuaEzxggc4DPW P2GPL1QLjejI0GZmqtN6aZUB29uVS7PwcLPn/06eYHUcHDLshkAQ9ZO07GaBG6bADfvL 1NPxjSkPM9nGb4xdu5574QayRFqptH15hC5CUiTXX3KFbIOkUhfOMT4HbwgHURjBYZd0 PqEg== X-Gm-Message-State: AKwxyteG3OciZM9vmAB9TsPiAZU5//JYJR9IzfgGuVa6bllVZDgM9cET maTWOWT93nhT6wOSNDx5ziCh4w== X-Google-Smtp-Source: AH8x227g/kje0YCWdRw24UQf9XBpwnQRojeQnn2pw0h0y85v3UeCJQl0a+WCsyZ9nR7lniRBHyHSNQ== X-Received: by 10.28.227.70 with SMTP id a67mr17950729wmh.46.1517263636031; Mon, 29 Jan 2018 14:07:16 -0800 (PST) Received: from andrea-ThinkPad-T520.homenet.telecomitalia.it (host57-10-dynamic.248-95-r.retail.telecomitalia.it. [95.248.10.57]) by smtp.gmail.com with ESMTPSA id v22sm13334832wra.58.2018.01.29.14.07.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 29 Jan 2018 14:07:15 -0800 (PST) From: Andrea Adami To: linux-mtd@lists.infradead.org Subject: [PATCH v2 2/2] ubi-utils: ubiformat.c: convert to integer arithmetic Date: Mon, 29 Jan 2018 23:07:12 +0100 Message-Id: <1517263632-11126-3-git-send-email-andrea.adami@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517263632-11126-1-git-send-email-andrea.adami@gmail.com> References: <1517263632-11126-1-git-send-email-andrea.adami@gmail.com> X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (andrea.adami[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:400c:c09:0:0:0:242 listed in] [list.dnswl.org] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Oberhollenzer MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Do not cast percent to double, it is just used as upper limit. Avoid floating point to fix compilation for aarch64 against klibc: error: '-mgeneral-regs-only' is incompatible with floating-point code | int percent = ((double)si->ok_cnt)/si->good_cnt * 100; | ^~~~~~~ Notes: * The checks in the code above this line ensure that si->good_cnt is not 0. * The code assumes si->good_cnt * 100 will not overflow, then we can use (si->ok_cnt * 100) safely because the former is bigger. * The truncated result does not affect the logic: i.e. a value of 49.9 is truncated to 49 and is still <50. Signed-off-by: Andrea Adami --- v2 no changes ubi-utils/ubiformat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ubi-utils/ubiformat.c b/ubi-utils/ubiformat.c index ef0378a..c38b9b4 100644 --- a/ubi-utils/ubiformat.c +++ b/ubi-utils/ubiformat.c @@ -844,7 +844,7 @@ int main(int argc, char * const argv[]) } if (!args.override_ec && si->empty_cnt < si->good_cnt) { - int percent = ((double)si->ok_cnt)/si->good_cnt * 100; + int percent = (si->ok_cnt * 100) / si->good_cnt; /* * Make sure the majority of eraseblocks have valid