From patchwork Mon Jun 20 00:42:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 12886914 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3DF82C433EF for ; Mon, 20 Jun 2022 00:43:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D01F46B0085; Sun, 19 Jun 2022 20:43:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CB25D6B0087; Sun, 19 Jun 2022 20:43:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B7A946B0088; Sun, 19 Jun 2022 20:43:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id AA9F26B0085 for ; Sun, 19 Jun 2022 20:43:26 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 86308801E0 for ; Mon, 20 Jun 2022 00:43:26 +0000 (UTC) X-FDA: 79596765612.25.0B09A3D Received: from mail-qv1-f51.google.com (mail-qv1-f51.google.com [209.85.219.51]) by imf13.hostedemail.com (Postfix) with ESMTP id E8C5A200AB for ; Mon, 20 Jun 2022 00:43:25 +0000 (UTC) Received: by mail-qv1-f51.google.com with SMTP id c1so13649803qvi.11 for ; Sun, 19 Jun 2022 17:43:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HWerF38n5tR4uSTYJFoRyRIOxNHFK081RFLAVt0+9RY=; b=gdle2QPYdF/YDxgrZ9pCDc5ZojhpY5013lioWippA7pS5CQtIdOHGV0VF6XVa7t8ur E4yDb9mwxMBv1FoxU33la1kQe+PkFQh+p4f404l5zrxKPcn7TqNGt2UAOeSLXL4sc9KE XTUgUbfGvRPlBJCKZYScvl0eybu5/QUXFImffx6qGE9NmZz830DBTO+DCBDXTRmWC66O Po1GeL6X5PVq6XXZ61vXr/ublbiswEFasOtyLVMIwXoK2hTpb15WdTu9/fuuVMnZPaUo mZWzHxOUGkR4pdoohQxvviHKsTD8mB0XpzPBuVFY+tNQg5HNEefdc4RGvWTO+Uq850ej 9HWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HWerF38n5tR4uSTYJFoRyRIOxNHFK081RFLAVt0+9RY=; b=Ym9Z8q2THVGulz16WbH8P5JCANKmcbFgcNeY2s9mIE+s781TbuvJkrv+ISnu9LuZZv C0jNkMknHq8PQU4qFWW4mnOi42foCoSntZT4zUPAacmveDM9OUPXURweNN9KgwUSBMID DyWUizKZL7j7mf8MPh8xgTUNOirjGuN0DLXKMOcNZrmsF++Y8fsi4eIlvz/+pVyJKz4p 0eFhLD4inGwfNgs3FbCk0PcmXAoNxfqM4v9NyDkgknmrKtLtDm3BydbgDs6fInvWQBYG rU9SJZWmzHv+aMl3GI+rGIKI+PghqdXxuuxRNqqH2QA6MDDPa73PKdT4SahWH931akDp UPsg== X-Gm-Message-State: AJIora96558S23MtXpCjm1veydrv1iDwTUdSoEC/rzXPkoGQf6fA/YkR v7JINjFEu36foBId/9ZARg== X-Google-Smtp-Source: AGRyM1sqZc0tCgtuhT0Syhi5cozDr+xp4LtE9SWos2+SZBuOvssoygcA8ICZRj2oL8lN6sg+wRIGtw== X-Received: by 2002:a05:6214:62a:b0:46e:5f25:56b6 with SMTP id a10-20020a056214062a00b0046e5f2556b6mr17206265qvx.12.1655685803670; Sun, 19 Jun 2022 17:43:23 -0700 (PDT) Received: from localhost (c-73-219-103-14.hsd1.vt.comcast.net. [73.219.103.14]) by smtp.gmail.com with ESMTPSA id bi20-20020a05620a319400b006a6dcd92eb3sm10291756qkb.121.2022.06.19.17.43.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jun 2022 17:43:23 -0700 (PDT) From: Kent Overstreet To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, pmladek@suse.com Cc: Kent Overstreet , rostedt@goodmis.org, enozhatsky@chromium.org, linux@rasmusvillemoes.dk, willy@infradead.org Subject: [PATCH v4 21/34] vsprintf: Refactor device_node_string, fwnode_string Date: Sun, 19 Jun 2022 20:42:20 -0400 Message-Id: <20220620004233.3805-22-kent.overstreet@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220620004233.3805-1-kent.overstreet@gmail.com> References: <20220620004233.3805-1-kent.overstreet@gmail.com> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=gdle2QPY; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf13.hostedemail.com: domain of kent.overstreet@gmail.com designates 209.85.219.51 as permitted sender) smtp.mailfrom=kent.overstreet@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655685806; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=HWerF38n5tR4uSTYJFoRyRIOxNHFK081RFLAVt0+9RY=; b=WDOGjRx+lKtAZYbvfbJa9ZhJxjQDGQXUvlc8JL3Oh29YwnE22647AfaV+ll5YKktdfComH zaLzLfnRT/dz4YRiTAVm27NC+723s1Mtj3x3RHk9n8JYIbzOSLzKPquk9P6Oa1Fu05SAtT TTGqsGB6ghtLQJiZ3LQeBrDBNFxQs9s= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655685806; a=rsa-sha256; cv=none; b=f70Qwtnu9bXxg5gmzhkWITNN6CWqTOY/Eh0fNxgE5r8fIljySi4M4R3CrswZWWxIV+ZlAV qntwYGTC7akOvc8JVS8YpsFMr5gJhpcYDnn3kij7vGnLvlxFuQvPfr6/uVTln+L2iQ4HR6 BUf8jmaEE4TWZjYBE/zVmPFCRZXt1ag= X-Rspamd-Queue-Id: E8C5A200AB Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=gdle2QPY; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf13.hostedemail.com: domain of kent.overstreet@gmail.com designates 209.85.219.51 as permitted sender) smtp.mailfrom=kent.overstreet@gmail.com X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: f4u8z6xti5rc5un353ri6igbdg8nwzzs X-HE-Tag: 1655685805-694930 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: - eliminate on-stack buffer in device_node_string - eliminate unnecessary uses of printf_spec, lift format string precision/field width to pointer() Signed-off-by: Kent Overstreet --- lib/vsprintf.c | 73 ++++++++++++++++++++------------------------------ 1 file changed, 29 insertions(+), 44 deletions(-) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 3900f7a1a5..7f47533ed8 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -1988,25 +1988,20 @@ void fwnode_full_name_string(struct printbuf *out, static noinline_for_stack void device_node_string(struct printbuf *out, struct device_node *dn, - struct printf_spec spec, const char *fmt) + const char *fmt) { - char tbuf[sizeof("xxxx") + 1]; const char *p; int ret; - unsigned start = out->pos; struct property *prop; bool has_mult, pass; - struct printf_spec str_spec = spec; - str_spec.field_width = -1; - if (fmt[0] != 'F') - return error_string_spec(out, "(%pO?)", spec); + return error_string(out, "(%pO?)"); if (!IS_ENABLED(CONFIG_OF)) - return error_string_spec(out, "(%pOF?)", spec); + return error_string(out, "(%pOF?)"); - if (check_pointer_spec(out, dn, spec)) + if (check_pointer(out, dn)) return; /* simple case without anything any more format specifiers */ @@ -2015,7 +2010,6 @@ void device_node_string(struct printbuf *out, struct device_node *dn, fmt = "f"; for (pass = false; strspn(fmt,"fnpPFcC"); fmt++, pass = true) { - int precision; if (pass) prt_char(out, ':'); @@ -2023,43 +2017,41 @@ void device_node_string(struct printbuf *out, struct device_node *dn, case 'f': /* full_name */ fwnode_full_name_string(out, of_fwnode_handle(dn)); break; - case 'n': /* name */ - p = fwnode_get_name(of_fwnode_handle(dn)); - precision = str_spec.precision; - str_spec.precision = strchrnul(p, '@') - p; - string_spec(out, p, str_spec); - str_spec.precision = precision; + case 'n': { /* name */ + const char *name = fwnode_get_name(of_fwnode_handle(dn)); + unsigned len = strchrnul(name, '@') - name; + + prt_bytes(out, name, len); break; + } case 'p': /* phandle */ - prt_u64(out, (unsigned int)dn->phandle); + prt_u64(out, dn->phandle); break; case 'P': /* path-spec */ p = fwnode_get_name(of_fwnode_handle(dn)); if (!p[1]) p = "/"; - string_spec(out, p, str_spec); + string(out, p); break; case 'F': /* flags */ - tbuf[0] = of_node_check_flag(dn, OF_DYNAMIC) ? 'D' : '-'; - tbuf[1] = of_node_check_flag(dn, OF_DETACHED) ? 'd' : '-'; - tbuf[2] = of_node_check_flag(dn, OF_POPULATED) ? 'P' : '-'; - tbuf[3] = of_node_check_flag(dn, OF_POPULATED_BUS) ? 'B' : '-'; - tbuf[4] = 0; - string_nocheck(out, tbuf, str_spec); + prt_char(out, of_node_check_flag(dn, OF_DYNAMIC) ? 'D' : '-'); + prt_char(out, of_node_check_flag(dn, OF_DETACHED) ? 'd' : '-'); + prt_char(out, of_node_check_flag(dn, OF_POPULATED) ? 'P' : '-'); + prt_char(out, of_node_check_flag(dn, OF_POPULATED_BUS) ? 'B' : '-'); break; case 'c': /* major compatible string_spec */ ret = of_property_read_string(dn, "compatible", &p); if (!ret) - string_spec(out, p, str_spec); + string(out, p); break; case 'C': /* full compatible string_spec */ has_mult = false; of_property_for_each_string(dn, "compatible", prop, p) { if (has_mult) - string_nocheck(out, ",", str_spec); - string_nocheck(out, "\"", str_spec); - string_spec(out, p, str_spec); - string_nocheck(out, "\"", str_spec); + prt_char(out, ','); + prt_char(out, '\"'); + string(out, p); + prt_char(out, '\"'); has_mult = true; } @@ -2068,39 +2060,30 @@ void device_node_string(struct printbuf *out, struct device_node *dn, break; } } - - widen_string(out, out->pos - start, spec); } static noinline_for_stack void fwnode_string(struct printbuf *out, struct fwnode_handle *fwnode, - struct printf_spec spec, const char *fmt) + const char *fmt) { - struct printf_spec str_spec = spec; - unsigned start = out->pos; - - str_spec.field_width = -1; - if (*fmt != 'w') - return error_string_spec(out, "(%pf?)", spec); + return error_string(out, "(%pf?)"); - if (check_pointer_spec(out, fwnode, spec)) + if (check_pointer(out, fwnode)) return; fmt++; switch (*fmt) { case 'P': /* name */ - string_spec(out, fwnode_get_name(fwnode), str_spec); + string(out, fwnode_get_name(fwnode)); break; case 'f': /* full_name */ default: fwnode_full_name_string(out, fwnode); break; } - - widen_string(out, out->pos - start, spec); } int __init no_hash_pointers_enable(char *str) @@ -2338,9 +2321,11 @@ void pointer(struct printbuf *out, const char *fmt, flags_string(out, ptr, fmt); return do_width_precision(out, prev_pos, spec); case 'O': - return device_node_string(out, ptr, spec, fmt + 1); + device_node_string(out, ptr, fmt + 1); + return do_width_precision(out, prev_pos, spec); case 'f': - return fwnode_string(out, ptr, spec, fmt + 1); + fwnode_string(out, ptr, fmt + 1); + return do_width_precision(out, prev_pos, spec); case 'x': return pointer_string(out, ptr, spec); case 'e':