public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sudeep Holla <sudeep.holla@arm.com>
To: Tejun Heo <tj@kernel.org>
Cc: Sudeep Holla <sudeep.holla@arm.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Pawel Moll <Pawel.Moll@arm.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>
Subject: Re: [PATCH] bitmap: remove explicit newline handling using scnprintf format string
Date: Mon, 27 Apr 2015 17:26:16 +0100	[thread overview]
Message-ID: <553E6328.2040904@arm.com> (raw)
In-Reply-To: <20150427161434.GF1499@htj.duckdns.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

  reply	other threads:[~2015-04-27 16:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-27  9:46 [PATCH] bitmap: remove explicit newline handling using scnprintf format string Sudeep Holla
2015-04-27 16:14 ` Tejun Heo
2015-04-27 16:26   ` Sudeep Holla [this message]
2015-04-27 16:30     ` Tejun Heo
2015-04-27 16:39       ` Sudeep Holla
2015-04-27 16:40         ` Tejun Heo
2015-04-28 15:36 ` [PATCH v2] " Sudeep Holla
2015-04-29 22:48   ` Andrew Morton
2015-04-30  8:23     ` Sudeep Holla

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=553E6328.2040904@arm.com \
    --to=sudeep.holla@arm.com \
    --cc=Pawel.Moll@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox