All of lore.kernel.org
 help / color / mirror / Atom feed
* + lib-introduce-simple-error-checking-wrapper-for-memparse.patch added to mm-nonmm-unstable branch
@ 2026-01-08 17:42 Andrew Morton
  0 siblings, 0 replies; only message in thread
From: Andrew Morton @ 2026-01-08 17:42 UTC (permalink / raw)
  To: mm-commits, kees, hch, cem, andy, dmantipov, akpm


The patch titled
     Subject: lib: introduce simple error-checking wrapper for memparse()
has been added to the -mm mm-nonmm-unstable branch.  Its filename is
     lib-introduce-simple-error-checking-wrapper-for-memparse.patch

This patch will shortly appear at
     https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/lib-introduce-simple-error-checking-wrapper-for-memparse.patch

This patch will later appear in the mm-nonmm-unstable branch at
    git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days

------------------------------------------------------
From: Dmitry Antipov <dmantipov@yandex.ru>
Subject: lib: introduce simple error-checking wrapper for memparse()
Date: Thu, 8 Jan 2026 19:52:15 +0300

Introduce 'memvalue()' which uses 'memparse()' to parse a string with
optional memory suffix into a non-negative number.  If parsing has
succeeded, returns 0 and stores the result at the location specified by
the second argument.  Otherwise returns -EINVAL and leaves the location
untouched.

Link: https://lkml.kernel.org/r/20260108165216.1054625-1-dmantipov@yandex.ru
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
Suggested-by: Christoph Hellwig <hch@infradead.org>
Suggested-by: Kees Cook <kees@kernel.org>
Reviewed-by: Kees Cook <kees@kernel.org>
Cc: Andy Shevchenko <andy@kernel.org>
Cc: Carlos Maiolino <cem@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 include/linux/string.h |    1 +
 lib/cmdline.c          |   26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+)

--- a/include/linux/string.h~lib-introduce-simple-error-checking-wrapper-for-memparse
+++ a/include/linux/string.h
@@ -319,6 +319,7 @@ DEFINE_FREE(argv_free, char **, if (!IS_
 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);
+extern int __must_check memvalue(const char *ptr, unsigned long long *valptr);
 extern bool parse_option_str(const char *str, const char *option);
 extern char *next_arg(char *args, char **param, char **val);
 
--- a/lib/cmdline.c~lib-introduce-simple-error-checking-wrapper-for-memparse
+++ a/lib/cmdline.c
@@ -191,6 +191,32 @@ unsigned long long memparse(const char *
 EXPORT_SYMBOL(memparse);
 
 /**
+ *	memvalue -  Wrap memparse() with simple error detection
+ *	@ptr: Where parse begins
+ *	@valptr: Where to store result
+ *
+ *	Unconditionally returns -EINVAL for a presumably negative value.
+ *	Otherwise uses memparse() to parse a string into a number stored
+ *	at @valptr and returns 0 or -EINVAL if an unrecognized character
+ *	was encountered. For a non-zero return value, memory at @valptr
+ *	is left untouched.
+ */
+int __must_check memvalue(const char *ptr, unsigned long long *valptr)
+{
+	unsigned long long ret;
+	char *end;
+
+	if (*ptr == '-')
+		return -EINVAL;
+	ret = memparse(ptr, &end);
+	if (*end)
+		return -EINVAL;
+	*valptr = ret;
+	return 0;
+}
+EXPORT_SYMBOL(memvalue);
+
+/**
  *	parse_option_str - Parse a string and check an option is set or not
  *	@str: String to be parsed
  *	@option: option name
_

Patches currently in -mm which might be from dmantipov@yandex.ru are

ocfs2-adjust-ocfs2_xa_remove_entry-to-match-ubsan-boundary-checks.patch
ocfs2-annotate-more-flexible-array-members-with-__counted_by_le.patch
lib-introduce-simple-error-checking-wrapper-for-memparse.patch
xfs-adjust-handling-of-a-few-numerical-mount-options.patch


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-01-08 17:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-08 17:42 + lib-introduce-simple-error-checking-wrapper-for-memparse.patch added to mm-nonmm-unstable branch Andrew Morton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.