Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1275877 > unrolled thread
| Started by | Rasmus Villemoes <linux@rasmusvillemoes.dk> |
|---|---|
| First post | 2015-11-23 22:40 +0100 |
| Last post | 2015-11-26 22:50 +0100 |
| Articles | 3 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH 01/14] lib/vsprintf.c: pull out padding code from dentry_name() Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-11-23 22:40 +0100
Re: [PATCH 01/14] lib/vsprintf.c: pull out padding code from dentry_name() Andy Shevchenko <andy.shevchenko@gmail.com> - 2015-11-24 00:00 +0100
Re: [PATCH 01/14] lib/vsprintf.c: pull out padding code from dentry_name() Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-11-26 22:50 +0100
| From | Rasmus Villemoes <linux@rasmusvillemoes.dk> |
|---|---|
| Date | 2015-11-23 22:40 +0100 |
| Subject | [PATCH 01/14] lib/vsprintf.c: pull out padding code from dentry_name() |
| Message-ID | <qy705-7p3-3@gated-at.bofh.it> |
Pull out the logic in dentry_name() which handles field width space
padding, in preparation for reusing it from string(). Rename the
widen() helper to move_right(), since it is used for handling the
!(flags & LEFT) case.
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
lib/vsprintf.c | 46 +++++++++++++++++++++++++++++++---------------
1 file changed, 31 insertions(+), 15 deletions(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index f9cee8e1233c..d7452563a6a6 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -538,7 +538,7 @@ char *string(char *buf, char *end, const char *s, struct printf_spec spec)
return buf;
}
-static void widen(char *buf, char *end, unsigned len, unsigned spaces)
+static void move_right(char *buf, char *end, unsigned len, unsigned spaces)
{
size_t size;
if (buf >= end) /* nowhere to put anything */
@@ -556,6 +556,35 @@ static void widen(char *buf, char *end, unsigned len, unsigned spaces)
memset(buf, ' ', spaces);
}
+/*
+ * Handle field width padding for a string.
+ * @buf: current buffer position
+ * @n: length of string
+ * @end: end of output buffer
+ * @spec: for field width and flags
+ * Returns: new buffer position after padding.
+ */
+static noinline_for_stack
+char *widen_string(char *buf, int n, char *end, struct printf_spec spec)
+{
+ unsigned spaces;
+
+ if (likely(n >= spec.field_width))
+ return buf;
+ /* we want to pad the sucker */
+ spaces = spec.field_width - n;
+ if (!(spec.flags & LEFT)) {
+ move_right(buf - n, end, n, spaces);
+ return buf + spaces;
+ }
+ while (spaces--) {
+ if (buf < end)
+ *buf = ' ';
+ ++buf;
+ }
+ return buf;
+}
+
static noinline_for_stack
char *dentry_name(char *buf, char *end, const struct dentry *d, struct printf_spec spec,
const char *fmt)
@@ -597,20 +626,7 @@ char *dentry_name(char *buf, char *end, const struct dentry *d, struct printf_sp
*buf = c;
}
rcu_read_unlock();
- if (n < spec.field_width) {
- /* we want to pad the sucker */
- unsigned spaces = spec.field_width - n;
- if (!(spec.flags & LEFT)) {
- widen(buf - n, end, n, spaces);
- return buf + spaces;
- }
- while (spaces--) {
- if (buf < end)
- *buf = ' ';
- ++buf;
- }
- }
- return buf;
+ return widen_string(buf, n, end, spec);
}
static noinline_for_stack
--
2.6.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Andy Shevchenko <andy.shevchenko@gmail.com> |
|---|---|
| Date | 2015-11-24 00:00 +0100 |
| Message-ID | <qy8fv-89o-7@gated-at.bofh.it> |
| In reply to | #1275877 |
On Mon, Nov 23, 2015 at 11:29 PM, Rasmus Villemoes
<linux@rasmusvillemoes.dk> wrote:
> Pull out the logic in dentry_name() which handles field width space
> padding, in preparation for reusing it from string(). Rename the
> widen() helper to move_right(), since it is used for handling the
> !(flags & LEFT) case.
>
> Cc: Al Viro <viro@ZenIV.linux.org.uk>
> Cc: Ingo Molnar <mingo@kernel.org>
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> ---
> lib/vsprintf.c | 46 +++++++++++++++++++++++++++++++---------------
> 1 file changed, 31 insertions(+), 15 deletions(-)
>
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index f9cee8e1233c..d7452563a6a6 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -538,7 +538,7 @@ char *string(char *buf, char *end, const char *s, struct printf_spec spec)
> return buf;
> }
>
> -static void widen(char *buf, char *end, unsigned len, unsigned spaces)
> +static void move_right(char *buf, char *end, unsigned len, unsigned spaces)
> {
> size_t size;
> if (buf >= end) /* nowhere to put anything */
> @@ -556,6 +556,35 @@ static void widen(char *buf, char *end, unsigned len, unsigned spaces)
> memset(buf, ' ', spaces);
> }
>
> +/*
Perhaps /**
> + * Handle field width padding for a string.
> + * @buf: current buffer position
> + * @n: length of string
> + * @end: end of output buffer
> + * @spec: for field width and flags
> + * Returns: new buffer position after padding.
> + */
> +static noinline_for_stack
> +char *widen_string(char *buf, int n, char *end, struct printf_spec spec)
> +{
> + unsigned spaces;
> +
> + if (likely(n >= spec.field_width))
> + return buf;
> + /* we want to pad the sucker */
> + spaces = spec.field_width - n;
> + if (!(spec.flags & LEFT)) {
> + move_right(buf - n, end, n, spaces);
> + return buf + spaces;
> + }
> + while (spaces--) {
> + if (buf < end)
> + *buf = ' ';
> + ++buf;
> + }
> + return buf;
> +}
> +
> static noinline_for_stack
> char *dentry_name(char *buf, char *end, const struct dentry *d, struct printf_spec spec,
> const char *fmt)
> @@ -597,20 +626,7 @@ char *dentry_name(char *buf, char *end, const struct dentry *d, struct printf_sp
> *buf = c;
> }
> rcu_read_unlock();
> - if (n < spec.field_width) {
> - /* we want to pad the sucker */
> - unsigned spaces = spec.field_width - n;
> - if (!(spec.flags & LEFT)) {
> - widen(buf - n, end, n, spaces);
> - return buf + spaces;
> - }
> - while (spaces--) {
> - if (buf < end)
> - *buf = ' ';
> - ++buf;
> - }
> - }
> - return buf;
> + return widen_string(buf, n, end, spec);
> }
>
> static noinline_for_stack
> --
> 2.6.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
--
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Rasmus Villemoes <linux@rasmusvillemoes.dk> |
|---|---|
| Date | 2015-11-26 22:50 +0100 |
| Message-ID | <qzcAq-2gR-23@gated-at.bofh.it> |
| In reply to | #1275942 |
On Mon, Nov 23 2015, Andy Shevchenko <andy.shevchenko@gmail.com> wrote:
> On Mon, Nov 23, 2015 at 11:29 PM, Rasmus Villemoes
> <linux@rasmusvillemoes.dk> wrote:
>> Pull out the logic in dentry_name() which handles field width space
>> padding, in preparation for reusing it from string(). Rename the
>> widen() helper to move_right(), since it is used for handling the
>> !(flags & LEFT) case.
>>
>> Cc: Al Viro <viro@ZenIV.linux.org.uk>
>> Cc: Ingo Molnar <mingo@kernel.org>
>> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
>>
>> -static void widen(char *buf, char *end, unsigned len, unsigned spaces)
>> +static void move_right(char *buf, char *end, unsigned len, unsigned spaces)
>> {
>> size_t size;
>> if (buf >= end) /* nowhere to put anything */
>> @@ -556,6 +556,35 @@ static void widen(char *buf, char *end, unsigned len, unsigned spaces)
>> memset(buf, ' ', spaces);
>> }
>>
>> +/*
>
> Perhaps /**
Nah, it's not an exported function, so I didn't want to do a formal
kernel-doc thing. I can make it proper kernel-doc if you insist, but I
don't think the whole "current buffer position", "end of output
buffer", "new buffer position" makes sense outside the context of
vsprintf.c with its own slightly peculiar way of doing things.
>> + * Handle field width padding for a string.
>> + * @buf: current buffer position
>> + * @n: length of string
>> + * @end: end of output buffer
>> + * @spec: for field width and flags
>> + * Returns: new buffer position after padding.
>> + */
>> +static noinline_for_stack
>> +char *widen_string(char *buf, int n, char *end, struct printf_spec spec)
>> +{
Rasmus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web