Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp639559ybj; Thu, 7 May 2020 04:17:23 -0700 (PDT) X-Google-Smtp-Source: APiQypKTugzmj8hSDzs3i1bJ0UHIkQMz7I4NqgIoPHYFOvaA6n9hKMSIRT4hYs4wgE8IYZ6BSVwG X-Received: by 2002:a50:ba83:: with SMTP id x3mr10769334ede.193.1588850242875; Thu, 07 May 2020 04:17:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588850242; cv=none; d=google.com; s=arc-20160816; b=kZkSUUcW3lwsJWDc1aRjX4vrxLLnlNkJ0r26Eo0ng2SVccrFD9d5/hsUrBCAzz7YVq xZrficp0uRT3zDa0sfCY412B4co0egZtmpCZ/AuP43U+E+/HDFAw02IPP8jSbdhHlokX +vDVTSCXrsVL7F69gx5V6AJBzvf/kWU6G1Yx/lrMJUpfvUvKmwv8RefZ9lG2wA86JUcM uFdeUrp1wdfDtio6xYmtTEmyuGG+BYL0Ok72otgI4iZpdsEUJEVpNT1iSFEpF5/zeegI tiqieG+sG5AClL4qYJX2y6CW+DIyznR+7H9EHAVk7DjkhnzepJQjYM8y2S/ypcZmzpvE H+9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=yFM4n343VY3IO0y4Pzw5h5wkNTae9iA1zwRFU/OJOgs=; b=TZZsg0rpBXOk6AA1jN5x+IKeBeSiOIFVY5ChAWMqnSLY6c2UQOVeF5syQ/AUOzQ3oq faIYw/HyfRfqBLYtDd0d1qo3QxJIUZUrF32BLkvaUsJp3EoCudt/qU42BZtH5PUmarFJ FOc6TBkBb7Lrc+jPzaCjR0PoHiFYtdQhuLk60KACLh549U3oSD6F+wjfoqbnuJi4DiKT 4gh4dCAIct/WwuDtNyVoxrklbjUR6X3fVYFXdWaQxzjgM527H1d54AzQimPZFrHj9mKa oOhssO/cNYVkxrlxI6pHnykytRwPZvk+Jbmiki3ju+dKRa/reNH5fy/iRACHdiDjB7+w ow0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=io0+5PU2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o61si2762801edb.125.2020.05.07.04.16.59; Thu, 07 May 2020 04:17:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=io0+5PU2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726913AbgEGLP3 (ORCPT + 99 others); Thu, 7 May 2020 07:15:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:45922 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725903AbgEGLP3 (ORCPT ); Thu, 7 May 2020 07:15:29 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 839FD20870; Thu, 7 May 2020 11:15:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588850129; bh=m5j26vopqsarHASCUs41VneRgz6W4ivAN8SWIs8XUAo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=io0+5PU2Jeftf20wluUzmyi6annaxFgvMBpalV5HD+3n1J20l9FbtshQAzuO3We6G WoUGLmhyX19mn3i2NhD5tGOlVldDjiTX0Iy1pXVWMgvHqvvYFc+I35BG5JPIcCsOYj XIS5ok98Sh/Aiopp4KLuMTh3HNg0bPK7aW4zOP5M= Date: Thu, 7 May 2020 13:15:26 +0200 From: Greg KH To: Jia-Ju Bai Cc: mchehab@kernel.org, allison@lohutok.net, tglx@linutronix.de, rfontana@redhat.com, tomasbortoli@gmail.com, sean@mess.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] media: usb: ttusb-dec: reduce the number of memory reads in ttusb_dec_handle_irq() Message-ID: <20200507111526.GA1498671@kroah.com> References: <20200507102521.17602-1-baijiaju1990@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200507102521.17602-1-baijiaju1990@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 07, 2020 at 06:25:21PM +0800, Jia-Ju Bai wrote: > In ttusb_dec_handle_irq(), buffer[4] is continuously read from memory > three times, without being modified. > To reduce the number of memory reads, buffer[4] is first assigned to a > local variable index, and then index is used to replace buffer[4]. > > Signed-off-by: Jia-Ju Bai > --- > drivers/media/usb/ttusb-dec/ttusb_dec.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/drivers/media/usb/ttusb-dec/ttusb_dec.c b/drivers/media/usb/ttusb-dec/ttusb_dec.c > index 3198f9624b7c..8543c552515b 100644 > --- a/drivers/media/usb/ttusb-dec/ttusb_dec.c > +++ b/drivers/media/usb/ttusb-dec/ttusb_dec.c > @@ -250,6 +250,7 @@ static void ttusb_dec_handle_irq( struct urb *urb) > struct ttusb_dec *dec = urb->context; > char *buffer = dec->irq_buffer; > int retval; > + int index = buffer[4]; > > switch(urb->status) { > case 0: /*success*/ > @@ -281,11 +282,11 @@ static void ttusb_dec_handle_irq( struct urb *urb) > * this should/could be added later ... > * for now lets report each signal as a key down and up > */ > - if (buffer[4] - 1 < ARRAY_SIZE(rc_keys)) { > - dprintk("%s:rc signal:%d\n", __func__, buffer[4]); > - input_report_key(dec->rc_input_dev, rc_keys[buffer[4] - 1], 1); > + if (index - 1 < ARRAY_SIZE(rc_keys)) { > + dprintk("%s:rc signal:%d\n", __func__, index); > + input_report_key(dec->rc_input_dev, rc_keys[index - 1], 1); > input_sync(dec->rc_input_dev); > - input_report_key(dec->rc_input_dev, rc_keys[buffer[4] - 1], 0); > + input_report_key(dec->rc_input_dev, rc_keys[index - 1], 0); > input_sync(dec->rc_input_dev); > } > } > -- > 2.17.1 > Reviewed-by: Greg Kroah-Hartman