From patchwork Fri Apr 23 01:15:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florent Revest X-Patchwork-Id: 12219351 X-Patchwork-Delegate: bpf@iogearbox.net 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=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 79104C433ED for ; Fri, 23 Apr 2021 01:15:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 47BDE6144D for ; Fri, 23 Apr 2021 01:15:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240107AbhDWBQA (ORCPT ); Thu, 22 Apr 2021 21:16:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231261AbhDWBP7 (ORCPT ); Thu, 22 Apr 2021 21:15:59 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DCBDC061756 for ; Thu, 22 Apr 2021 18:15:23 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id o21-20020a1c4d150000b029012e52898006so358288wmh.0 for ; Thu, 22 Apr 2021 18:15:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=H2iyahBHzOh1s1/2DDrTt76XfDUplpwYz1B02Q5JMG8=; b=QrGJ0WbTFOBeAA0exsEZvLpywew49OqEUPMbWHqiq14wL85spVThPTXWeaYkYKMpts RfbDhHvxCNv4cYMQpl9b2zqU3uwWhlFbsLsW33fVvAgT1OGg8+NStrYdS4o6hqs0aJF2 tp1ajTlsBTrgKM4I7KPzjseDw7I2SS4MNO0fw= 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:mime-version:content-transfer-encoding; bh=H2iyahBHzOh1s1/2DDrTt76XfDUplpwYz1B02Q5JMG8=; b=TQMJcnJdypfz7Lxw1u2pktBGmpONwovnx2qic255zNvFjZ/iuVIxvcVJIHH49UIqE2 ALkc+YspuPAWACm/57H90hfSa1Gbtw5auVvr79/Ny8wKGhiIWnIE95oX4JLXfLqp40K3 7M2ZEaLbB+Ym/o/hCtO5m9uTMoYyj6g+AzPoAJgz4xqUxVnJbkI5uevO8QRbx8S3nwUa biJsgDVR25x+uokBP+/ZgIJQbR/eo7VZoUPgbXq7u32tsnvb1/2MZO44IbWbmac0ONwe CkbyXOIdF5DP9+RZTpBIlqTagoJZAswto8xQX6FQjEteGTX/ZSVT+Uw4MIEjkYmTKQVc d4DQ== X-Gm-Message-State: AOAM530ZWIngnBABjLDT2j2ijHwGu2lyx8TD/MrE9j1V4zhS9NRJ1Vzq M5uHVPGMnoF3qviyjBp18Ks9Ku+vJ7dHYg== X-Google-Smtp-Source: ABdhPJykgMyRqYka02II3MnpOSqLN9awuNage0XpfEWrRk2h6Gk1EU5+x87de9PYTdQM+a5iqIP8nQ== X-Received: by 2002:a7b:c5c8:: with SMTP id n8mr1549439wmk.2.1619140521519; Thu, 22 Apr 2021 18:15:21 -0700 (PDT) Received: from revest.zrh.corp.google.com ([2a00:79e0:61:302:e4b7:67ca:7609:a533]) by smtp.gmail.com with ESMTPSA id a13sm6709340wrs.78.2021.04.22.18.15.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Apr 2021 18:15:21 -0700 (PDT) From: Florent Revest To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kpsingh@kernel.org, jackmanb@google.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, Florent Revest Subject: [PATCH bpf-next 1/2] seq_file: Add a seq_bprintf function Date: Fri, 23 Apr 2021 03:15:16 +0200 Message-Id: <20210423011517.4069221-2-revest@chromium.org> X-Mailer: git-send-email 2.31.1.498.g6c1eba8ee3d-goog In-Reply-To: <20210423011517.4069221-1-revest@chromium.org> References: <20210423011517.4069221-1-revest@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Similarly to seq_buf_bprintf in lib/seq_buf.c, this function writes a printf formatted string with arguments provided in a "binary representation" built by functions such as vbin_printf. Signed-off-by: Florent Revest --- fs/seq_file.c | 18 ++++++++++++++++++ include/linux/seq_file.h | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/fs/seq_file.c b/fs/seq_file.c index cb11a34fb871..5059248f2d64 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c @@ -412,6 +412,24 @@ void seq_printf(struct seq_file *m, const char *f, ...) } EXPORT_SYMBOL(seq_printf); +#ifdef CONFIG_BINARY_PRINTF +void seq_bprintf(struct seq_file *m, const char *f, const u32 *binary) +{ + int len; + + if (m->count < m->size) { + len = bstr_printf(m->buf + m->count, m->size - m->count, f, + binary); + if (m->count + len < m->size) { + m->count += len; + return; + } + } + seq_set_overflow(m); +} +EXPORT_SYMBOL(seq_bprintf); +#endif /* CONFIG_BINARY_PRINTF */ + /** * mangle_path - mangle and copy path to buffer beginning * @s: buffer start diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h index b83b3ae3c877..723b1fa1177e 100644 --- a/include/linux/seq_file.h +++ b/include/linux/seq_file.h @@ -146,6 +146,10 @@ void *__seq_open_private(struct file *, const struct seq_operations *, int); int seq_open_private(struct file *, const struct seq_operations *, int); int seq_release_private(struct inode *, struct file *); +#ifdef CONFIG_BINARY_PRINTF +void seq_bprintf(struct seq_file *m, const char *f, const u32 *binary); +#endif + #define DEFINE_SEQ_ATTRIBUTE(__name) \ static int __name ## _open(struct inode *inode, struct file *file) \ { \