From patchwork Tue Feb 24 16:27:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 5873971 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3073ABF440 for ; Tue, 24 Feb 2015 16:27:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5E2F9201CE for ; Tue, 24 Feb 2015 16:27:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6BC5720154 for ; Tue, 24 Feb 2015 16:27:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752970AbbBXQ1k (ORCPT ); Tue, 24 Feb 2015 11:27:40 -0500 Received: from mail-la0-f47.google.com ([209.85.215.47]:36138 "EHLO mail-la0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752821AbbBXQ1j (ORCPT ); Tue, 24 Feb 2015 11:27:39 -0500 Received: by labgq15 with SMTP id gq15so27017370lab.3 for ; Tue, 24 Feb 2015 08:27:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id; bh=7ukpOQJTOHmFVt/Uc4KRYZamV+Wt+5dgLpZ6kmthoxI=; b=eqMU9pEPwFvI1A54cGSBEidHUHcZVzLk3mOtK2bSAdm6VwuEkHPf/lSk8Nh2Lafpju GW4zBKqa8/NLG7Sxcz0oNyI+OO/uiT7p8o+BALbLbIWsJLTH+PvT95dslmGV6g7tQsU7 Su6t7Re1EjhPCtWK7LOQiZWfcnBIX0y60s3JY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=7ukpOQJTOHmFVt/Uc4KRYZamV+Wt+5dgLpZ6kmthoxI=; b=aJXBux+rhJcJmdMP9yJYJ45cBqI8cpxPvkDEVB4zkedXdLN51kd1gqlWX4oPivNi71 6fCOX+V7zcYWUWAw3rzpzzLhyt5fPh/uqOaT9ZgklHIv/BqhY4p93F+jNf+OHY5Frcyn xG6zU870cYdsjKnKpUqpI5HkMar65ODJQLJPU8nx10TV4+TBvrrPAFeMvPXawMO5GoJM K3vQN+0o4Ql8oAeG9FsgS1qFdMxyoYnXdE4Bk/fpLwZpB2hIw72JefENqOxcinDNWBna sAT0Y8IuvDfARYId9X6QfKIUQ4vu68r96+LlKETMtaiM4jlRyN0pSxmrPoUq3Ta5ZIzx N+NQ== X-Gm-Message-State: ALoCoQmHp0quGojg/HduT2L+lm8B/JGlHour7F7RH0/suzyi8clPPa48SlFM58QXeTR812r9i4sA X-Received: by 10.152.219.2 with SMTP id pk2mr14836538lac.107.1424795257965; Tue, 24 Feb 2015 08:27:37 -0800 (PST) Received: from spencer.imf.au.dk ([130.225.20.51]) by mx.google.com with ESMTPSA id i13sm7224207lab.38.2015.02.24.08.27.36 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Feb 2015 08:27:37 -0800 (PST) From: Rasmus Villemoes To: Alexander Viro Cc: Rasmus Villemoes , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] binfmt_misc: simplify entry_status() Date: Tue, 24 Feb 2015 17:27:27 +0100 Message-Id: <1424795247-2282-1-git-send-email-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.1.3 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(). Signed-off-by: Rasmus Villemoes --- fs/binfmt_misc.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c index 97aff2879cda..34de9ca78ced 100644 --- a/fs/binfmt_misc.c +++ b/fs/binfmt_misc.c @@ -24,6 +24,7 @@ #include #include #include +#include #ifdef DEBUG # define USE_DEBUG 1 @@ -521,9 +522,8 @@ static int parse_command(const char __user *buffer, size_t count) static void entry_status(Node *e, char *page) { - char *dp; - char *status = "disabled"; - const char *flags = "flags: "; + char *dp = page; + const char *status = "disabled"; if (test_bit(Enabled, &e->flags)) status = "enabled"; @@ -533,12 +533,10 @@ static void entry_status(Node *e, char *page) return; } - sprintf(page, "%s\ninterpreter %s\n", status, e->interpreter); - dp = page + strlen(page); + dp += sprintf(dp, "%s\ninterpreter %s\n", status, e->interpreter); /* print the special flags */ - sprintf(dp, "%s", flags); - dp += strlen(flags); + dp += sprintf(dp, "flags: "); if (e->flags & MISC_FMT_PRESERVE_ARGV0) *dp++ = 'P'; 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)) { sprintf(dp, "extension .%s\n", e->magic); } else { - int i; - - 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; - } + dp += sprintf(dp, "offset %i\nmagic ", e->offset); + dp = bin2hex(dp, e->magic, e->size); if (e->mask) { - sprintf(dp, "\nmask "); - dp += 6; - for (i = 0; i < e->size; i++) { - sprintf(dp, "%02x", 0xff & (int) (e->mask[i])); - dp += 2; - } + dp += sprintf(dp, "\nmask "); + dp = bin2hex(dp, e->mask, e->size); } *dp++ = '\n'; *dp = '\0';