From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753320AbbD0Q0V (ORCPT ); Mon, 27 Apr 2015 12:26:21 -0400 Received: from foss.arm.com ([217.140.101.70]:57163 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751803AbbD0Q0T (ORCPT ); Mon, 27 Apr 2015 12:26:19 -0400 Message-ID: <553E6328.2040904@arm.com> Date: Mon, 27 Apr 2015 17:26:16 +0100 From: Sudeep Holla User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Tejun Heo CC: Sudeep Holla , "linux-kernel@vger.kernel.org" , Pawel Moll , Andrew Morton , "Peter Zijlstra (Intel)" Subject: Re: [PATCH] bitmap: remove explicit newline handling using scnprintf format string References: <1430128018-14667-1-git-send-email-sudeep.holla@arm.com> <20150427161434.GF1499@htj.duckdns.org> In-Reply-To: <20150427161434.GF1499@htj.duckdns.org> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 27/04/15 17:14, Tejun Heo wrote: > Hello, Sudeep. > > On Mon, Apr 27, 2015 at 10:46:58AM +0100, Sudeep Holla wrote: >> int bitmap_print_to_pagebuf(bool list, char *buf, const unsigned long *maskp, >> int nmaskbits) >> { >> - ptrdiff_t len = PTR_ALIGN(buf + PAGE_SIZE - 1, PAGE_SIZE) - buf - 2; >> + ptrdiff_t len = PTR_ALIGN(buf + PAGE_SIZE - 1, PAGE_SIZE) - buf; >> int n = 0; >> >> - if (len > 1) { >> - n = list ? scnprintf(buf, len, "%*pbl", nmaskbits, maskp) : >> - scnprintf(buf, len, "%*pb", nmaskbits, maskp); >> - buf[n++] = '\n'; >> - buf[n] = '\0'; >> - } >> + if (len > 1) >> + n = list ? scnprintf(buf, len, "%*pbl\n", nmaskbits, maskp) : >> + scnprintf(buf, len, "%*pb\n", nmaskbits, maskp); >> return n; >> } >> EXPORT_SYMBOL(bitmap_print_to_pagebuf); > > So, there's one behavior difference stemming from this. When the > buffer is too small, the original code would still output '\n' at the > end while the new code would just continue to print the formatted > string. Completely agree and in-fact we did discuss that internally too. But since this function deals only with page size buffers, we thought it's highly unlikely to hit that corner case. > Given that bitmap outputs can be pretty long, this behavior > difference has a minute but still non-zero chance of causing something > surprising. There are multiple copies of the above function in arch > codes too. I assumed that I had consolidated most of them in commit 5aaba36318e5 ("cpumask: factor out show_cpumap into separate helper function"). I might have missed, will have a look at it again. > We prolly want to audit the usages to verify that the > passed in buffer is always big enough at which point the above > function and its copies can simply be replaced with direct scnprintf() > calls. This function doesn't actually add anything. > Ah, right that would be much simpler. Regards, Sudeep