[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5212E910.7030609@asianux.com>
Date: Tue, 20 Aug 2013 11:57:04 +0800
From: Chen Gang <gang.chen@...anux.com>
To: Mel Gorman <mgorman@...e.de>, kosaki.motohiro@...fujitsu.com,
riel@...hat.com, hughd@...gle.com, xemul@...allels.com,
Cyrill Gorcunov <gorcunov@...nvz.org>, rientjes@...gle.com,
Wanpeng Li <liwanp@...ux.vnet.ibm.com>, hughd@...gle.com
CC: Andrew Morton <akpm@...ux-foundation.org>, linux-mm@...ck.org,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: [PATCH 1/3] mm/mempolicy.c: still fill buffer as full as possible
when buffer space is not enough in mpol_to_str()
Need still try to fill buffer as full as possible if the buffer space
is not enough, commonly, the caller can bear of it (e.g. print warning
and still continue).
Signed-off-by: Chen Gang <gang.chen@...anux.com>
---
mm/mempolicy.c | 14 ++++++++++----
1 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 27022ca..c81b64f 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -2800,6 +2800,8 @@ out:
* Convert a mempolicy into a string.
* Returns the number of characters in buffer (if positive)
* or an error (negative)
+ * If the buffer space is not enough, it will return -ENOSPC,
+ * and try to fill the buffer as full as possible.
*/
int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol)
{
@@ -2842,11 +2844,10 @@ int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol)
return -EINVAL;
}
+ strlcpy(p, policy_modes[mode], maxlen);
l = strlen(policy_modes[mode]);
if (buffer + maxlen < p + l + 1)
return -ENOSPC;
-
- strcpy(p, policy_modes[mode]);
p += l;
if (flags & MPOL_MODE_FLAGS) {
@@ -2857,10 +2858,15 @@ int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol)
/*
* Currently, the only defined flags are mutually exclusive
*/
- if (flags & MPOL_F_STATIC_NODES)
+ if (flags & MPOL_F_STATIC_NODES) {
p += snprintf(p, buffer + maxlen - p, "static");
- else if (flags & MPOL_F_RELATIVE_NODES)
+ if (buffer + maxlen <= p)
+ return -ENOSPC;
+ } else if (flags & MPOL_F_RELATIVE_NODES) {
p += snprintf(p, buffer + maxlen - p, "relative");
+ if (buffer + maxlen <= p)
+ return -ENOSPC;
+ }
}
if (!nodes_empty(nodes)) {
--
1.7.7.6
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists