From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D69FC388F2 for ; Mon, 2 Nov 2020 17:01:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE41820786 for ; Mon, 2 Nov 2020 17:01:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727453AbgKBRBe (ORCPT ); Mon, 2 Nov 2020 12:01:34 -0500 Received: from smtprelay0231.hostedemail.com ([216.40.44.231]:52312 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727438AbgKBRBd (ORCPT ); Mon, 2 Nov 2020 12:01:33 -0500 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay04.hostedemail.com (Postfix) with ESMTP id 957C3180A8450; Mon, 2 Nov 2020 17:01:32 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-HE-Tag: drug29_53075a1272b1 X-Filterd-Recvd-Size: 2510 Received: from XPS-9350.home (unknown [47.151.133.149]) (Authenticated sender: joe@perches.com) by omf18.hostedemail.com (Postfix) with ESMTPA; Mon, 2 Nov 2020 17:01:31 +0000 (UTC) Message-ID: <7309c580def7427769b4c133c5037209d3ecac91.camel@perches.com> Subject: Re: [PATCH 4/5] mm: shmem: Convert shmem_enabled_show to use sysfs_emit_at From: Joe Perches To: Matthew Wilcox , Greg Kroah-Hartman Cc: Hugh Dickins , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Date: Mon, 02 Nov 2020 09:01:29 -0800 In-Reply-To: <20201102144025.GL27442@casper.infradead.org> References: <20201101204834.GF27442@casper.infradead.org> <616b92af9378e9f9697555074bba1e377450477f.camel@perches.com> <20201101211910.GG27442@casper.infradead.org> <20201101220604.GI27442@casper.infradead.org> <20201102133343.GA1011963@kroah.com> <20201102140836.GJ27442@casper.infradead.org> <20201102143259.GA1024551@kroah.com> <20201102144025.GL27442@casper.infradead.org> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.38.1-1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2020-11-02 at 14:40 +0000, Matthew Wilcox wrote: > For someone who's used to C "strings", it's pretty common to do > something like: > > buf += sprintf(buf, "foo "); > buf += sprintf(buf, "bar "); It's not equivalent code. What was actually necessary was using scnprintf which tests the number of bytes available in the buffer. The actual equivalent code was something like: int used = 0; used += scnprintf(buf + used, PAGE_SIZE - used, "foo "); used += scnprintf(buf + used, PAGE_SIZE - used, "bar "); > sysfs_emit_at instead wants me to do: > > len += sprintf(buf + len, "foo "); > len += sprintf(buf + len, "bar "); > > I don't see how the code I wrote defeats the check. It checks that the > buffer never crosses a PAGE_SIZE boundary, which is equivalently safe. And it'd be required to store the original buf value passed to be able to return the actual number of bytes emitted when multiple calls are used. return sprintf(buf) - obuf; This also does and can not verify that buf is originally page aligned.