Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1874110imm; Sat, 18 Aug 2018 06:17:58 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxoUSXwNesQjrNGzHwb7wkcUDUKIZkp/F4GGiLnaxLC2Im9ZWxtCtFDn+uQciaOFhEweKNO X-Received: by 2002:a62:e511:: with SMTP id n17-v6mr40888844pff.210.1534598278298; Sat, 18 Aug 2018 06:17:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534598278; cv=none; d=google.com; s=arc-20160816; b=jyvVHhyo57osDUsHJv3c6Oplvy3diQ8y+KINphVrCETQ1SZN9cNBvpS3yJ94bQ+Rwa Y9NYpkgv29SOn7m/UIZN5jq2AncIGJagNKdLYCe6HqoKkGvh/MHBgd9sEhn3lI9H60A9 gHhrB3miXETEoS4fY8NLV5rvpjUdmXFGt7QVpuE1Awsa0J/AR+e6flh4YroRe98fhZuE tSb6jPC59wX+eRzwc+zaK3Qz6cmFef/wjAH669CR9Zp3TnamwEGM8eFhArzTVyuHT+wH qVzmKzRI3coIsJfnc8Z8L90UHgrCBGs58GmuLdXnmzTTK4gotj3J67AA9Vqo3RN5HA18 HrcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=dxhFnp8a3JQlhkZoZgfQ7p7+WfMJlV8bqTkBphCAz9Y=; b=vOW+0c34LMr0gUYYjvFa9p+lcRVHgFFPV0D3P39hz12CRYrkQbHT+1GXD80m2TzYmL +jPJbXk0ifB6tgInqQHo1IoI3jXCSKfFX2+8TWHku0pdEtz5au5As/8ruVSTflQVhDOQ Yb1fhLogHCdTOcRcwGYQ6qDBfnUC1y6yW+RU4eJrW7z9Tl8V6w1tyQnP5rfxeKOsz9J3 fFdpF8W82YFfl/d9IHrSJmt1BrAAct7dWQWWF40ME8Fc8JqBNqHhSdrBQZYkqJox33dp KIS2ja3PnqBIzdX176LyVjn/Hx7oaCtTThHfhFrjYeaorIIVBRBkqSO9nvuLXqgyqy13 j55Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=elWHM+iG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c10-v6si1761329pla.450.2018.08.18.06.17.43; Sat, 18 Aug 2018 06:17:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=elWHM+iG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726564AbeHRQYS (ORCPT + 99 others); Sat, 18 Aug 2018 12:24:18 -0400 Received: from mail-ed1-f44.google.com ([209.85.208.44]:44084 "EHLO mail-ed1-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726441AbeHRQYR (ORCPT ); Sat, 18 Aug 2018 12:24:17 -0400 Received: by mail-ed1-f44.google.com with SMTP id f23-v6so5961233edr.11 for ; Sat, 18 Aug 2018 06:16:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dxhFnp8a3JQlhkZoZgfQ7p7+WfMJlV8bqTkBphCAz9Y=; b=elWHM+iGNhV9lbryXnmtdjRblmiRsvJJqpUdtHkHc4LYeK/RKJijZ9qEnz+4ATOe+V /NB3N07IF9p4851sppyJVHWPlU1PzbM9aZZYs1D9NRho0MVBIs8afVTpTyycATeoxRCi JUbttuidtEzMzrCb5vjkiT0J6WMZFXNVHyzjY= 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=dxhFnp8a3JQlhkZoZgfQ7p7+WfMJlV8bqTkBphCAz9Y=; b=FXgSPnrrPySCYA0ICC67r/EZAezYmEr/qIKw/AYxJwsIlRQux0SFX0Jeyfdkjkh3pH yq00hVLJIXHi06Wb1pRGIzpJbMRUMC9Acjr2AGAn4GRFeMCxiXRXgkb/57hZkntSF/e7 TpGABq37a+uKBcXYpqnI8L928rCL5OVjmBgg4uqltIT59LKZ3JCPHUtHnXexFyCJBKU+ JzJnXSLh+2mBdpMkaf2lBozBloBIkBrv/ZUOJ9Rqc17juPZ57g3MmGdGfphyF6VoIp4g G20tudFXWPLixMYQuk2XDp+tUXvGZoWXsl0oN3Vzbkr5M2kuzUaND1NBkZZ1jGvcoQve XBpQ== X-Gm-Message-State: AOUpUlEZgc5ZcFyMESpIqpmx6rDtD0+xbufbnIJP3fumFTxE/+9m88ax xxMDcDfDaqB/4nY7i7bQMhPFmMZEeikE/A== X-Received: by 2002:a50:da01:: with SMTP id z1-v6mr46785481edj.62.1534598195349; Sat, 18 Aug 2018 06:16:35 -0700 (PDT) Received: from prevas-ravi.waoo.dk (dhcp-5-186-114-212.cgn.ip.fibianet.dk. [5.186.114.212]) by smtp.gmail.com with ESMTPSA id r11-v6sm2821403edp.60.2018.08.18.06.16.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 18 Aug 2018 06:16:34 -0700 (PDT) From: Rasmus Villemoes To: Andrew Morton , Yury Norov Cc: Andy Shevchenko , Rasmus Villemoes , Sudeep Holla , linux-kernel@vger.kernel.org Subject: [PATCH 7/7] lib/bitmap.c: simplify bitmap_print_to_pagebuf Date: Sat, 18 Aug 2018 15:16:23 +0200 Message-Id: <20180818131623.8755-8-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180818131623.8755-1-linux@rasmusvillemoes.dk> References: <20180818131623.8755-1-linux@rasmusvillemoes.dk> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org len is guaranteed to lie in [1, PAGE_SIZE]. If scnprintf is called with a buffer size of 1, it is guaranteed to return 0. So in the extremely unlikely case of having just one byte remaining in the page, let's just call scnprintf anyway. The only difference is that this will write a '\0' to that final byte in the page, but that's an improvement: We now guarantee that after the call, buf is a properly terminated C string of length exactly the return value. Signed-off-by: Rasmus Villemoes --- lib/bitmap.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/bitmap.c b/lib/bitmap.c index 277c9a63a5ab..75175da01fd8 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -469,12 +469,9 @@ int bitmap_print_to_pagebuf(bool list, char *buf, const unsigned long *maskp, int nmaskbits) { ptrdiff_t len = PAGE_SIZE - ((unsigned long)buf & (PAGE_SIZE-1)); - int n = 0; - if (len > 1) - n = list ? scnprintf(buf, len, "%*pbl\n", nmaskbits, maskp) : - scnprintf(buf, len, "%*pb\n", nmaskbits, maskp); - return n; + return list ? scnprintf(buf, len, "%*pbl\n", nmaskbits, maskp) : + scnprintf(buf, len, "%*pb\n", nmaskbits, maskp); } EXPORT_SYMBOL(bitmap_print_to_pagebuf); -- 2.16.4