From patchwork Sat Aug 5 17:50:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13342643 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 0D3AFC41513 for ; Sat, 5 Aug 2023 17:49:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 64F388D0001; Sat, 5 Aug 2023 13:49:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 58EAF8D0005; Sat, 5 Aug 2023 13:49:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3DC388D0002; Sat, 5 Aug 2023 13:49:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1F8FF8D0002 for ; Sat, 5 Aug 2023 13:49:36 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id ECB17401CD for ; Sat, 5 Aug 2023 17:49:35 +0000 (UTC) X-FDA: 81090788310.26.D37E435 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by imf06.hostedemail.com (Postfix) with ESMTP id 7E2C018000D for ; Sat, 5 Aug 2023 17:49:33 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=jSSlHpr0; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf06.hostedemail.com: domain of andriy.shevchenko@linux.intel.com has no SPF policy when checking 192.55.52.151) smtp.mailfrom=andriy.shevchenko@linux.intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691257774; 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=APFaLpzRvkmsd23+nAQve4IWVf1KVk54bqCwJXd8ZvA=; b=7bUN/DirO0zKkAWA5f7z3mEw3uNadg2L3qeyfm5i91DIhjgDCK/ah9SDpuMRddJfzhxCAG D3qXqIPqQ5usNr94LfEoz25QpzM4lBV5/bXDf38NcLqQqLLvK4FZajjbMeGRo8965pROIO ZR8E1av2af3ptZ1RRY7W+mabBcDvx+8= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=jSSlHpr0; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf06.hostedemail.com: domain of andriy.shevchenko@linux.intel.com has no SPF policy when checking 192.55.52.151) smtp.mailfrom=andriy.shevchenko@linux.intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691257774; a=rsa-sha256; cv=none; b=lTgoN3+gJBLhhL2VFDT60BaL2tjCfl+FCeZ1MdNoP2LNwfE8n5bF/M30PxXCuh4G4T3vma md7GtcknJMjl4FvfsPF8m45yr7FEtQPLBra6ehub6ovVJyevujfuA15OaJWWiay8N33SBq 2uAlPnnBCHwapwC+CgGejNELirltbvY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1691257773; x=1722793773; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WwFlBTMWGP/2Noo8uToUlcYjMLDc5ySAvwUDql7sE7Y=; b=jSSlHpr0/OCujrrizHhDJhBToIyd21sKfSVutUtNPSE0/l/3B+bR+exE 4whM9u5wiAH3VnMOgmemvGQ1TvtiDmrnM+7I/sN3v3dgv+1Quqwvs1rZ9 YABD0f29u64nOQJ3O3IJAgM32kHttyRjJ4igsXeQKU1RrsH34nXr0+BjD 08hB6d9oksUMY/mHWV6Lj7bP+yPip40TPje/wtmHS3Fp8d0pQXvFfd8ny 5mn1iLWQjwyH7dRQmRznk6eRXrNrUN39nBBysIQcN2k5fqTkBeSURa0Fd 3WoDfCEKYYZRhyNbZgBAZMAEKilaDe2Rnx5HVZFpHqbr4xLYpAYhGNELS A==; X-IronPort-AV: E=McAfee;i="6600,9927,10793"; a="350638995" X-IronPort-AV: E=Sophos;i="6.01,258,1684825200"; d="scan'208";a="350638995" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Aug 2023 10:49:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10793"; a="733622471" X-IronPort-AV: E=Sophos;i="6.01,258,1684825200"; d="scan'208";a="733622471" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga007.fm.intel.com with ESMTP; 05 Aug 2023 10:49:28 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 9F9D5BAB; Sat, 5 Aug 2023 20:50:29 +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 v2 2/3] lib/vsprintf: Split out sprintf() and friends Date: Sat, 5 Aug 2023 20:50:26 +0300 Message-Id: <20230805175027.50029-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230805175027.50029-1-andriy.shevchenko@linux.intel.com> References: <20230805175027.50029-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 7E2C018000D X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 4o83rq8yj6s8ncg1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tWlODH/IatXVGzkCHMnMWhQ+3ieEZvMX2/c4M5XSkt8oTwmT7xTfyUxK01JPS5jfmqrLtzY3gyp5lbVW1fO91TPTqNdLRVXzyzq2//Ho= 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 --- 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 2ab09a0dc841..5adca19d34e2 100644 --- a/lib/test_printf.c +++ b/lib/test_printf.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include "../tools/testing/selftests/kselftest_module.h" diff --git a/lib/vsprintf.c b/lib/vsprintf.c index b17e0744a7bc..c89719586d0c 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include