From patchwork Mon Aug 14 16:33:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13353070 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 83792C001DB for ; Mon, 14 Aug 2023 16:27:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 25F8B6B0075; Mon, 14 Aug 2023 12:27:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 210036B0078; Mon, 14 Aug 2023 12:27:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D7B46B007B; Mon, 14 Aug 2023 12:27:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id F38BC6B0075 for ; Mon, 14 Aug 2023 12:27:03 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 60F08140BA0 for ; Mon, 14 Aug 2023 16:27:03 +0000 (UTC) X-FDA: 81123239526.08.AA54507 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by imf04.hostedemail.com (Postfix) with ESMTP id 2BA5A4000E for ; Mon, 14 Aug 2023 16:27:00 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="gzvX/q6a"; spf=none (imf04.hostedemail.com: domain of andriy.shevchenko@linux.intel.com has no SPF policy when checking 134.134.136.100) smtp.mailfrom=andriy.shevchenko@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692030421; 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=aoQdUnUxWu79/wu/ynaQz9sqIF+EP8+qxQ7gq7KmF9k=; b=6GtCklcUDJjsmfmOIM9Kk0KjM7SZXDBpuli4WRhgUHmcUM33lgFPNpbbbffbZmDonHohtn oy0Ri0lIJqT4vuqXZSvN+RmN6fgBFtIi1oPkm023MPOFaDNYDzkNeQ1/gfbjmqTS6CPitw wBDkDE0MQCljh+fPT24UDFupoJ1AvsU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692030421; a=rsa-sha256; cv=none; b=c8bMErpDhyABr1M057R82iskqIcjabohezX0sh+HjiKU7GYrTHjgvQ/xIfqbxagexzU43h S40AhvaOLk/FJUfXvWIdnoexbQi0zKcZwfP78OWA8TPzqN8HeDVf5kGnZhlZI1dGUXO2z9 g5UHFSX8sZqv0y/25tVCt5r2B+53lZA= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="gzvX/q6a"; spf=none (imf04.hostedemail.com: domain of andriy.shevchenko@linux.intel.com has no SPF policy when checking 134.134.136.100) smtp.mailfrom=andriy.shevchenko@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692030421; x=1723566421; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LZQOx7C238eM5ntkHv1oYly7+slLbIPiN9FmjDzt/5w=; b=gzvX/q6alaS/YkdpOQEkOn+XhMhiyNdLUq/SXf2Pr3SDhP7EndgV3Gcq eGzw3Y8hw3/b0GkLs4DEz0ri/Nb2Rx/ExHKUby7L2A8cwBxrkELFf/n9o 3g/G2i79E1BqlcRuRRg38eMx897QThi6ci5QBD6AqhgvLmIGinavQlb+t pf350EsCHVaJdtxFaoKvSPFUiVzonNfPgqLhUE3uhxQq5CfYjh72b97yA YLBHRFIz0QwiM4KE5UcFXXBxPjmiyfPNlyDtvi2qOjtFMrigfz8SegZiy MB6srWJ8cww1CD/U92Mp+aYDPl8d5yd1vGzuMUv7ZLZJyJ0lQ65W63FTP A==; X-IronPort-AV: E=McAfee;i="6600,9927,10802"; a="438415051" X-IronPort-AV: E=Sophos;i="6.01,173,1684825200"; d="scan'208";a="438415051" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2023 09:26:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10802"; a="736565824" X-IronPort-AV: E=Sophos;i="6.01,173,1684825200"; d="scan'208";a="736565824" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga007.fm.intel.com with ESMTP; 14 Aug 2023 09:26:19 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 62A54370; Mon, 14 Aug 2023 19:33:48 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Petr Mladek , Marco Elver , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Cc: Steven Rostedt , Rasmus Villemoes , Sergey Senozhatsky , Alexander Potapenko , Dmitry Vyukov , Andrew Morton Subject: [PATCH v3 1/2] lib/vsprintf: Split out sprintf() and friends Date: Mon, 14 Aug 2023 19:33:43 +0300 Message-Id: <20230814163344.17429-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230814163344.17429-1-andriy.shevchenko@linux.intel.com> References: <20230814163344.17429-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 2BA5A4000E X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: waoxxkpsg4wtt4o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hRC5omYKJRza/BlvlGZVRy63IRXNwkbvux+fsLHZiCOia00ai4ob+0/ja5VLVUBX1pGi30WwLqtuSEiA3OMiiARVpViCQ= 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: kernel.h is being used as a dump for all kinds of stuff for a long time. sprintf() and friends are used in many drivers without need of the full kernel.h dependency train with it. Here is the attempt on cleaning it up by splitting out sprintf() and friends. Signed-off-by: Andy Shevchenko Reviewed-by: Petr Mladek --- include/linux/kernel.h | 30 +----------------------------- include/linux/sprintf.h | 25 +++++++++++++++++++++++++ lib/test_printf.c | 1 + lib/vsprintf.c | 1 + 4 files changed, 28 insertions(+), 29 deletions(-) create mode 100644 include/linux/sprintf.h diff --git a/include/linux/kernel.h b/include/linux/kernel.h index b9e76f717a7e..cee8fe87e9f4 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -203,35 +204,6 @@ static inline void might_fault(void) { } void do_exit(long error_code) __noreturn; -extern int num_to_str(char *buf, int size, - unsigned long long num, unsigned int width); - -/* lib/printf utilities */ - -extern __printf(2, 3) int sprintf(char *buf, const char * fmt, ...); -extern __printf(2, 0) int vsprintf(char *buf, const char *, va_list); -extern __printf(3, 4) -int snprintf(char *buf, size_t size, const char *fmt, ...); -extern __printf(3, 0) -int vsnprintf(char *buf, size_t size, const char *fmt, va_list args); -extern __printf(3, 4) -int scnprintf(char *buf, size_t size, const char *fmt, ...); -extern __printf(3, 0) -int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); -extern __printf(2, 3) __malloc -char *kasprintf(gfp_t gfp, const char *fmt, ...); -extern __printf(2, 0) __malloc -char *kvasprintf(gfp_t gfp, const char *fmt, va_list args); -extern __printf(2, 0) -const char *kvasprintf_const(gfp_t gfp, const char *fmt, va_list args); - -extern __scanf(2, 3) -int sscanf(const char *, const char *, ...); -extern __scanf(2, 0) -int vsscanf(const char *, const char *, va_list); - -extern int no_hash_pointers_enable(char *str); - extern int get_option(char **str, int *pint); extern char *get_options(const char *str, int nints, int *ints); extern unsigned long long memparse(const char *ptr, char **retptr); diff --git a/include/linux/sprintf.h b/include/linux/sprintf.h new file mode 100644 index 000000000000..9ca23bcf9f42 --- /dev/null +++ b/include/linux/sprintf.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_KERNEL_SPRINTF_H_ +#define _LINUX_KERNEL_SPRINTF_H_ + +#include +#include + +int num_to_str(char *buf, int size, unsigned long long num, unsigned int width); + +__printf(2, 3) int sprintf(char *buf, const char * fmt, ...); +__printf(2, 0) int vsprintf(char *buf, const char *, va_list); +__printf(3, 4) int snprintf(char *buf, size_t size, const char *fmt, ...); +__printf(3, 0) int vsnprintf(char *buf, size_t size, const char *fmt, va_list args); +__printf(3, 4) int scnprintf(char *buf, size_t size, const char *fmt, ...); +__printf(3, 0) int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); +__printf(2, 3) __malloc char *kasprintf(gfp_t gfp, const char *fmt, ...); +__printf(2, 0) __malloc char *kvasprintf(gfp_t gfp, const char *fmt, va_list args); +__printf(2, 0) const char *kvasprintf_const(gfp_t gfp, const char *fmt, va_list args); + +__scanf(2, 3) int sscanf(const char *, const char *, ...); +__scanf(2, 0) int vsscanf(const char *, const char *, va_list); + +int no_hash_pointers_enable(char *str); + +#endif /* _LINUX_KERNEL_SPRINTF_H */ diff --git a/lib/test_printf.c b/lib/test_printf.c index 7677ebccf3c3..ce749cfac033 100644 --- a/lib/test_printf.c +++ b/lib/test_printf.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 40f560959b16..afb88b24fa74 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include