From patchwork Tue Nov 24 12:33:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 7690111 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@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 D137CBF90C for ; Tue, 24 Nov 2015 12:33:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E3535207D3 for ; Tue, 24 Nov 2015 12:33:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 00380207D0 for ; Tue, 24 Nov 2015 12:33:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753254AbbKXMd4 (ORCPT ); Tue, 24 Nov 2015 07:33:56 -0500 Received: from mail-lf0-f48.google.com ([209.85.215.48]:32826 "EHLO mail-lf0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752966AbbKXMd4 (ORCPT ); Tue, 24 Nov 2015 07:33:56 -0500 Received: by lfaz4 with SMTP id z4so18552596lfa.0 for ; Tue, 24 Nov 2015 04:33:54 -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=+90PiaQcTEd3qDEbfal9mdlmRzCJTB23dHw3+5Sryn4=; b=gUsP1SdyVnjXS65qE2pKyl0gRRVkaKYxsX1T5HQYsfwkxe7gS1SZ4H6qu+GFnc5RUI 13k3QAWu0qU6PA4s/L9Yg8gAhCDD8K/GP8yp2H2O9vLXe1JgeCZvfxqt/eQ7+fTdy8Jg 6rdAF+pccGw9IlGbfc1EcPcLcC/O6ZXT5iq2M= 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=+90PiaQcTEd3qDEbfal9mdlmRzCJTB23dHw3+5Sryn4=; b=iBjZI/6yBFIeV9BKOfyJfE/srqFXaoTJ8ehMT3OaNASLBgA9BMNtRjXSIfJj0ytHzL M15MqOW/V9BKeM4VGRv3SkqJqlTdhEozvwE4RdW2WVuopWmvj/3HJ/viwuTk4+K1TCNu 9IY6ZZzHqh77Gl8TTYf0MsIc70CJTNYe0Adu6hhlaTyRnG1PRdbUBP2Ce/r/3FVu7r+k qW0bnZ2dzGRhdSEMq68yT7hemFee4LyFtL0ygv3rsV1yUjRFBLes5glgnhe8sOUqPrSK /sk4XSKnm9UrNFnyLSrymzDpDTBAxs6zMAHKvBv48rITh3R7T4xTcRhJ2zgrZr1gkbyx ADxw== X-Gm-Message-State: ALoCoQmOt4GxPrmSKEwsoN7Az+fGqNGaTXrIn93TWH+npqfUL6HCRhN1ZgQ289iU9GMm4lLttnD5 X-Received: by 10.25.5.201 with SMTP id 192mr5020376lff.82.1448368434397; Tue, 24 Nov 2015 04:33:54 -0800 (PST) Received: from garcia.imf.au.dk ([130.225.20.51]) by smtp.gmail.com with ESMTPSA id l81sm2392166lfb.40.2015.11.24.04.33.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 24 Nov 2015 04:33:53 -0800 (PST) From: Rasmus Villemoes To: Jiri Kosina Cc: Rasmus Villemoes , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] HID: debug: improve hid_debug_event() Date: Tue, 24 Nov 2015 13:33:47 +0100 Message-Id: <1448368427-1669-1-git-send-email-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.6.1 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham 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 The code in hid_debug_event() causes horrible code generation. First, we do a strlen() call for every byte we copy (we're doing a store to global memory, so gcc has no way of proving that strlen(buf) doesn't change). Second, since both i, list->tail and HID_DEBUG_BUFSIZE have signed type, the modulo computation has to take into account the possibility that list->tail+i is negative, so it's not just a simple and. Fix the former by simply not doing strlen() at all (we have to load buf[i] anyway, so testing it is almost free) and the latter by changing i to unsigned. This cuts 29% (69 bytes) of the size of the function. Signed-off-by: Rasmus Villemoes --- drivers/hid/hid-debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-debug.c b/drivers/hid/hid-debug.c index 2886b645ced7..acfb522a432a 100644 --- a/drivers/hid/hid-debug.c +++ b/drivers/hid/hid-debug.c @@ -659,13 +659,13 @@ EXPORT_SYMBOL_GPL(hid_dump_device); /* enqueue string to 'events' ring buffer */ void hid_debug_event(struct hid_device *hdev, char *buf) { - int i; + unsigned i; struct hid_debug_list *list; unsigned long flags; spin_lock_irqsave(&hdev->debug_list_lock, flags); list_for_each_entry(list, &hdev->debug_list, node) { - for (i = 0; i < strlen(buf); i++) + for (i = 0; buf[i]; i++) list->hid_debug_buf[(list->tail + i) % HID_DEBUG_BUFSIZE] = buf[i]; list->tail = (list->tail + i) % HID_DEBUG_BUFSIZE;