Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp948561pxy; Thu, 22 Apr 2021 18:16:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1C17NL6tCxnRjBLx9bScg4+9AE8oWAy7K2P2kiSb8VtCpZA54o80OnpL/iQegwZrrTv/1 X-Received: by 2002:a17:906:1a0d:: with SMTP id i13mr1435229ejf.197.1619140596529; Thu, 22 Apr 2021 18:16:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619140596; cv=none; d=google.com; s=arc-20160816; b=qlWJkGqVoH4tRosT4GAN2xLFk72fO9vMeAzN/r5qaTs996EmSLfuM/yY3MXiUwmJri 7wT1OB71ENMfnwuHVtvrVop5NqbcP6z1oa0JEM32CESZjWVzXLVoIMG+6E55a1i+jjzI nW6eTKGzUB8l5o0n48hSjEd0TQqNHb1SZ7VPyOodJqf5AW7hkw/Clp2gltZw+x+k7ezH 9tpauGAzNgg9px0eutXr3NrGCD+ijTt9VcAaYCsopQiViqIYkDuQ+YaGoBMD/njHzsun sCRvxnwsRDAeAFStrNGMle27gwPDCzwa2d90eNTKM8riLx5cpDv+OcEGqeOlbL0CE7Wm tS9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=H2iyahBHzOh1s1/2DDrTt76XfDUplpwYz1B02Q5JMG8=; b=i6wmYVEtRul/Zebs9+TRRkFUWTnCDdk0Ra17O04r+ZcfXQr0DqqCYNlZHQf5uP6V2d IjzBX08greFkCA4QifMmywGnpd0/wiGg44rOd41uc1TtjAggC9zqZOPSkj5W+UV51q4W tqPasfwLD3dhH5cynulh0+XCEi9UKtXw0dHePEo2pYncEVn95R0v3CQb87hWWq1zZM2G jUNintvGH5M5HpTeA+P77IaWslzuthCjBkzIQ/ng1tV9WK40eig56G0VoSw3QazlvT8q BfKmxkA9ANXPFbLUWJSX04qKZZtYZpM0ICQaZV3P9PV0DIL+6s6xpkeh8iHDkJ0Mieyr Xgqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QrGJ0WbT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w11si4026281edc.569.2021.04.22.18.16.12; Thu, 22 Apr 2021 18:16:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QrGJ0WbT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239918AbhDWBP6 (ORCPT + 99 others); Thu, 22 Apr 2021 21:15:58 -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 S231261AbhDWBP6 (ORCPT ); Thu, 22 Apr 2021 21:15:58 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAC96C06174A for ; Thu, 22 Apr 2021 18:15:22 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id w186so20580350wmg.3 for ; Thu, 22 Apr 2021 18:15:22 -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=Ial8iIRvIgHaReTmuC2OdNN/6XKoU2CgQTrqSH/h8NUTcQQ7nwyXQhKx5eP7mFaAiQ T/Lm3cxLt/09SynfRWmzq/kgFAalVUCPTjb5Y7gLk7CSWichRuFbv0HDzTXMJ7rmlGW+ b3xPounymS67M9QrpeO7Nj3RXSiKCQ6TwsNiwI0PbE7EIqucq6tUiauK+4vzfgzf2qu8 eAokJcCo/qlhSWL73UjsSeTfYdmQY+F2TNRZUr4vsKyNR+o3OVBUsh3FnBh3oFmTO7JY o3I0X5pkD26Y3UkmMLU/8PK/LEl5eRygK2/F0QJ50JTumZEsZQ7ct1O60pgF6q0DRmem tdtw== X-Gm-Message-State: AOAM532K84RXpcKRL9FK3bnnkhd5Ua7ZOea4AIE5JNEwZPKQyu/pigcf wzjLf2xZ5Z7T/HY24Kv7kTBcxw== 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) \ { \ -- 2.31.1.498.g6c1eba8ee3d-goog