fs/binfmt_misc.c: simplify entry_status()

sprintf() reliably returns the number of characters printed, so we don't
need to ask strlen() where we are.  Also replace calling sprintf("%02x")
in a loop with the much simpler bin2hex().

[akpm@linux-foundation.org: it's odd to include kernel.h after everything else]
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Rasmus Villemoes 2015-04-16 12:44:56 -07:00 коммит произвёл Linus Torvalds
Родитель e0df7e1fae
Коммит 6ceafb880c
1 изменённых файлов: 9 добавлений и 21 удалений

Просмотреть файл

@ -9,6 +9,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/sched.h> #include <linux/sched.h>
@ -521,9 +522,8 @@ static int parse_command(const char __user *buffer, size_t count)
static void entry_status(Node *e, char *page) static void entry_status(Node *e, char *page)
{ {
char *dp; char *dp = page;
char *status = "disabled"; const char *status = "disabled";
const char *flags = "flags: ";
if (test_bit(Enabled, &e->flags)) if (test_bit(Enabled, &e->flags))
status = "enabled"; status = "enabled";
@ -533,12 +533,10 @@ static void entry_status(Node *e, char *page)
return; return;
} }
sprintf(page, "%s\ninterpreter %s\n", status, e->interpreter); dp += sprintf(dp, "%s\ninterpreter %s\n", status, e->interpreter);
dp = page + strlen(page);
/* print the special flags */ /* print the special flags */
sprintf(dp, "%s", flags); dp += sprintf(dp, "flags: ");
dp += strlen(flags);
if (e->flags & MISC_FMT_PRESERVE_ARGV0) if (e->flags & MISC_FMT_PRESERVE_ARGV0)
*dp++ = 'P'; *dp++ = 'P';
if (e->flags & MISC_FMT_OPEN_BINARY) if (e->flags & MISC_FMT_OPEN_BINARY)
@ -550,21 +548,11 @@ static void entry_status(Node *e, char *page)
if (!test_bit(Magic, &e->flags)) { if (!test_bit(Magic, &e->flags)) {
sprintf(dp, "extension .%s\n", e->magic); sprintf(dp, "extension .%s\n", e->magic);
} else { } else {
int i; dp += sprintf(dp, "offset %i\nmagic ", e->offset);
dp = bin2hex(dp, e->magic, e->size);
sprintf(dp, "offset %i\nmagic ", e->offset);
dp = page + strlen(page);
for (i = 0; i < e->size; i++) {
sprintf(dp, "%02x", 0xff & (int) (e->magic[i]));
dp += 2;
}
if (e->mask) { if (e->mask) {
sprintf(dp, "\nmask "); dp += sprintf(dp, "\nmask ");
dp += 6; dp = bin2hex(dp, e->mask, e->size);
for (i = 0; i < e->size; i++) {
sprintf(dp, "%02x", 0xff & (int) (e->mask[i]));
dp += 2;
}
} }
*dp++ = '\n'; *dp++ = '\n';
*dp = '\0'; *dp = '\0';